-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.js
More file actions
67 lines (53 loc) · 1.6 KB
/
Copy pathgenerate.js
File metadata and controls
67 lines (53 loc) · 1.6 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
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
const fs = require('fs');
const showdown = require('showdown');
const pug = require('pug');
const articles = require('./articles');
const frontpage = require('./frontpage');
const about = require('./about');
converter = new showdown.Converter();
fs.rmSync('./docs', { recursive: true, force: true });
fs.mkdirSync('./docs');
if (about.exists()) {
const about = true;
}
const info = JSON.parse(fs.readFileSync('./content/info.json'));
// About page
const aboutHtml = pug.renderFile('./views/about.pug', {
info,
content: converter.makeHtml(about.read()),
about
});
fs.writeFileSync('./docs/about.html', aboutHtml);
// Frontpage
if (frontpage.exists()) {
const frontpageHtml = pug.renderFile('./views/index.pug', {
info,
content: converter.makeHtml(frontpage.read()),
about
});
fs.writeFileSync('./docs/index.html', frontpageHtml);
} else {
const frontpageHtml = pug.renderFile('./views/list.pug', {
info,
articles: articles.list()
});
fs.writeFileSync('./docs/index.html', frontpageHtml);
}
// Blog
const blogHtml = pug.renderFile('./views/list.pug', {
info,
articles: articles.list(),
about
});
fs.writeFileSync('./docs/blog.html', blogHtml);
// Individual articles
console.log(`Generating pages for ${articles.list().length} articles...`);
articles.list().forEach((article) => {
const articleHtml = pug.renderFile('./views/article.pug', {
info,
content: articles.read(article.name, 0, true),
title: article.name,
about
});
fs.writeFileSync(`./docs/${article.name}.html`, articleHtml);
});