body excludes frontmatter

This commit is contained in:
2026-03-21 15:52:47 +00:00
parent 44b0554cc3
commit 17e79c1f3e
+5 -3
View File
@@ -46,9 +46,11 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration {
const lines = contents.split('\n'); const lines = contents.split('\n');
let data: Record<string, unknown> = {}; let data: Record<string, unknown> = {};
let frontmatter = ''; let frontmatter = '';
let bodyStartLineIndex = 0;
if (lines.at(0) === '---' && lines.lastIndexOf('---')) { if (lines.at(0) === '---' && lines.lastIndexOf('---') > 0) {
frontmatter = lines.slice(1, lines.indexOf('---', 1)).join('\n'); bodyStartLineIndex = lines.indexOf('---', 1) + 1;
frontmatter = lines.slice(1, bodyStartLineIndex).join('\n');
try { try {
data = { ...data, ...parseYaml(frontmatter, { schema: 'yaml-1.1' }) }; data = { ...data, ...parseYaml(frontmatter, { schema: 'yaml-1.1' }) };
} catch { } } catch { }
@@ -57,7 +59,7 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration {
return { return {
data, data,
rawData: frontmatter, rawData: frontmatter,
body: contents, body: lines.slice(bodyStartLineIndex).join('\n'),
slug: typeof data['slug'] === 'string' ? data['slug'] : fileUrl.pathname, slug: typeof data['slug'] === 'string' ? data['slug'] : fileUrl.pathname,
}; };
}, },