(value: string)
| 82 | const DEFAULT_K = 8 |
| 83 | |
| 84 | function parseFrontmatter(value: string): { title?: string; body: string } { |
| 85 | if (!value.startsWith(`---\n`)) { |
| 86 | return { body: value } |
| 87 | } |
| 88 | |
| 89 | const end = value.indexOf(`\n---\n`, 4) |
| 90 | if (end === -1) { |
| 91 | return { body: value } |
| 92 | } |
| 93 | |
| 94 | const frontmatter = value.slice(4, end) |
| 95 | const titleMatch = frontmatter.match(/^title:\s*(.+)$/m) |
| 96 | return { |
| 97 | title: titleMatch?.[1]?.trim().replace(/^['"]|['"]$/g, ``), |
| 98 | body: value.slice(end + 5), |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | function firstHeading(value: string): string | undefined { |
| 103 | const match = value.match(/^#\s+(.+)$/m) |
no test coverage detected