diff2html/scripts/release-website.js

70 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-08-23 17:20:54 +00:00
var fs = require('fs');
var hogan = require('hogan.js');
2016-10-09 15:56:58 +00:00
var root = 'website/templates';
var pagesRoot = root + '/pages';
2016-08-23 17:20:54 +00:00
2016-10-09 15:56:58 +00:00
var websitePages = fs.readdirSync(root + '/pages');
2016-08-23 17:20:54 +00:00
2016-10-09 15:56:58 +00:00
var template = hogan.compile(readFile(root + '/template.mustache'));
2016-08-23 17:20:54 +00:00
2016-10-15 21:18:16 +00:00
var options = {
'all': {
'demoUrl': 'demo.html?diff=https://github.com/rtfpessoa/diff2html/pull/106'
},
'demo': {
2016-10-15 21:18:16 +00:00
'extraClass': 'template-index-min'
}
};
2016-10-09 15:56:58 +00:00
websitePages.map(function(page) {
var pagePartialTemplate = hogan.compile(readFile(pagesRoot + '/' + page + '/' + page + '.partial.mustache'));
var pageAssetsTemplate = hogan.compile(readFile(pagesRoot + '/' + page + '/' + page + '-assets.partial.mustache'));
var pageScriptsTemplate = hogan.compile(readFile(pagesRoot + '/' + page + '/' + page + '-scripts.partial.mustache'));
2016-10-15 21:18:16 +00:00
var templateOptions = {};
var key;
// Allow the pages to share common options
var genericOptions = options['all'] || {};
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
var pageOptions = options[page] || {};
for (key in pageOptions) {
2016-10-15 21:18:16 +00:00
if (pageOptions.hasOwnProperty(key)) {
templateOptions[key] = pageOptions[key];
}
}
var pagePartial = pagePartialTemplate.render(templateOptions);
var pageAssets = pageAssetsTemplate.render(templateOptions);
var pageScripts = pageScriptsTemplate.render(templateOptions);
templateOptions.assets = pageAssets;
templateOptions.scripts = pageScripts;
templateOptions.content = pagePartial;
2016-10-15 21:18:16 +00:00
var pageHtml = template.render(templateOptions);
2016-10-09 15:56:58 +00:00
writeFile('docs/' + page + '.html', pageHtml);
});
2016-08-23 17:20:54 +00:00
function readFile(filePath) {
2016-10-09 15:56:58 +00:00
try {
return fs.readFileSync(filePath, 'utf8');
} catch (_ignore) {
}
return '';
2016-08-23 17:20:54 +00:00
}
function writeFile(filePath, content) {
return fs.writeFileSync(filePath, content);
}