-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
47 lines (41 loc) · 1.4 KB
/
build.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
const fse = require('fs-extra');
const { titleCase } = require('title-case');
const { noCase } = require('change-case');
const yaml = require('js-yaml');
const ejs = require('ejs');
const sass = require('sass');
// Create folders
if (!fse.existsSync('dist')) {
fse.mkdirpSync('dist/css');
fse.mkdirSync('dist/js');
}
// Copy static assets
fse.copySync('src/assets', 'dist', { overwrite: true });
fse.copySync('src/js', 'dist/js', { overwrite: true });
// Build CSS
const sassResult = sass.renderSync({
file: 'src/scss/style.scss',
sourceMap: true,
outFile: 'dist/css/style.css',
});
fse.writeFileSync('dist/css/style.css', sassResult.css.toString());
fse.writeFileSync('dist/css/style.css.map', sassResult.map.toString());
// Build HTML
const categories = require('build-categories');
const entryTemplate = ejs.compile(fse.readFileSync('src/views/pages/entry.ejs').toString(), {
filename: 'src/views/pages/entry.ejs',
});
for (const dataDir of fse.readdirSync(`data`)) {
for (const entryFile of fse.readdirSync(`data/${dataDir}`, {})) {
const entryName =
(entryData.config && entryData.config.title) || titleCase(noCase(entryFile.split('.')[0]));
const entryData = yaml.load(fse.readFileSync(`data/${dataDir}/${entryFile}`));
const html = entryTemplate({
entryData,
entryName,
distUrl: '/',
publicUrl: '/',
});
fse.writeFileSync(`dist/${entryName}.html`, html);
}
}