i feel insane. what have i done.
This commit is contained in:
		
							parent
							
								
									a4d7294da2
								
							
						
					
					
						commit
						f30a89cda0
					
				| @ -74,8 +74,17 @@ const fics = defineCollection({ | |||||||
|   }), |   }), | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| // const fics = defineCollection({
 | const test = defineCollection({ | ||||||
| //   loader: ficsLoader(glob({ pattern: "**/*.{yml,yaml}", base: source })),
 |   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 }; | ||||||
| @ -1,3 +1,4 @@ | |||||||
|  | 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"; | ||||||
| @ -33,11 +34,35 @@ export function ficsLoader(loader: Loader) { | |||||||
|                 ...chapters.length > 1 && { chapters: chapters }, |                 ...chapters.length > 1 && { chapters: chapters }, | ||||||
|               }, |               }, | ||||||
|             }); |             }); | ||||||
|  |             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({ |               context.store.set({ | ||||||
|                 ...valueWithoutDigest, |                 ...valueWithoutDigest, | ||||||
|                 data: newData, |                 data: newData, | ||||||
|                 digest: context.generateDigest(newData), |                 digest: context.generateDigest(newData), | ||||||
|               }); |               }); | ||||||
|  |             } | ||||||
|             loadedPromise.resolve(chapters); |             loadedPromise.resolve(chapters); | ||||||
|           } |           } | ||||||
|         ); |         ); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user