summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/index.ts21
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({