-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-html.ts
79 lines (66 loc) · 2.2 KB
/
build-html.ts
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
68
69
70
71
72
73
74
75
76
77
78
79
import Handlebars from "handlebars";
import cv from "./cv.json";
import template from "./theme/template.txt";
import { readdir, mkdir } from "node:fs/promises";
import { marked } from "marked";
export function dateToYear(date: string): string {
return new Date(date).getFullYear().toString();
}
export function dateToMonthName(date: string): string {
return new Date(date).toLocaleString("en-UK", { month: "long" });
}
export function dateToDay(date: string): string {
return new Date(date).toLocaleString("en-UK", { day: "numeric" });
}
let icons: { [key: string]: string } = {
googleplus: "fab fa-google-plus",
flickr: "fab fa-flickr",
codepen: "fab fa-codepen",
soundcloud: "fab fa-soundcloud",
reddit: "fab fa-reddit",
tumblr: "fab fa-tumblr",
stackoverflow: "fab fa-stack-overflow",
"stack-overflow": "fab fa-stack-overflow",
blog: "fas fa-rss",
rss: "fas fa-rss",
gitlab: "fab fa-gitlab",
github: "fab fa-github",
};
export function iconify(network: string): string {
network = network.toLowerCase();
if (network in icons) {
return icons[network];
}
return `fab fa-${network}`;
}
export function markdown(text: string): string {
return marked(text);
}
export function compile(template: string, content: object): string {
const hb = Handlebars.compile(template);
Handlebars.registerHelper("year", dateToYear);
Handlebars.registerHelper("month", dateToMonthName);
Handlebars.registerHelper("day", dateToDay);
Handlebars.registerHelper("iconify", iconify);
Handlebars.registerHelper("markdown", markdown);
return hb(content);
}
export async function buildHTML() {
// if /build does not exist, create it
try {
await readdir("./build");
} catch (err) {
await mkdir("./build");
}
// copy all files in /theme to /build
Bun.write("./build/style.css", Bun.file("./theme/style.css"));
Bun.write("./build/print.css", Bun.file("./theme/print.css"));
Bun.write("./build/bootstrap.min.css", Bun.file("./theme/bootstrap.min.css"));
// compile template
const html = compile(template, cv);
await Bun.write("./build/cv.html", html);
console.log(`You can find your HTML cv at ./build/cv.html. Nice work! 🚀`);
}
if (import.meta.main) {
await buildHTML();
}