body excludes frontmatter
This commit is contained in:
+5
-3
@@ -46,9 +46,11 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration {
|
||||
const lines = contents.split('\n');
|
||||
let data: Record<string, unknown> = {};
|
||||
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,
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user