diff options
| author | Joe Carstairs <me@joeac.net> | 2026-03-21 11:59:24 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-03-21 11:59:24 +0000 |
| commit | e20dd723c37c3a6660b9d6a260e18e31ff2edf69 (patch) | |
| tree | 4ac2587b8466f1ce1d0fa5a7eddb9dc5ca1eee6f /src/index.ts | |
| parent | 03ef3d20786fe9e585d010ff7d3676bf127d6446 (diff) | |
stab in the dark at getEntryInfo()
Diffstat (limited to 'src/index.ts')
| -rw-r--r-- | src/index.ts | 21 |
1 files 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<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({ |
