stab in the dark at getEntryInfo()

This commit is contained in:
2026-03-21 11:59:24 +00:00
parent 03ef3d2078
commit e20dd723c3
+19 -2
View File
@@ -1,6 +1,7 @@
import type {AstroIntegration, ContentEntryType, HookParameters} from "astro" import type {AstroIntegration, ContentEntryType, HookParameters} from "astro"
import {fileURLToPath} from "url" import {fileURLToPath} from "url"
import gemtextVitePlugin from "./vitePlugin.js" import gemtextVitePlugin from "./vitePlugin.js"
import { parse as parseYaml } from "yaml";
export const ext = "gmi" export const ext = "gmi"
@@ -41,8 +42,24 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration {
params.addPageExtension(ext) params.addPageExtension(ext)
params.addContentEntryType({ params.addContentEntryType({
extensions: [`.${ext}`], extensions: [`.${ext}`],
getEntryInfo: async (params) => { getEntryInfo: async ({ fileUrl, contents }) => {
throw new Error("Not implemented") const lines = contents.split('\n');
let data: Record<string, unknown> = {};
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({ params.updateConfig({