-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
57 lines (46 loc) · 1.25 KB
/
index.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
const yaml = require("js-yaml");
const fs = require("fs");
const nunjucks = require("nunjucks");
const groups = yaml
.safeLoad(fs.readFileSync("groups.yml", "utf8"))
.sort((a, b) => {
const nameA = a.name.toUpperCase();
const nameB = b.name.toUpperCase();
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
});
buildPages();
async function buildPages() {
try {
let pages = fs.readdirSync(`pages/`);
pages = pages.filter(page => page.includes(".njk"));
pageNames = pages.map(page => page.split(".")[0]);
const pageTitles = {
index: "Awesome Athens",
about: "About",
contact: "Contact",
events: "Upcoming events"
};
if (!fs.existsSync("public")) {
fs.mkdirSync("public");
}
pages.forEach(page => {
const currentPage = page.split(".")[0];
const renderedPage = nunjucks.render(`pages/${page}`, {
groups,
title: pageTitles[currentPage]
});
fs.closeSync(fs.openSync(`${__dirname}/public/${currentPage}.html`, "a"));
fs.writeFileSync(`${__dirname}/public/${currentPage}.html`, renderedPage);
});
console.log("Build completed!");
return 0;
} catch (e) {
console.log(e);
}
}