Skip to Content
Vuesho

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:

vuesho.config.ts
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:

vuesho.config.ts
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 zod
vuesho.config.ts
import { 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:

vuesho.config.ts
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:

vuesho.config.ts
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.json and content.meta.json for defineDocs() in content/
  • blog.json for a defineCollections() in blog/, and content-blog.json for one in content/blog/

Point to a schema with $schema, or in your editor's settings:

content/guide/meta.json
{
  "$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:

vuesho.config.ts
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" }), 
});
index.md
install.md
hello.md

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.

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:

content/docs/meta.json
{ "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:

vuesho.config.ts
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() }),
});
authors/fuma.yaml
name: Fuma Nama
url: https://fuma-nama.dev

At 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:

vuesho.config.ts
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():

vuesho.config.ts
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:

vuesho.config.ts
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:

vuesho.config.ts
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:

vuesho.config.ts
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.

Options

Prop

Type

Prop

Type