-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Adoption of Loader for Content Layer API #240
Comments
// 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 |
I made a PoC. Personally, I feel it is more reliable to take this opportunity to place all content... |
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. |
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/
The text was updated successfully, but these errors were encountered: