-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
81 lines (73 loc) · 1.58 KB
/
Copy pathindex.js
File metadata and controls
81 lines (73 loc) · 1.58 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { resumePath } from "#root/config.js";
import { readFile, writeFile } from "fs/promises";
import browserSync from "browser-sync";
import marked from "marked";
import customHeadingId from "marked-custom-heading-id";
import path from "path";
const renderer = {
table(header, body) {
return `<table>${body}</table>`;
},
};
marked.use({ renderer });
marked.use(customHeadingId());
export async function convertMarkdown2Html() {
try {
const data = await readFile(resumePath, "utf8");
const html = await marked(data);
return html;
} catch (e) {
console.log(e);
return "";
}
}
export async function exportMarkdown2Html() {
const html = await convertMarkdown2Html();
const content = decorateHtml(html);
await save('./resume.html', content);
}
export function decorateHtml(html) {
return `
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/styles/index.css" type="text/css"></link>
</head>
<body class="markdown-body">
<div id="custom">
${html}
</div>
</body>
</html>
`;
}
async function save(dist, content) {
try {
await writeFile(dist, content);
} catch (e) {
console.log(e);
}
}
exportMarkdown2Html();
browserSync({
server: {
baseDir: ".",
index: "resume.html"
},
files: [
{
match: ["styles/*.css"],
fn: () => {
browserSync.reload("*.css");
}
},
{
match: [resumePath],
fn: () => {
exportMarkdown2Html();
browserSync.reload();
}
}
]
});