forked from rtfpessoa/diff2html
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease-website.js
69 lines (53 loc) · 1.88 KB
/
release-website.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var fs = require('fs');
var hogan = require('hogan.js');
var root = 'website/templates';
var pagesRoot = root + '/pages';
var websitePages = fs.readdirSync(root + '/pages');
var template = hogan.compile(readFile(root + '/template.mustache'));
var options = {
'all': {
'demoUrl': 'demo.html?diff=https://github.com/rtfpessoa/diff2html/pull/106'
},
'demo': {
'extraClass': 'template-index-min'
}
};
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'));
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];
}
}
// Allow each page to have custom options
var pageOptions = options[page] || {};
for (key in pageOptions) {
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;
var pageHtml = template.render(templateOptions);
writeFile('docs/' + page + '.html', pageHtml);
});
function readFile(filePath) {
try {
return fs.readFileSync(filePath, 'utf8');
} catch (_ignore) {
}
return '';
}
function writeFile(filePath, content) {
return fs.writeFileSync(filePath, content);
}