import { IPluginBuilder, Plugin } from "./typings.js"; import { readFileAsText, writeTextAsFile } from "./toolchain-helpers.js"; type StartPagePluginOptions = { indexTemplatePath: string; contentTemplateTag: string; }; export class StartPagePlugin implements IPluginBuilder { options: StartPagePluginOptions; constructor(options: StartPagePluginOptions) { this.options = options; } build(): Plugin { return (builderContext) => { let htmlTemplate = readFileAsText(this.options.indexTemplatePath); const links = builderContext.menuManifest .map((m) => { const name = m.name.slice(m.name.indexOf("-") + 1).replaceAll("-", " "); return `

${name}

Read here!
` }) .reverse(); const html = ` ${links.join("")} `; htmlTemplate = htmlTemplate.replace("{{content}}", html); console.log("Generating index", this.options.indexTemplatePath); writeTextAsFile( `${builderContext.outputDirectory}/index.html`, htmlTemplate ); }; } }