holy shit i did it
This commit is contained in:
		
							parent
							
								
									f30a89cda0
								
							
						
					
					
						commit
						e38e2cec2b
					
				| @ -49,6 +49,7 @@ const chapters = defineCollection({ | |||||||
|     notes: z.ostring().transform(notes => parser.renderInline(notes ?? "", {})), |     notes: z.ostring().transform(notes => parser.renderInline(notes ?? "", {})), | ||||||
|     lastModified: z.coerce.date().optional(), |     lastModified: z.coerce.date().optional(), | ||||||
|     sortOrder: z.number().default(1), |     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 }; | export const collections = { blog, fics, chapters, test }; | ||||||
| @ -43,6 +43,7 @@ const links = [ | |||||||
|   {lastModified}  |   {lastModified}  | ||||||
|   notes={chapter.data.notes} |   notes={chapter.data.notes} | ||||||
| > | > | ||||||
|  |   {chapter.id} | ||||||
|   <Fragment slot="breadcrumbs"> |   <Fragment slot="breadcrumbs"> | ||||||
|     <Breadcrumbs id="breadcrumbs" customizeLinks={links} linkTextFormat="capitalized"> |     <Breadcrumbs id="breadcrumbs" customizeLinks={links} linkTextFormat="capitalized"> | ||||||
|       <Fragment slot="separator" set:text="/" /> |       <Fragment slot="separator" set:text="/" /> | ||||||
| @ -50,7 +51,6 @@ const links = [ | |||||||
|   </Fragment> |   </Fragment> | ||||||
| 
 | 
 | ||||||
|   <Content /> |   <Content /> | ||||||
| 
 |  | ||||||
|   {chapters.length > 1 && ( |   {chapters.length > 1 && ( | ||||||
|   <nav id="chapter-pagination" slot="pagination"> |   <nav id="chapter-pagination" slot="pagination"> | ||||||
|     <div id="chapter-index"> |     <div id="chapter-index"> | ||||||
|  | |||||||
							
								
								
									
										26
									
								
								src/pages/test.astro
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/pages/test.astro
									
									
									
									
									
										Normal 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> | ||||||
| @ -2,16 +2,14 @@ import type { MarkdownInstance } from "astro"; | |||||||
| import { glob as astroGlob, type Loader, type LoaderContext } from "astro/loaders"; | import { glob as astroGlob, type Loader, type LoaderContext } from "astro/loaders"; | ||||||
| import path from "path"; | import path from "path"; | ||||||
| import { glob } from "fs/promises"; | import { glob } from "fs/promises"; | ||||||
|  | import { reference } from "astro:content"; | ||||||
| 
 | 
 | ||||||
| async function getAllChapters(metaPath: string) { | async function getAllChapters(metaPath: string) { | ||||||
|   const entryPath = path.parse(metaPath); |   const entryPath = path.parse(metaPath); | ||||||
|   const fic = entryPath.dir; |   const fic = entryPath.dir; | ||||||
|   const entries = await Array.fromAsync(glob(fic + '/*.md')); |   const entries = await Array.fromAsync(glob(fic + '/*.md')); | ||||||
|   const chapters = entries.map(chapter => path.relative(fic, chapter)); |   const chapters = entries.map(chapter => path.relative(fic, chapter)); | ||||||
|   return chapters.map(chapter => ({ |   return chapters.map(chapter => `${fic.split("/").at(-1)}/${path.parse(chapter).name}`); | ||||||
|     relativePath: chapter, |  | ||||||
|     chapter: path.resolve(fic, chapter), |  | ||||||
|   })); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function ficsLoader(loader: Loader) { | export function ficsLoader(loader: Loader) { | ||||||
| @ -39,7 +37,7 @@ export function ficsLoader(loader: Loader) { | |||||||
|               const search = import.meta.glob(`../content/fics/**/*.md`, { eager: true }); |               const search = import.meta.glob(`../content/fics/**/*.md`, { eager: true }); | ||||||
|               let body; |               let body; | ||||||
|               for (const path in search) { |               for (const path in search) { | ||||||
|                 if (path.includes(chapters[0].relativePath)) { |                 if (path.includes(chapters[0])) { | ||||||
|                   body = search[path] as MarkdownInstance<any>; |                   body = search[path] as MarkdownInstance<any>; | ||||||
|                   context.store.set({ |                   context.store.set({ | ||||||
|                     ...valueWithoutDigest, |                     ...valueWithoutDigest, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user