1const fs = require("fs");
2const path = require("path");
3const matter = require("gray-matter");
4const toml = require("@iarna/toml");
5const markdoc = require("@urbit/markdoc");
9 toml: toml.parse.bind(toml),
17function buildSearchIndex(dir) {
18 const dirName = dir.split("/").slice(-1).join("");
21 title: dirName.charAt(0).toUpperCase() + dirName.slice(1),
26 metadata = matter(fs.readFileSync(path.join(dir, "_index.md")), options);
29 const children = fs.readdirSync(dir, { withFileTypes: true });
30 const pages = children.filter((f) => f.isFile() && f.name !== "_index.md");
31 const subdirs = children.filter(
32 (f) => f.isDirectory() && f.name !== "ids" && f.name !== "glossary"
36 ...pages.map((page) => {
37 const { data: pageData, content: pageContent } = matter(
38 fs.readFileSync(path.join(dir, page.name)),
41 const parsed = markdoc.parse(pageContent);
42 const transform = markdoc.transform(parsed);
44 title: pageData.title,
47 dir.substr(dir.indexOf("content") + 7),
49 page.name.replace(/.md$/, "")
51 content: pageData.description || "",
52 headings: transform.children
53 .filter((e) => e.name === "h2" || e.name === "h3")
54 .map((e) => e.children)
56 .filter((e) => typeof e === "string"),
57 parent: metadata.data.title,
63 subdirs.map((subdir) => [
65 buildSearchIndex(path.join(dir, subdir.name)),
70buildSearchIndex(path.join(process.cwd(), "content"));
72const fileContents = `export const index = ${JSON.stringify(index)}`;
75 fs.readdirSync("cache");
77 fs.mkdirSync("cache");
80fs.writeFile("cache/data.js", fileContents, function (err) {
81 if (err) return console.error(err);
82 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