Content Hooks
Plugin hooks that render and transform pages.
Content hooks render the pages of a content source, and change page data, frontmatter, the page tree and Markdown. defineDocs() already renders its pages, so the getPage* hooks are for custom sources.
Each getPage* hook receives a page, and the latest plugin to return something other than undefined wins. So a plugin checks page.type, which is the key its source has in createSite():
import { createSite, type Source } from "vuesho/config";
import { defineDocs } from "vuesho/content";
type Release = { title: string; date: string; html: string };
const docs = defineDocs();
const changelog: Source<{ pageData: Release; metaData: {} }> = {
files: [
{
type: "page",
path: "changelog/0.2.0.md",
data: { title: "v0.2.0", date: "2026-11-01", html: "<p>Custom content sources.</p>" },
},
],
};
export default createSite({ docs: docs.toSource(), changelog }).plugins({
name: "acme:changelog",
getPageBody(page) {
if (page.type === "changelog") return { html: page.data.html };
},
getPageText(page) {
if (page.type === "changelog") return page.data.html.replace(/<[^>]+>/g, "");
},
getPageLastModified(page) {
if (page.type === "changelog") return new Date(page.data.date);
},
});Prop
Type
A page that has an absolutePath uses that file for its edit link. getPageStructuredData returns the headings and text that search indexes:
getPageStructuredData(page) {
if (page.type !== "changelog") return;
return { headings: [], contents: [{ content: page.data.html.replace(/<[^>]+>/g, "") }] };
},Page Bodies
getPageBody returns HTML, or the name and props of a body component from the plugin's theme:
getPageBody: (page) => ({ html: "<p>Rendered as HTML.</p>" }),Plugin<C, { bodies }> types the props, and the theme module maps each body to a component under bodies. The props reach the browser as JSON on every page load, so keep them small:
import type { AppShape, Plugin } from "vuesho/config";
export interface CardProps {
heading: string;
items: string[];
}
export function cardsPlugin<C extends AppShape>(
source: NoInfer<C["source"]>,
): Plugin<C, { bodies: { card: CardProps } }> {
return {
name: "acme:cards",
theme: "/src/cards/theme.ts",
getPageBody(page) {
if (page.type !== source) return;
const { heading, items } = page.data as Partial<CardProps>;
if (heading && items) return { type: "card", props: { heading, items } };
},
};
}A site replaces a body component in its theme's bodies. On a page from a Markdown collection, page.data keeps only the fields that the collection's schema and the plugins' frontmatter declare.
highlightCode() from vuesho/highlight highlights code on the server, for a body's props. Code in an unsupported language stays plain text:
import { highlightCode } from "vuesho/highlight";
const code = await highlightCode("const a = 1;", { lang: "ts" });Page Data
Page data is what the browser receives about a page, in usePage().value.pageData. transformPage returns the fields to change, and undefined unsets a field:
transformPage(_data, { path }) {
// No edit link on the generated reference.
if (path.startsWith("/reference/")) return { githubUrl: undefined };
},Prop
Type
A plugin declares a new field in its types, and a site reads the field's type as PageOf<typeof app, "docs">["pageData"]["readingTime"]. The value must be JSON:
import type { AppShape, Plugin } from "vuesho/config";
export function readingTimePlugin<C extends AppShape>(): Plugin<
C,
{ pageData: { /** Reading time in minutes. */ readingTime?: number } }
> {
return {
name: "acme:reading-time",
async transformPage(_data, { page }) {
const text = page && (await this.getPageText(page));
if (text) return { readingTime: Math.ceil(text.split(/\s+/).length / 200) };
},
};
}To compute a field from the tokens while the page compiles, use a Markdown rule instead.
Frontmatter Fields
frontmatter declares fields and their schemas. Vuesho validates them on every page, adds them to the JSON schema that editors read, and types them in PageOf<typeof app, "docs">["data"]:
import type { AppShape, Plugin } from "vuesho/config";
import { z } from "zod";
const status = z.enum(["beta", "deprecated"]);
export function deprecationPlugin<C extends AppShape>(): Plugin<
C,
{ frontmatter: { status?: z.infer<typeof status> } }
> {
return {
name: "acme:deprecation",
frontmatter: { status },
transformPage(_data, { page }) {
const value = page && (page.data as { status?: string }).status;
if (value === "deprecated") return { noindex: true };
},
};
}A custom source validates its frontmatter with validateFrontmatter(), which adds the plugins' fields to a schema:
import { getSiteContext } from "vuesho/config";
import { defaultPageSchema } from "vuesho/content";
import { parseFrontmatter } from "vuesho/markdown";
async function pageData(text: string) {
const { data } = parseFrontmatter(text);
return getSiteContext().validateFrontmatter(defaultPageSchema, data);
}Loader Hooks
init, configureLoader and configure run once, in that order, when the site starts. They don't run again when a dynamic source reloads.
configureLoader receives createSite()'s options and returns the ones it changes.
configure runs after the content loads, so it can check the content. An error thrown there stops the site:
configure() {
for (const page of this.getPages()) {
if (!page.data.title) throw new Error(`${page.path} has no title`);
}
},transformStorage and transformPageTree run every time the content loads, in plugin order. transformStorage changes a language's files before the page tree is built:
transformStorage({ storage }) {
for (const path of storage.getFiles()) {
if (path.split("/").some((part) => part.startsWith("_"))) storage.delete(path);
}
},Page Tree
transformPageTree changes page tree nodes, after the pageTree.transformers of createSite(). A transformer can set a name or an icon to a string, a component or a VNode. Other node fields reach usePageTree() when their values are JSON:
import { h } from "vue";
createSite(docs.toSource()).plugins({
name: "acme:code-titles",
transformPageTree: {
file(node) {
if (typeof node.name === "string" && node.name.endsWith("()")) {
return { ...node, name: h("code", node.name), kind: "function" };
}
return node;
},
},
});Inside a transformer, this holds the storage, the language and the tree's texts:
Prop
Type
Markdown Transforms
transformPageMarkdown changes a page's Markdown, which <page>.md, llms-full.txt and AI tools read. Each plugin receives the Markdown the previous one returned, and returning undefined keeps it:
transformPageMarkdown(markdown, { path }) {
return `${markdown}\n\n[Read this page on the site](${this.absoluteUrl(path)})`;
},The second argument also has the page, its page data and text, which is the Markdown without the title and description.
Rendering Markdown
defineDocs() compiles Markdown when the site builds. Markdown that the server receives, like a CMS's posts, renders with your own markdown-it and these exports of vuesho/markdown:
pageMarkdownSyntaxadds GFM, footnotes and the pages' heading IDs, with[#id]and[!toc].buildToc()andextractStructuredData()return the table of contents and the search data of the parsed tokens.
npm i markdown-itThis site renders each post's Markdown to HTML, and reads the table of contents and the search data from its tokens:
import markdownIt from "markdown-it";
import { createSite } from "vuesho/config";
import { highlightCode } from "vuesho/highlight";
import { pageMarkdownSyntax, extractStructuredData, buildToc } from "vuesho/markdown";
// A symbol key keeps the Markdown on the server.
const body = Symbol("body");
// HTML stays off, so HTML tags in the Markdown render as text.
const md = markdownIt({ linkify: true }).use(pageMarkdownSyntax);
// markdown-it highlights synchronously, so the code blocks are highlighted with your code themes before it renders.
async function render(text: string) {
const tokens = md.parse(text, {});
const blocks = new Map<string, string>();
for (const { type, info, content } of tokens) {
if (type !== "fence") continue;
const { pre, html } = await highlightCode(content, { lang: info.split(" ")[0] || "text" });
const attributes = Object.entries(pre).map(
([name, value]) => ` ${name}="${md.utils.escapeHtml(value)}"`,
);
blocks.set(content, `<pre${attributes.join("")}><code>${html}</code></pre>`);
}
return md.renderer.render(
tokens,
{ ...md.options, highlight: (code) => blocks.get(code) ?? "" },
{},
);
}
async function listPosts() {
const response = await fetch("https://cms.example.com/posts");
const posts: { slug: string; title: string; body: string }[] = await response.json();
return posts.map((post) => ({
type: "page" as const,
path: `${post.slug}.md`,
data: { title: post.title, [body]: post.body },
}));
}
export default createSite({ posts: { files: listPosts, staleTime: 60_000 } }).plugins({
name: "acme:posts",
async getPageBody(page) {
if (page.type === "posts") return { html: await render(page.data[body]) };
},
getPageToc(page) {
if (page.type === "posts") return buildToc(md.parse(page.data[body], {}));
},
getPageStructuredData(page) {
if (page.type === "posts") return extractStructuredData(md.parse(page.data[body], {}));
},
getPageText(page) {
if (page.type === "posts") return page.data[body];
},
});Your markdown-it instance uses only the highlight option of the config's markdown, through highlightCode(), so add markdown-it plugins to it with use(). To render components, like <Callout>, return a body component instead, as Page Bodies shows.