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 #

config(handler: GeneratorPluginHandler<SiteConfig>): void

Changes the site config. Values are raw here: defaults are not applied yet.

configResolved(handler: GeneratorPluginHandler<ResolvedSiteConfig>): void

Reads the final site config once every config() hook ran, with defaults applied and values normalized. Runs before markdown() and vite().

markdown(handler: GeneratorPluginHandler<MarkdownExit>): void

Changes the Markdown renderer, for example to add a markdown-it plugin.

pagesRegisterPluginPages

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.

frontmatter(schema: FrontmatterSchema): void

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.

~standardStandardSchemaProps<Input, Output>
pageData(handler: PageDataHandler): void

Changes the data of each page before it is sent to the browser.

pageArtifact(handler: GeneratorPluginHandler<Readonly<PageBuildArtifact>>): void

Reads each built page, for example to collect data for an index.

vite(handler: GeneratorPluginHandler<UserConfig>): void

Changes the Vite config of the site.

buildArtifacts(handler: GeneratorPluginHandler<BuildArtifactsContext>): void

Runs once after the build, with every page; can write extra files such as a sitemap.

Full type signature
TypeScript
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
}

Edit this page

Comments