Content Collections
Keep your pages in Astro content collections.
Your pages are MDX files in content collections, and new sites already include one. A collection needs three files:
import { defineConfig } from "astro/config";
import press from "@fumapress/astro";
export default defineConfig({
integrations: [
press({
collections: { docs: { dir: "content" } },
lastModified: true,
includeProcessedMarkdown: true,
}),
],
});Without collections, press() reads the docs collection from content/docs. See Integration for the other options.
Frontmatter Fields
pageLoader() accepts the standard fields. Extend the schema to add a field. The new field is typed on page.data in your layout.
import { defineCollection } from "astro:content";
import { z } from "astro/zod";
import { pageSchema } from "fumadocs-core/source/schema";
import { metaLoader, pageLoader } from "@fumadocs/astro/loaders";
export const collections = {
docs: defineCollection({
loader: pageLoader(),
schema: pageSchema.extend({ draft: z.boolean().optional() }),
}),
meta: defineCollection({ loader: metaLoader() }),
};Multiple Collections
To add a blog, or to free / for a landing page, give each collection a folder and a URL prefix. After these steps, content/docs/index.mdx is at /docs, and content/blog/hello.mdx is at /blog/hello.
Name the Folders
press({
collections: {
docs: { dir: "content/docs" },
blog: { dir: "content/blog" },
},
});Load the Collections
pageLoader("blog") reads the blog folder above, and each key of this object is a name for getCollection().
export const collections = {
docs: defineCollection({ loader: pageLoader() }),
meta: defineCollection({ loader: metaLoader() }),
blog: defineCollection({ loader: pageLoader("blog") }),
blogMeta: defineCollection({ loader: metaLoader("blog") }),
};Add the Sources
export default createPress({
docs: toFumadocsSource(await getCollection("docs"), await getCollection("meta"), {
baseDir: "docs",
}),
blog: toFumadocsSource(await getCollection("blog"), await getCollection("blogMeta"), {
baseDir: "blog",
}),
});A collection you leave out of createPress() has no docs pages. You can render it on custom
pages.
Last updated on