implement simple build system for static html

This commit is contained in:
ansuz
2016-08-16 17:57:57 +02:00
parent eb797aa7cd
commit 6b86c11b2c
8 changed files with 195 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
var Fs = require("fs");
// read a file
var read = function (path) {
return Fs.readFileSync(path, 'utf-8');
};
// write a file
var write = function (path, src) {
return Fs.writeFileSync(path, src);
};
// basic templating
var swap = function (src, dict) {
return src.replace(/\{\{(.*?)\}\}/g, function (a, b) {
return dict[b] || b;
});
};
// read the template file
var template = read('./template.html');
// read page fragments
var fragments = {};
[ 'analytics',
'index',
'fork',
'terms',
'privacy',
].forEach(function (name) {
fragments[name] = read('./fragments/' + name + '.html');
});
// build static pages
['index', 'privacy', 'terms'].forEach(function (page) {
var source = swap(template, {
fork: fragments.fork,
analytics: fragments.analytics,
main: fragments[page],
});
write('../' + page + '.html', source);
});