diff --git a/guestbook.db b/guestbook.db deleted file mode 100644 index e69de29..0000000 diff --git a/src/content/fics/weight of living/moving on.md b/src/content/fics/weight of living/moving on.md index 81c8b1d..60bcebe 100644 --- a/src/content/fics/weight of living/moving on.md +++ b/src/content/fics/weight of living/moving on.md @@ -4,6 +4,8 @@ publishedAt: 2020-12-20T19:18:00 notes: i wrote this in a fugue state while listening to [Waste by Oh Wonder](https://www.youtube.com/watch?v=Ar1grAdGkec) --- +![the of all time]($/images/the-of-all-time.png) +     diff --git a/src/utils/ficsLoader.ts b/src/utils/ficsLoader.ts new file mode 100644 index 0000000..90f7ac0 --- /dev/null +++ b/src/utils/ficsLoader.ts @@ -0,0 +1,39 @@ +import { type Loader, type LoaderContext } from "astro/loaders"; +import { parseFrontmatter } from '@astrojs/markdown-remark'; +import { readdirSync } from "fs"; +import { glob } from "fs/promises"; + +export function ficsLoader(options: { path: string }) { + return { + name: "fics", + async load(context: LoaderContext) { + const fics = readdirSync(options.path, { withFileTypes: true }) + .filter(dirent => dirent.isDirectory()) + .map(dirent => dirent.name); + + for (const fic of fics) { + const { content } = parseFrontmatter(fic, { frontmatter: "empty-with-spaces" }); + console.log(content); + } + }, + }; +} + +async function test(options: { path: string }) { + const fics = readdirSync(options.path, { withFileTypes: true }) + .filter(dirent => dirent.isDirectory()) + .map(dirent => `${dirent.parentPath}/${dirent.name}`); + + for (const fic of fics) { + const entries = await Array.fromAsync(glob([`${fic}/*.yaml`, `${fic}/*.yml`, `${fic}/*.toml`, `${fic}/*.json`])); + console.log(entries); + const chapterPaths = await Array.fromAsync(glob(fic + '/*.md')); + const chapters = chapterPaths.map(chapter => chapter); + // const files + // console.log("" + chapters) + // const { content } = parseFrontmatter(fic, { frontmatter: "empty-with-spaces" }); + // console.log(content); + } +} + +test({ path: "./src/content/fics" }); \ No newline at end of file diff --git a/src/utils/lastModified.mjs b/src/utils/lastModified.mjs index 5ec0233..17f6e0e 100644 --- a/src/utils/lastModified.mjs +++ b/src/utils/lastModified.mjs @@ -3,7 +3,11 @@ import { statSync } from "fs"; export function modifiedTime() { return function (_tree, file) { const path = file.history[0]; - const result = statSync(path); - file.data.astro.frontmatter.lastModified = result.mtime; + try { + const result = statSync(path); + file.data.astro.frontmatter.lastModified = result.mtime; + } catch (error) { + return; + } } } \ No newline at end of file diff --git a/src/utils/loader.ts b/src/utils/loader.ts index 5b98f85..9f0af1f 100644 --- a/src/utils/loader.ts +++ b/src/utils/loader.ts @@ -1,15 +1,8 @@ import type { MarkdownInstance } from "astro"; import type { Loader, LoaderContext } from "astro/loaders"; +import { parseFrontmatter } from '@astrojs/markdown-remark'; import path from "path"; -import { glob } from "fs/promises"; - -async function getAllChapters(metaPath: string) { - const entryPath = path.parse(metaPath); - const fic = entryPath.dir; - const entries = await Array.fromAsync(glob(fic + '/*.md')); - const chapters = entries.map(chapter => path.relative(fic, chapter)); - return chapters.map(chapter => `${fic.split("/").at(-1)}/${path.parse(chapter).name}`); -} +import { glob, readFile } from "fs/promises"; export function ficsLoader(loader: Loader) { const oldLoad = loader.load; @@ -47,8 +40,13 @@ async function resolveFics(loader: (oldContext: LoaderContext) => Promise, if (valueWithoutDigest.data['oneshot'] === true) { // i've committed unspeakable atrocities here const search = import.meta.glob>(`../content/fics/**/*.md`, { eager: true }); - const body = Object.values(search).filter(path => path.file?.includes(chapters[0]))[0]; + const onlyChapter = chapters[0]; + const includedChapter = (path: MarkdownInstance) => path.file?.includes(onlyChapter); + const [body] = Object.values(search).filter(includedChapter); const html = await body.compiledContent(); + // following could be good for being way more forgiving of paths + // const { content, frontmatter } = await readChapterFile(value.filePath as string, chapters); + // const test = await context.renderMarkdown(content); context.store.set({ ...valueWithoutDigest, data: newData, @@ -75,4 +73,27 @@ async function resolveFics(loader: (oldContext: LoaderContext) => Promise, return loadedPromise.promise; }) ); +} + +async function getAllChapters(metaPath: string) { + const entryPath = path.parse(metaPath); + const fic = entryPath.dir; + const ficFolder = fic.split("/").at(-1); + const entries = await Array.fromAsync(glob(fic + '/*.md')); + const chapters = entries.map(chapter => path.relative(fic, chapter)); + return chapters.map(chapter => `${ficFolder}/${chapter}`); +} + +// unused for now +async function readChapterFile(folderPath: string, chapters: string[]) { + const folder = (folderPath) + .split("/") + .slice(0, -2) // we only want the stuff before fic folder + .join("/"); // reconnect as string + const onlyChapter = chapters[0]; + const filePath = path.resolve(folder, onlyChapter); + const [search] = await Array.fromAsync(glob(`${filePath}`)); + const fileContent = await readFile(search, "utf8"); + const result = parseFrontmatter(fileContent); + return result; } \ No newline at end of file