Add cache headers, real 404s, social meta, JSON-LD, robots and sitemap
This commit is contained in:
parent
2041f6b899
commit
fc7c749856
19 changed files with 258 additions and 47 deletions
17
src/lib/seo.ts
Normal file
17
src/lib/seo.ts
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue