A simple, folder-driven static-site engine.
bun ssg fs
at dev 38 lines 1.6 kB view raw
1/** 2 * Plugin API types. 3 */ 4 5import type { Logger } from "../logging/logger"; 6import type { Site, Collection, Entry, Block } from "../core/model"; 7import Handlebars from "handlebars"; 8import type { WebetteEnv } from "../config/env"; 9 10export type PluginContext = { 11 rootDir: string; 12 env: WebetteEnv; 13 logger: Logger; 14 readContent: boolean; 15 exportDir: string; 16 pluginId: string; 17 addExpectedOutput: (relativePath: string) => void; 18 addExpectedDir: (relativeDir: string) => void; 19}; 20 21export interface Plugin { 22 // Optional identifier; if missing we derive one from the filename 23 pluginId?: string; 24 // Called after env/site load, before scanning 25 onInit?: (ctx: PluginContext) => Promise<void> | void; 26 // Called after scan/routes, before content resolution 27 onScan?: (site: Site, ctx: PluginContext) => Promise<Site | void> | Site | void; 28 // Called after content resolution, before timestamps/export 29 onResolved?: (site: Site, ctx: PluginContext) => Promise<Site | void> | Site | void; 30 // Per-block mutation after resolution (subBlocks handled recursively) 31 transformBlock?: (block: Block, ctx: PluginContext & { entry: Entry; collection: Collection }) => Promise<Block | void> | Block | void; 32 // Per-entry mutation after blocks 33 transformEntry?: (entry: Entry, ctx: PluginContext & { collection: Collection }) => Promise<Entry | void> | Entry | void; 34 // Template extensions (helpers/partials/layouts) 35 extendTemplates?: (hb: typeof Handlebars, ctx: PluginContext) => Promise<void> | void; 36} 37 38export type LoadedPlugin = Plugin & { pluginId: string };