Derive a stable kebab-case slug from a human title.
(title: string)
| 84 | |
| 85 | /** Derive a stable kebab-case slug from a human title. */ |
| 86 | function slugify(title: string): string { |
| 87 | return title |
| 88 | .toLowerCase() |
| 89 | .trim() |
| 90 | .replace(/[^a-z0-9]+/g, '-') |
| 91 | .replace(/^-+|-+$/g, '') |
| 92 | } |
| 93 | |
| 94 | /** Serialize a frontmatter object + body back into the `---\n…\n---\n\n<body>` |
| 95 | * document shape the reader expects. Body is preserved verbatim (trimmed). */ |