diff --git a/src/content/config.ts b/src/content/config.ts index 44bf2f3..3af640e 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -74,8 +74,17 @@ const fics = defineCollection({ }), }); -// const fics = defineCollection({ -// loader: ficsLoader(glob({ pattern: "**/*.{yml,yaml}", base: source })), -// }); +const test = defineCollection({ + loader: ficsLoader( + glob({ + pattern: "**/*.{yml,yaml}", + base: source, + generateId: ({ entry, data }) => { + if (data.slug) return data.slug as string; + return slugify(entry.split("/")[0]); + } + }) + ), +}); -export const collections = { blog, fics, chapters }; \ No newline at end of file +export const collections = { blog, fics, chapters, test }; \ No newline at end of file diff --git a/src/utils/loader.ts b/src/utils/loader.ts index 2f4fda0..58d55a5 100644 --- a/src/utils/loader.ts +++ b/src/utils/loader.ts @@ -1,3 +1,4 @@ +import type { MarkdownInstance } from "astro"; import { glob as astroGlob, type Loader, type LoaderContext } from "astro/loaders"; import path from "path"; import { glob } from "fs/promises"; @@ -33,11 +34,35 @@ export function ficsLoader(loader: Loader) { ...chapters.length > 1 && { chapters: chapters }, }, }); - context.store.set({ - ...valueWithoutDigest, - data: newData, - digest: context.generateDigest(newData), - }); + if (chapters.length === 1) { + // i've committed unspeakable atrocities here + const search = import.meta.glob(`../content/fics/**/*.md`, { eager: true }); + let body; + for (const path in search) { + if (path.includes(chapters[0].relativePath)) { + body = search[path] as MarkdownInstance; + context.store.set({ + ...valueWithoutDigest, + data: newData, + body: body.rawContent(), + rendered: { + html: await body.compiledContent(), + metadata: { + headings: body.getHeadings(), + frontmatter: body.frontmatter, + }, + }, + digest: context.generateDigest(newData), + }); + }; + } + } else { + context.store.set({ + ...valueWithoutDigest, + data: newData, + digest: context.generateDigest(newData), + }); + } loadedPromise.resolve(chapters); } );