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);
43 const slug = dir.includes("/grants/")
44 ? `/grants/${page.name.replace(/.md$/, "")}`
46 dir.substr(dir.indexOf("content") + 7),
48 page.name.replace(/.md$/, "")
51 title: pageData.title,
54 content: pageData.description || "",
55 headings: transform.children
56 .filter((e) => e.name === "h2" || e.name === "h3")
57 .map((e) => e.children)
59 .filter((e) => typeof e === "string"),
60 parent: metadata.data.title,
66 subdirs.map((subdir) => [
68 buildSearchIndex(path.join(dir, subdir.name)),
73buildSearchIndex(path.join(process.cwd(), "content"));
75const fileContents = `export const index = ${JSON.stringify(index)}`;
78 fs.readdirSync("cache");
80 fs.mkdirSync("cache");
83fs.writeFile("cache/data.js", fileContents, function (err) {
84 if (err) return console.error(err);
85 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