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

20 lines
1.1 KiB
JavaScript
Raw Permalink 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;
}