Compare commits
No commits in common. "e56feaf1d0f505edf0b5522e144e8ba821aed754" and "ebcc2bf819430f3531351a87c8a78b438dde0627" have entirely different histories.
e56feaf1d0
...
ebcc2bf819
0
guestbook.db
Normal file
0
guestbook.db
Normal file
@ -4,8 +4,6 @@ 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)
|
notes: i wrote this in a fugue state while listening to [Waste by Oh Wonder](https://www.youtube.com/watch?v=Ar1grAdGkec)
|
||||||
---
|
---
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
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" });
|
|
@ -5,11 +5,5 @@ export function modifiedTime() {
|
|||||||
const path = file.history[0];
|
const path = file.history[0];
|
||||||
const result = statSync(path);
|
const result = statSync(path);
|
||||||
file.data.astro.frontmatter.lastModified = result.mtime;
|
file.data.astro.frontmatter.lastModified = result.mtime;
|
||||||
// try {
|
|
||||||
// const result = statSync(path);
|
|
||||||
// file.data.astro.frontmatter.lastModified = result.mtime;
|
|
||||||
// } catch (error) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,15 @@
|
|||||||
import type { MarkdownInstance } from "astro";
|
import type { MarkdownInstance } from "astro";
|
||||||
import type { Loader, LoaderContext } from "astro/loaders";
|
import type { Loader, LoaderContext } from "astro/loaders";
|
||||||
import { parseFrontmatter } from '@astrojs/markdown-remark';
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { glob, readFile } from "fs/promises";
|
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}`);
|
||||||
|
}
|
||||||
|
|
||||||
export function ficsLoader(loader: Loader) {
|
export function ficsLoader(loader: Loader) {
|
||||||
const oldLoad = loader.load;
|
const oldLoad = loader.load;
|
||||||
@ -40,13 +47,8 @@ async function resolveFics(loader: (oldContext: LoaderContext) => Promise<void>,
|
|||||||
if (valueWithoutDigest.data['oneshot'] === true) {
|
if (valueWithoutDigest.data['oneshot'] === true) {
|
||||||
// i've committed unspeakable atrocities here
|
// i've committed unspeakable atrocities here
|
||||||
const search = import.meta.glob<MarkdownInstance<any>>(`../content/fics/**/*.md`, { eager: true });
|
const search = import.meta.glob<MarkdownInstance<any>>(`../content/fics/**/*.md`, { eager: true });
|
||||||
const onlyChapter = chapters[0];
|
const body = Object.values(search).filter(path => path.file?.includes(chapters[0]))[0];
|
||||||
const includedChapter = (path: MarkdownInstance<any>) => path.file?.includes(onlyChapter);
|
|
||||||
const [body] = Object.values(search).filter(includedChapter);
|
|
||||||
const html = await body.compiledContent();
|
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({
|
context.store.set({
|
||||||
...valueWithoutDigest,
|
...valueWithoutDigest,
|
||||||
data: newData,
|
data: newData,
|
||||||
@ -73,27 +75,4 @@ async function resolveFics(loader: (oldContext: LoaderContext) => Promise<void>,
|
|||||||
return loadedPromise.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;
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user