2019-10-06 20:04:33 +00:00
|
|
|
#!/usr/bin/env node
|
2016-08-23 17:20:54 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const fs = require("fs");
|
2016-08-23 17:20:54 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const hogan = require("hogan.js");
|
2016-08-23 17:20:54 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const root = "website/templates";
|
|
|
|
|
const pagesRoot = root + "/pages";
|
2016-08-23 17:20:54 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const websitePages = fs.readdirSync(root + "/pages");
|
2016-08-23 17:20:54 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const template = hogan.compile(readFile(root + "/template.mustache"));
|
|
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
|
all: {
|
|
|
|
|
demoUrl: "demo.html?diff=https://github.com/rtfpessoa/diff2html/pull/106"
|
2016-10-16 16:40:36 +00:00
|
|
|
},
|
2019-10-06 20:04:33 +00:00
|
|
|
demo: {
|
|
|
|
|
extraClass: "template-index-min"
|
2016-10-15 21:18:16 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-09 15:56:58 +00:00
|
|
|
websitePages.map(function(page) {
|
2019-10-06 20:04:33 +00:00
|
|
|
const pagePartialTemplate = hogan.compile(readFile(pagesRoot + "/" + page + "/" + page + ".partial.mustache"));
|
|
|
|
|
const pageAssetsTemplate = hogan.compile(readFile(pagesRoot + "/" + page + "/" + page + "-assets.partial.mustache"));
|
|
|
|
|
const pageScriptsTemplate = hogan.compile(
|
|
|
|
|
readFile(pagesRoot + "/" + page + "/" + page + "-scripts.partial.mustache")
|
|
|
|
|
);
|
2016-10-15 21:18:16 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const templateOptions = {};
|
2016-10-16 16:40:36 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
let key;
|
2016-10-16 16:40:36 +00:00
|
|
|
|
|
|
|
|
// Allow the pages to share common options
|
2019-10-06 20:04:33 +00:00
|
|
|
const genericOptions = options.all || {};
|
2016-10-16 16:40:36 +00:00
|
|
|
for (key in genericOptions) {
|
|
|
|
|
if (genericOptions.hasOwnProperty(key)) {
|
|
|
|
|
templateOptions[key] = genericOptions[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-15 21:18:16 +00:00
|
|
|
|
|
|
|
|
// Allow each page to have custom options
|
2019-10-06 20:04:33 +00:00
|
|
|
const pageOptions = options[page] || {};
|
2016-10-16 16:40:36 +00:00
|
|
|
for (key in pageOptions) {
|
2016-10-15 21:18:16 +00:00
|
|
|
if (pageOptions.hasOwnProperty(key)) {
|
|
|
|
|
templateOptions[key] = pageOptions[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const pagePartial = pagePartialTemplate.render(templateOptions);
|
|
|
|
|
const pageAssets = pageAssetsTemplate.render(templateOptions);
|
|
|
|
|
const pageScripts = pageScriptsTemplate.render(templateOptions);
|
2016-10-16 16:40:36 +00:00
|
|
|
|
|
|
|
|
templateOptions.assets = pageAssets;
|
|
|
|
|
templateOptions.scripts = pageScripts;
|
|
|
|
|
templateOptions.content = pagePartial;
|
|
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const pageHtml = template.render(templateOptions);
|
|
|
|
|
writeFile("docs/" + page + ".html", pageHtml);
|
2016-10-09 15:56:58 +00:00
|
|
|
});
|
2016-08-23 17:20:54 +00:00
|
|
|
|
|
|
|
|
function readFile(filePath) {
|
2016-10-09 15:56:58 +00:00
|
|
|
try {
|
2019-10-06 20:04:33 +00:00
|
|
|
return fs.readFileSync(filePath, "utf8");
|
|
|
|
|
} catch (_ignore) {}
|
2016-10-09 15:56:58 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
return "";
|
2016-08-23 17:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function writeFile(filePath, content) {
|
|
|
|
|
return fs.writeFileSync(filePath, content);
|
|
|
|
|
}
|