-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
47 lines (40 loc) · 1.3 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
const fs = require('fs-extra')
const { formatLatex, replaceFormulaSpansWithButtons, replaceInPath, replaceTagRandom } = require('./common')
const contentPath = './content/'
const buildPath = './build/'
const indexHtml = 'index.html'
const readFromPath = (path) =>
fs
.readFile(contentPath + path)
.then((file) => formatLatex(file.toString()))
.then((output) => replaceFormulaSpansWithButtons(output))
.then((output) => replaceTagRandom(output))
.then((output) => fs.writeFile(buildPath + path, output))
.then(() => {
console.log(`Done with ${path}`)
return
})
const replaceTaulukkoWithBuild = (file) =>
fs.readFile(file).then((data) => {
var path = replaceInPath(data.toString())
return fs.writeFile(file, path, 'utf8')
})
const getFileNamesFromDir = async (path) => {
const dirents = await fs.readdir(path, { withFileTypes: true })
return dirents.filter((dirent) => dirent.isFile()).map((dirent) => dirent.name)
}
const build = async () => {
await fs.ensureDir(buildPath)
await replaceTaulukkoWithBuild(indexHtml)
const contentFileNames = await getFileNamesFromDir(contentPath)
return Promise.all(contentFileNames.map(readFromPath))
}
build()
.then(() => {
console.log('Finished')
return
})
.catch((err) => {
console.error(err)
return
})