1const fs = require("fs");
2const path = require("path");
3const matter = require("gray-matter");
4const toml = require("@iarna/toml");
8 toml: toml.parse.bind(toml),
16function buildSearchIndex(dir) {
17 const dirName = dir.split("/").slice(-1).join("");
20 title: dirName.charAt(0).toUpperCase() + dirName.slice(1),
25 metadata = matter(fs.readFileSync(path.join(dir, "_index.md")), options);
28 const children = fs.readdirSync(dir, { withFileTypes: true });
29 const pages = children.filter((f) => f.isFile() && f.name !== "_index.md");
30 const subdirs = children.filter(
31 (f) => f.isDirectory() && f.name !== "ids" && f.name !== "glossary"
35 ...pages.map((page) => {
36 const { data: pageData, content: pageContent } = matter(
37 fs.readFileSync(path.join(dir, page.name)),
41 title: pageData.title,
44 dir.substr(dir.indexOf("content") + 7),
46 page.name.replace(/.md$/, "")
48 content: pageData.description || "",
49 parent: metadata.data.title,
55 subdirs.map((subdir) => [
57 buildSearchIndex(path.join(dir, subdir.name)),
62buildSearchIndex(path.join(process.cwd(), "content"));
64const fileContents = `export const index = ${JSON.stringify(index)}`;
67 fs.readdirSync("cache");
69 fs.mkdirSync("cache");
72fs.writeFile("cache/data.js", fileContents, function (err) {
73 if (err) return console.error(err);
74 console.log("Site index created.");
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list