stab in the dark at getEntryInfo()
This commit is contained in:
+19
-2
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user