summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-03-21 15:52:47 +0000
committerJoe Carstairs <me@joeac.net>2026-03-21 15:52:47 +0000
commit17e79c1f3edb21dd4e4c1d7564dced868e397a12 (patch)
treee35ec8d6f904d208b8c9eaf66236cd9bb0289458 /src
parent44b0554cc356f5fa35da689c79e5fbb48436755e (diff)
body excludes frontmatter
Diffstat (limited to 'src')
-rw-r--r--src/index.ts8
1 files changed, 5 insertions, 3 deletions
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<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,
};
},