i feel insane. what have i done.

This commit is contained in:
haetae 2025-08-05 00:38:27 -04:00
parent a4d7294da2
commit f30a89cda0
2 changed files with 43 additions and 9 deletions

View File

@ -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 };
export const collections = { blog, fics, chapters, test };

View File

@ -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<any>;
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);
}
);