Adoption of Loader for Content Layer API
Astro 5.0(and Astro 4.14(experimental)) introduced Content Layer API.
One of these is added as Loader.
What this does is that by executing glob(), you can receive an array of content from it and display it.
The great part about this is that you can change the entry point, remote or local, and it doesn't matter where you are as long as you get the content.
This solves the problem that fuwari has of having to forcibly place content under src/content.
I would like to adopt this. What do you think? @saicaca
https://astro.build/blog/astro-4140/ https://astro.build/blog/astro-5/
// src/content/config.ts to src/content.config.ts
import { defineCollection, z } from 'astro:content'
import { glob } from 'astro/loaders'
const postsCollection = defineCollection({
loader: glob({ pattern: '**/*.md', base: 'path/to/content' }),
schema: z.object({
title: z.string(),
published: z.date(),
draft: z.boolean().optional().default(false),
description: z.string().optional().default(''),
image: z.string().optional().default(''),
tags: z.array(z.string()).optional().default([]),
category: z.string().optional().default(''),
lang: z.string().optional().default(''),
/* For internal use */
prevTitle: z.string().default(''),
prevSlug: z.string().default(''),
nextTitle: z.string().default(''),
nextSlug: z.string().default(''),
}),
})
export const collections = {
posts: postsCollection,
}
Yes, I think it's great to adopt the new API.
They said they would adopt it, so I'm creating a PoC.
Thinking about where to place content.
I think it's okay to keep them in /src/content since it matches existing practices. Users can easily modify the location if they want.
I made a PoC. There is no problem until the article is displayed, but it seems to be causing a rather troublesome problem around images...
Personally, I feel it is more reliable to take this opportunity to place all content...
https://github.com/L4Ph/fuwari/tree/content-layer-api
I've tried a few things since then, but I can't think of a good way to do it, so I'd appreciate some advice. ImageWrapper is the only problem
@saicaca