dika/public/src-note.js
peppa-bot 10c489cf9c
All checks were successful
peppa/lint lint: success за 0с
peppa/test test: success за 0с
peppa/build build: success за 0с
ci / checks (pull_request) Successful in 10s
deploy / deploy (pull_request) Successful in 19s
DIK-66: источник описания и фото на карточке, «Фото пока нет» у заглушки
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 11:40:47 +00:00

20 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Подпись источника для главной и страницы «Все заведения» (DIK-66).
// «2ГИС — https://…» → { name: "2ГИС", href: "https://…" }; «владелец» → «добавлено владельцем».
export function srcParts(source, t) {
if (!source) return null;
const m = /^(.*?)\s*(https?:\/\/\S+)$/.exec(String(source).trim());
let name = (m ? m[1] : String(source).trim()).replace(/[\s—-]+$/, "");
if (name === "владелец") name = t.srcOwner;
return { name: name || (m ? m[2] : ""), href: m ? m[2] : null };
}
// Готовый блок «Источник описания: 2ГИС» (название ссылкой, если есть адрес страницы)
export function srcNode(label, source, t, cls = "srcnote") {
const p = srcParts(source, t);
if (!p) return null;
const d = document.createElement("div"); d.className = cls;
d.append(label + " ");
if (p.href) { const a = document.createElement("a"); a.href = p.href; a.textContent = p.name; a.target = "_blank"; a.rel = "noopener noreferrer"; d.append(a); }
else d.append(p.name);
return d;
}