diff --git a/src/index.ts b/src/index.ts index a9fd873..2f06f24 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,9 +46,11 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration { const lines = contents.split('\n'); let data: Record = {}; let frontmatter = ''; + let bodyStartLineIndex = 0; - if (lines.at(0) === '---' && lines.lastIndexOf('---')) { - frontmatter = lines.slice(1, lines.indexOf('---', 1)).join('\n'); + if (lines.at(0) === '---' && lines.lastIndexOf('---') > 0) { + bodyStartLineIndex = lines.indexOf('---', 1) + 1; + frontmatter = lines.slice(1, bodyStartLineIndex).join('\n'); try { data = { ...data, ...parseYaml(frontmatter, { schema: 'yaml-1.1' }) }; } catch { } @@ -57,7 +59,7 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration { return { data, rawData: frontmatter, - body: contents, + body: lines.slice(bodyStartLineIndex).join('\n'), slug: typeof data['slug'] === 'string' ? data['slug'] : fileUrl.pathname, }; },