@@ -0,0 +1,59 @@
1+const fs = require("fs");
2+const path = require("path");
3+const matter = require("gray-matter");
4+const toml = require("@iarna/toml");
5+
6+const options = {
7+ engines: {
8+ toml: toml.parse.bind(toml),
9+ },
10+ language: "toml",
11+ delimiters: "+++",
12+};
13+
14+const glossary = [];
15+
16+function buildGlossary(dir) {
17+ const children = fs.readdirSync(dir, { withFileTypes: true });
18+ const pages = children.filter((f) => f.isFile() && f.name !== "_index.md");
19+ const subdirs = children.filter(
20+ (f) => f.isDirectory()
21+ );
22+ pages.map((page) => {
23+ const { data } = matter(fs.readFileSync(path.join(dir, page.name)), options);
24+ const glossaryEntry = data.glossaryEntry
25+ ? Object.values(data.glossaryEntry)
26+ .map((e) => ({
27+ ...e, ...{
28+ url: "https://urbit.org" + path.join(
29+ dir.substr(dir.indexOf("content") + 7),
30+ "/",
31+ page.name.replace(/.md$/, "")
32+ )
33+ }
34+ }))
35+ : [];
36+ glossaryEntry.forEach((entry) => glossary.push(entry));
37+ });
38+
39+ Object.fromEntries(
40+ subdirs.map((subdir) => [
41+ subdir.name,
42+ buildGlossary(path.join(dir, subdir.name)),
43+ ])
44+ );
45+}
46+
47+buildGlossary(path.join(process.cwd(), "content"));
48+const fileContents = `export const glossary = ${JSON.stringify(glossary)}`;
49+
50+try {
51+ fs.readdirSync("cache");
52+} catch (err) {
53+ fs.mkdirSync("cache");
54+}
55+
56+fs.writeFile("cache/glossary.js", fileContents, function (err) {
57+ if (err) return console.error(err);
58+ console.log("Site glossary created.");
59+});