-
Notifications
You must be signed in to change notification settings - Fork 6
/
render.js
82 lines (66 loc) · 2.14 KB
/
render.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
77
78
79
80
81
82
import {
mkdir, readdir, readFile, unlink, writeFile,
} from "fs/promises";
import toc from "markdown-toc";
const renderContent = async () => {
const destination = "./projects/site/src/rendered-content";
mkdir(destination, { recursive: true });
const preexisting = await readdir(destination);
await Promise.all(preexisting.map(async (file) => {
await unlink(`${destination}/${file}`);
}));
const source = "./content";
const order = [
"title",
"intro",
"installation",
"basic-usage",
"full-configuration",
"examples",
"semantics",
"alternatives",
"license-and-contributing",
"about-this-site",
];
const content = order.map((stem) => readFile(`${source}/${stem}.md`));
const combined = (await Promise.all(content)).join("\n\n");
let formatted = combined.replace(/\\/gm, "\\\\");
formatted = formatted
.replace("# 🌗 Tailwind CSS Theme Variants", "# Introducing: Theme Variants for Tailwind CSS")
.replace("# ⬇️", "# ")
.replace("# 🛠", "# ")
.replace("# ⚙️", "# ")
.replace("# 📄", "# ");
formatted = formatted.replace(/^⚠️ (.+)$/gm, "<WatchOut>\n\n$1\n\n</WatchOut>");
formatted = formatted.replace(/^💡 (.+)$/gm, "<Idea>\n\n$1\n\n</Idea>");
formatted = formatted.replace(/✅/gm, "<Feature type='yes' />");
formatted = formatted.replace(/🟡/gm, "<Feature type='kinda' />");
formatted = formatted.replace(/❌/gm, "<Feature type='no' />");
formatted = `
<script>
import WatchOut from "../components/WatchOut.svelte";
import Idea from "../components/Idea.svelte";
import Feature from "../components/Feature.svelte";
</script>
${formatted}`;
writeFile(`${destination}/site-all.svx`, formatted);
writeFile(`${destination}/site-toc.svx`, toc(formatted).content);
};
const renderReadme = async () => {
const contentOrder = [
"title",
"intro",
"installation",
"basic-usage",
"full-configuration",
"examples",
"semantics",
"alternatives",
"license-and-contributing",
];
const content = contentOrder.map((stem) => readFile(`./content/${stem}.md`));
const combined = (await Promise.all(content)).join("\n\n");
writeFile("./README.md", combined);
};
renderContent();
renderReadme();