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 // Assume years belong to Grants for now.
19 const dirName = dir.split("/").slice(-1).join("");
20 const parentName = String(Number(dirName)).length === 4
22 : dirName.charAt(0).toUpperCase() + dirName.slice(1);
30 metadata = matter(fs.readFileSync(path.join(dir, "_index.md")), options);
33 const children = fs.readdirSync(dir, { withFileTypes: true });
34 const pages = children.filter((f) => f.isFile() && f.name !== "_index.md");
35 const subdirs = children.filter(
36 (f) => f.isDirectory() && f.name !== "ids" && f.name !== "glossary"
40 ...pages.map((page) => {
41 const { data: pageData, content: pageContent } = matter(
42 fs.readFileSync(path.join(dir, page.name)),
45 const parsed = markdoc.parse(pageContent);
46 const transform = markdoc.transform(parsed);
47 const slug = dir.includes("/grants/")
48 ? `/grants/${page.name.replace(/.md$/, "")}`
50 dir.substr(dir.indexOf("content") + 7),
52 page.name.replace(/.md$/, "")
55 title: pageData.title,
58 content: pageData.description || "",
59 headings: transform.children
60 .filter((e) => e.name === "h2" || e.name === "h3")
61 .map((e) => e.children)
63 .filter((e) => typeof e === "string"),
64 parent: metadata.data.title,
70 subdirs.map((subdir) => [
72 buildSearchIndex(path.join(dir, subdir.name)),
77buildSearchIndex(path.join(process.cwd(), "content"));
79const fileContents = `export const index = ${JSON.stringify(index)}`;
82 fs.readdirSync("cache");
84 fs.mkdirSync("cache");
87fs.writeFile("cache/data.js", fileContents, function (err) {
88 if (err) return console.error(err);
89 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