Add Markdown editor, server statistics and content navigation

This commit is contained in:
SantaSpeen committed 2026-12-02 15:32:14 +03:00
1 parent 03c590e172
commit 1819f35f91
52 files changed
+7190 -28

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
import { escapeText } from "./text-runtime.js";
export function breadcrumbsMarkup({ items = [], t = (ru) => ru } = {}) {
if (!Array.isArray(items) || items.length > 32)
throw new TypeError("Breadcrumbs support up to 32 entries");
return `<nav class="breadcrumbs" aria-label="${t("Хлебные крошки", "Breadcrumbs")}"><ol>${items
.map((item, index) => {
const label = escapeText(item.label),
current = index === items.length - 1;
let href = item.href;
if (href) {
try {
if (
!["http:", "https:"].includes(
new URL(
href,
globalThis.location?.href || "https://anidev.invalid/",
).protocol,
)
)
href = null;
} catch {
href = null;
}
}
return `<li>${index ? '<span class="breadcrumb-separator" aria-hidden="true">/</span>' : ""}${!current && href ? `<a href="${escapeText(href)}">${label}</a>` : `<span ${current ? 'aria-current="page"' : ""}>${label}</span>`}</li>`;
})
.join("")}</ol></nav>`;
}
export function mountBreadcrumbs(root, { onNavigate } = {}) {
const abort = new AbortController();
root.addEventListener(
"click",
(event) => {
const link = event.target.closest("a[href]");
if (
!onNavigate ||
!link ||
event.defaultPrevented ||
event.button !== 0 ||
event.ctrlKey ||
event.metaKey ||
event.shiftKey ||
event.altKey ||
link.target === "_blank"
)
return;
const url = new URL(link.href, location.href);
if (url.origin !== location.origin) return;
event.preventDefault();
onNavigate(url);
},
{ signal: abort.signal },
);
return () => abort.abort();
}