GeneratorPluginAPI #
What setup(api) of a Generator Plugin receives: one method per hook. A method adds a handler; the handlers of several plugins run in plugin order.
Fields #
Changes the site config. Values are raw here: defaults are not applied yet.
Reads the final site config once every config() hook ran, with defaults
applied and values normalized. Runs before markdown() and vite().
Changes the Markdown renderer, for example to add a markdown-it plugin.
Adds a group of pages that do not come from a Markdown file: the route
template first, then where the content comes from, a file template or a
generator function. Groups are collected after every configResolved(),
when the page list is first needed. A plugin can call it more than once;
each call is its own group.
Adds rules for the frontmatter keys this plugin reads: a Zod object, or a schema from another Standard Schema library such as Valibot. Every page is checked against the rules of every plugin and of the site, and editors get the same rules as hints. Keys the schema does not mention stay allowed.
Changes the data of each page before it is sent to the browser.
Reads each built page, for example to collect data for an index.
Changes the Vite config of the site.
Runs once after the build, with every page; can write extra files such as a sitemap.
Full type signature
interface GeneratorPluginAPI {
config: (handler: GeneratorPluginHandler<SiteConfig>) => void
configResolved: (handler: GeneratorPluginHandler<ResolvedSiteConfig>) => void
markdown: (handler: GeneratorPluginHandler<MarkdownExit>) => void
pages: RegisterPluginPages
frontmatter: (schema: FrontmatterSchema) => void
pageData: (handler: PageDataHandler) => void
pageArtifact: (handler: GeneratorPluginHandler<Readonly<PageBuildArtifact>>) => void
vite: (handler: GeneratorPluginHandler<UserConfig>) => void
buildArtifacts: (handler: GeneratorPluginHandler<BuildArtifactsContext>) => void
}

Comments