-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
54 lines (44 loc) · 1.23 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
48
49
50
51
52
53
54
import Mustache from "./mustache.js";
import fs from "node:fs";
import restaurants from "./mittwochsdates/restaurants.js";
let templates = {};
function load(name) {
if (!templates.name)
templates[name] = fs.readFileSync("templates/mittwochsdates/" + name, { encoding: "utf-8" });
return templates[name];
}
function restaurantView(restaurant, index) {
return {
number: index + 1,
...restaurant
};
}
function count(iterable, predicate) {
let count = 0;
for (let item of iterable) {
if (predicate(item))
count++;
}
return count;
}
let view = {
restaurants: restaurants.map(restaurantView).reverse(),
stats: {
total: restaurants.length,
starred: count(restaurants, r => r.starred),
faina: {
total: count(restaurants, r => r.by === "faina"),
starred: count(restaurants, r => r.starred && r.by === "faina")
},
lars: {
total: count(restaurants, r => r.by === "lars"),
starred: count(restaurants, r => r.starred && r.by === "lars")
}
}
};
fs.mkdirSync("site/mittwochsdates", { recursive: true });
fs.cpSync("static/", "site/", { recursive: true });
fs.writeFileSync(
"site/mittwochsdates/index.html",
Mustache.render("{> index.html}", view, load, ["{", "}"])
);