-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgenerate.js
44 lines (36 loc) · 1.03 KB
/
generate.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
import { render } from "ejs"
import { readFileSync, writeFileSync, readdirSync, statSync } from "node:fs"
import minifyHtml from "@minify-html/node"
import { URL } from "node:url"
const PUBLISH_DIR = "public"
const projects = []
readdirSync("public").forEach((item) => {
const basePath = PUBLISH_DIR + "/" + item
const obj = statSync(basePath)
if (obj.isFile()) return
let meta = {
name: item,
author: "-",
description: "-",
}
try {
meta = {
...meta,
...JSON.parse(readFileSync(basePath + "/meta.json", "utf-8")),
}
} catch (error) {}
meta.path = "/" + item
meta.external = false
if (meta.redirectPath !== undefined) {
try {
new URL(meta.redirectPath)
meta.path = meta.redirectPath
meta.external = true
} catch {}
}
projects.push(meta)
})
const template = readFileSync("template.ejs", "utf-8")
const htmlContent = render(template, { projects }, {})
const minified = minifyHtml.minify(Buffer.from(htmlContent), {})
writeFileSync(`${PUBLISH_DIR}/index.html`, minified)