Broke out all functionality into plugins
This commit is contained in:
32
packages/@zblog/toolchain/src/start-page-plugin.ts
Normal file
32
packages/@zblog/toolchain/src/start-page-plugin.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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) => `<a href='${m.link}'>${m.name}</a>`)
|
||||
.reverse();
|
||||
const unorderedListItems = links.map((l) => `<li>${l}</li>`).join("\r\n");
|
||||
const html = `
|
||||
<ul>
|
||||
${unorderedListItems}
|
||||
<ul>
|
||||
`;
|
||||
htmlTemplate = htmlTemplate.replace("{{content}}", html);
|
||||
writeTextAsFile(
|
||||
`${builderContext.outputDirectory}/index.html`,
|
||||
htmlTemplate
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user