From e20dd723c37c3a6660b9d6a260e18e31ff2edf69 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Sat, 21 Mar 2026 11:59:24 +0000 Subject: [PATCH] stab in the dark at getEntryInfo() --- src/index.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 83db082..f2620fe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import type {AstroIntegration, ContentEntryType, HookParameters} from "astro" import {fileURLToPath} from "url" import gemtextVitePlugin from "./vitePlugin.js" +import { parse as parseYaml } from "yaml"; export const ext = "gmi" @@ -41,8 +42,24 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration { params.addPageExtension(ext) params.addContentEntryType({ extensions: [`.${ext}`], - getEntryInfo: async (params) => { - throw new Error("Not implemented") + getEntryInfo: async ({ fileUrl, contents }) => { + const lines = contents.split('\n'); + let data: Record = {}; + let frontmatter = ''; + + if (lines.at(0) === '---' && lines.lastIndexOf('---')) { + frontmatter = lines.slice(1, lines.indexOf('---', 1)).join('\n'); + try { + data = { ...data, ...parseYaml(frontmatter) }; + } catch { } + } + + return { + data, + rawData: frontmatter, + body: contents, + slug: typeof data['slug'] === 'string' ? data['slug'] : fileUrl.pathname, + }; }, }) params.updateConfig({