-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcompile.js
More file actions
41 lines (33 loc) · 1.15 KB
/
compile.js
File metadata and controls
41 lines (33 loc) · 1.15 KB
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
#!/usr/bin/env node
require('shelljs/global');
var path = require('path');
var nunjucks = require('nunjucks');
config.fatal = true;
config.silent = true;
rm('-rf', 'build');
mkdir('build');
['js', 'styles', 'assets'].forEach(dir => cp('-r', dir, 'build'));
ls('-R', 'pages').filter(file => file.slice(-5) === '.html').forEach(page => {
mkdir('-p', path.join('build', path.dirname(page)));
const str = cat(path.join('pages', page)).toString();
const out = nunjucks.renderString(str, getContext(path.basename(page, '.html')));
out.to(path.join('build', page)); // FIXME: Won't be compatable with shelljs@0.7.0
});
function getContext (pageName) {
const defaultContext = {
__DEV__: (typeof process.env.DEV === 'string') ? process.env.DEV.trim() === '1' : process.env.NODE_ENV !== 'production',
};
const pagesContexts = {
"team":{
"members": require('./data/members.json')
},
"press": {
"stories": require('./data/press.json')
},
"sponsors":{
"sponsors":require('./data/sponsors.json'),
"individualSponsors":require('./data/individualSponsors.json'),
}
}
return Object.assign({}, defaultContext, pagesContexts[pageName]);
}