Add cache headers, real 404s, social meta, JSON-LD, robots and sitemap

This commit is contained in:
dtonon 2026-08-18 17:49:01 +01:00
parent 2041f6b899
commit fc7c749856
19 changed files with 258 additions and 47 deletions

17
src/lib/seo.ts Normal file
View file

@ -0,0 +1,17 @@
// Plain-text excerpt of a markdown body for description meta tags: the first
// paragraph that isn't a heading or a bare media URL, trimmed to `max` chars.
export function excerpt(markdown: string, max = 160): string {
const lines = markdown.split("\n").map((l) => l.trim());
const line = lines.find(
(l) => l && !l.startsWith("#") && !/^https?:\/\/\S+$/.test(l),
);
if (!line) return "";
const text = line
.replace(/!\[[^\]]*\]\([^)]*\)/g, "") // images
.replace(/\[([^\]]*)\]\([^)]*\)/g, "$1") // links → label
.replace(/[*_`~]+/g, "")
.replace(/nostr:([a-z0-9]{12})[a-z0-9]*/g, "@$1…") // keep a short handle
.replace(/\s+/g, " ")
.trim();
return text.length > max ? text.slice(0, max - 1).trimEnd() + "…" : text;
}