holy shit i did it

This commit is contained in:
haetae 2025-08-05 01:59:13 -04:00
parent f30a89cda0
commit e38e2cec2b
4 changed files with 43 additions and 6 deletions

View File

@ -49,6 +49,7 @@ const chapters = defineCollection({
notes: z.ostring().transform(notes => parser.renderInline(notes ?? "", {})),
lastModified: z.coerce.date().optional(),
sortOrder: z.number().default(1),
// fic: reference("fics"),
}),
});
@ -85,6 +86,18 @@ const test = defineCollection({
}
})
),
schema: z.object({
title: z.string(),
series: z.union([z.string(), z.array(z.string())]),
publishedAt: z.coerce.date(),
summary: z.string().transform(summary => parser.renderInline(summary, {})),
characters: z.array(z.string()).optional(),
ships: z.ostring(),
tags: z.array(z.string()).optional(),
notes: z.ostring().transform(notes => parser.renderInline(notes ?? "", {})),
lastModified: z.coerce.date().optional(),
chapters: z.array(reference("chapters")).optional(),
}),
});
export const collections = { blog, fics, chapters, test };

View File

@ -43,6 +43,7 @@ const links = [
{lastModified}
notes={chapter.data.notes}
>
{chapter.id}
<Fragment slot="breadcrumbs">
<Breadcrumbs id="breadcrumbs" customizeLinks={links} linkTextFormat="capitalized">
<Fragment slot="separator" set:text="/" />
@ -50,7 +51,6 @@ const links = [
</Fragment>
<Content />
{chapters.length > 1 && (
<nav id="chapter-pagination" slot="pagination">
<div id="chapter-index">

26
src/pages/test.astro Normal file
View File

@ -0,0 +1,26 @@
---
import Layout from "@/layouts/Layout.astro";
import { getEntries } from "astro:content";
import { render } from "astro:content";
import { getEntry } from "astro:content";
import { getCollection } from "astro:content";
const fics = await getCollection("test");
// console.log(fics);
const entry = await getEntry("test", "test");
// const chapter = await getEntry("chapters", "test/two");
if (!entry) throw new Error("not found!");
const chapters = await getEntries(entry.data.chapters!);
// const { Content } = await render(entry);
---
<Layout>
{fics.map(fic => (
<article>
<h2>{fic.data.title}</h2>
{chapters.map(chapter => (
<p>{JSON.stringify(chapter)}</p>
))}
{JSON.stringify(fic.data.chapters?.map(chapter => chapter))}
</article>
))}
</Layout>

View File

@ -2,16 +2,14 @@ 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";
import { reference } from "astro:content";
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 => ({
relativePath: chapter,
chapter: path.resolve(fic, chapter),
}));
return chapters.map(chapter => `${fic.split("/").at(-1)}/${path.parse(chapter).name}`);
}
export function ficsLoader(loader: Loader) {
@ -39,7 +37,7 @@ export function ficsLoader(loader: Loader) {
const search = import.meta.glob(`../content/fics/**/*.md`, { eager: true });
let body;
for (const path in search) {
if (path.includes(chapters[0].relativePath)) {
if (path.includes(chapters[0])) {
body = search[path] as MarkdownInstance<any>;
context.store.set({
...valueWithoutDigest,