-
Notifications
You must be signed in to change notification settings - Fork 26
/
build.js
76 lines (67 loc) · 1.7 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
const fs = require('fs')
const marked = require('marked')
const path = require('path')
const rimraf = require('rimraf')
const hljs = require('highlight.js')
const base = path.join(__dirname, 'problems')
rimraf.sync(path.join(__dirname, 'build'))
marked.setOptions({
highlight: function (code, lang) {
const language = hljs.getLanguage(lang) ? lang : 'plaintext'
return hljs.highlight(code, { language }).value
},
langPrefix: 'hljs language-'
})
try {
fs.mkdirSync(path.join(__dirname, 'build'))
} catch (err) {
// do nothing
}
const css = fs.readFileSync('./node_modules/highlight.js/styles/github-dark.css', 'utf8')
const style = `<style>
body {
padding: 40px;
}
.markdown-body {
-webkit-text-size-adjust: 100%;
text-size-adjust: 100%;
color: #333;
font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;
font-size: 16px;
line-height: 1.6;
word-wrap: break-word;
padding: 5rem 2rem 8rem 2rem;
width: 60rem;
margin-left: auto;
margin-right: auto;
}
.markdown-body h3 {
font-size: 1.5em;
}
.markdown-body h4 {
font-size: 1.25em;
}
.markdown-body pre {
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
}
${css}
</style>`
fs.readdirSync(base).forEach(name => {
const input = path.join(base, name)
const output = path.join(__dirname, 'build', name.replace('.md', '.html'))
const html = marked.parse(fs.readFileSync(input, 'utf-8'))
const file = `<html>
<head>
<title>Problem ${name.replace('.md', '')}</title>
${style}
</head>
<body class="markdown-body">
${html}
</body>
</html>`
fs.writeFileSync(output, file)
})