Collections
Configure page folders and frontmatter schemas.
A collection is a folder of Markdown pages and meta files, which Vuesho validates and compiles when the site builds. Without a config, a site has one collection, content/, as if it had this config:
import { createSite } from "vuesho/config";
import { defineDocs } from "vuesho/content";
const docs = defineDocs();
export default createSite(docs.toSource()); Defining Collections
defineDocs() reads pages and meta files. Pass the page options in docs, and the meta file options in meta:
const docs = defineDocs({
// The folder, from the project root
dir: "docs",
// The options of the Markdown pages
docs: {
// The pages in `dir`, where `!` leaves files out
files: ["**/*.md", "!archive/**"],
},
// The options of the meta files, like `meta.json`
meta: {
files: ["**/meta.json"],
},
});A collection skips node_modules, and the files and folders whose names start with _ or .. A pattern can't hold (, ) or \. A file can be in several collections, which validate and compile it with their own options.
Frontmatter Schema
A page accepts Vuesho's frontmatter fields, and drops unknown keys. To add custom fields, extend pageSchema, a Zod object from vuesho/schema:
npm i zodimport { defineDocs } from "vuesho/content";
import { pageSchema } from "vuesho/schema";
import { z } from "zod";
const docs = defineDocs({
docs: { schema: pageSchema.extend({ author: z.string() }) },
});page.data.author is then a string in layouts and plugins, and a page without it fails the build. For meta files, extend metaSchema in meta.schema.
A schema can be any Standard Schema, like Valibot or ArkType. Don't declare fields that a plugin adds, like the blog plugin's tags.
Computed Defaults
To compute a default from the file, like a post's date from its file name, make schema a function. It receives each file's absolute path and source:
import { basename } from "node:path";
import { defineCollections } from "vuesho/content";
import { pageSchema } from "vuesho/schema";
import { z } from "zod";
const blog = defineCollections({
type: "doc",
dir: "blog",
schema: ({ path }) =>
pageSchema.extend({
date: z.coerce.date().default(new Date(basename(path).slice(0, 10))),
}),
});The URL keeps the date, like /blog/2026-01-31-hello, unless slugs in createSite() removes it:
createSite(
{ docs: docs.toSource(), blog: blog.toSource({ baseDir: "blog" }) },
{
// `blog/2026-01-31-hello.md` is served at `/blog/hello`
slugs: (file, next) =>
file.path.startsWith("blog/")
? next().map((slug) => slug.replace(/^\d{4}-\d{2}-\d{2}-/, ""))
: undefined,
},
);JSON Schema
vuesho dev, vuesho build and vuesho prepare write a JSON Schema for each collection to node_modules/.vuesho/json-schema, so your editor can check frontmatter and meta files:
content.docs.jsonandcontent.meta.jsonfordefineDocs()incontent/blog.jsonfor adefineCollections()inblog/, andcontent-blog.jsonfor one incontent/blog/
Point to a schema with $schema, or in your editor's settings:
{
"$schema": "../../node_modules/.vuesho/json-schema/content.meta.json",
"title": "Guide"
}There's no JSON Schema for a schema written as a function, or one from a library without Standard JSON Schema support, like Zod before 4.2.
Multiple Collections
defineCollections() defines a collection of one file type, and takes the page options at its top level. With type: "doc", it reads pages without meta files, like blog posts. Pass your collections to createSite() by key, and serve each under a folder with baseDir:
import { createSite } from "vuesho/config";
import { defineCollections, defineDocs } from "vuesho/content";
const docs = defineDocs({ dir: "content/docs" });
const blog = defineCollections({ type: "doc", dir: "content/blog" });
export default createSite({
docs: docs.toSource(),
blog: blog.toSource({ baseDir: "blog" }),
});The docs are at / and /install, and the post is at /blog/hello. Give every source except one a baseDir. Two sources with a file at the same path fail the build.
A source's key is the type of its pages. Once a layout or a plugin checks page.type, TypeScript narrows page.data to that source's fields:
if (page.type === "blog") console.log(page.data.title);On a site with one source, the type of every page is undefined.
Sidebar
The sources share one sidebar, where each baseDir is a folder. A meta file can hide that folder. It can also make the docs a root folder, so the sidebar shows only the docs pages:
{ "pages": ["...", "!blog"] }The blog plugin adds a post list and a post layout.
Data Collections
type: "meta" reads JSON, YAML or meta.ts files that aren't pages, like the authors of a blog:
import { defineCollections } from "vuesho/content";
import { z } from "zod";
const authors = defineCollections({
type: "meta",
dir: "authors",
schema: z.object({ name: z.string(), url: z.string().optional() }),
});name: Fuma Nama
url: https://fuma-nama.devAt the config's top level, toSource().files works only with YAML or JSON files and a synchronous schema. For a meta.ts collection or an async schema, read the entries in a plugin's hook instead. This config passes the authors to the blog plugin:
const authorsById = Object.fromEntries(
authors.toSource().files.map((file) => [file.path.replace(/\.yaml$/, ""), file.data]),
);
authorsById.fuma?.name; // "Fuma Nama"Per-Collection Options
These options apply to one collection's pages. Set them in docs of defineDocs(), or at the top level of defineCollections():
const docs = defineDocs({
docs: { lastModified: true },
});Markdown Options
markdown replaces the config's Markdown options for the collection's pages. It receives the config's options, so spread them to change only some. The built-in syntax and the plugins' Markdown extensions still apply:
const blog = defineCollections({
type: "doc",
dir: "blog",
markdown: (site) => ({ ...site, imageSize: { external: false } }),
});Components
components sets a separate components folder for a collection, so components that only its pages use don't load elsewhere:
const blog = defineCollections({
type: "doc",
dir: "blog",
components: "src/components/blog",
});A file in that folder takes priority over one in the site's src/components/content/ for the collection's pages. An included file compiles with the markdown options and components of the page that includes it.
Last Modified Dates
lastModified: true sets page.data.lastModified to the date of each file's last commit. The docs layout, the sitemap and the RSS feed show it:
const docs = defineDocs({ docs: { lastModified: true } });A file that Git doesn't track has no date, and a build without .git logs a warning.
Shallow Clones
In a shallow clone, like in CI, older pages show the latest commit's date. Fetch the full history, like with fetch-depth: 0 in actions/checkout.
When the build has no Git history, a plugin's getPageLastModified hook can fetch the dates from the GitHub API:
import type { Plugin } from "vuesho/config";
const dates = new Map<string, Promise<Date | undefined>>();
async function fetchLastCommit(file: string): Promise<Date | undefined> {
const url = `https://api.github.com/repos/acme/docs/commits?path=${encodeURIComponent(file)}&per_page=1`;
const headers = process.env.GITHUB_TOKEN
? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` }
: undefined;
const res = await fetch(url, { headers });
if (!res.ok) return;
const [commit] = (await res.json()) as { commit: { committer: { date: string } } }[];
return commit && new Date(commit.commit.committer.date);
}
const githubDates: Plugin = {
name: "site:github-dates",
async getPageLastModified(page) {
const file = await this.getPageFile(page);
if (!file) return;
if (!dates.has(file)) dates.set(file, fetchLastCommit(file));
return dates.get(file);
},
};
createSite(docs.toSource()).plugins(githubDates);getPageFile() returns the path from the project root, so in a monorepo, add the package's folder in front. Without GITHUB_TOKEN, GitHub allows 60 requests an hour.
Options
Prop
Type
Prop
Type