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((f) => f.isDirectory());
33 ...pages.map((page) => {
34 const { data: pageData, content: pageContent } = matter(
35 fs.readFileSync(path.join(dir, page.name)),
39 title: pageData.title,
42 dir.substr(dir.indexOf("content") + 7),
44 page.name.replace(/.md$/, "")
46 content: pageData.description || "",
47 parent: metadata.data.title,
53 subdirs.map((subdir) => [
55 buildSearchIndex(path.join(dir, subdir.name)),
60buildSearchIndex(path.join(process.cwd(), "content"));
62const fileContents = `export const index = ${JSON.stringify(index)}`;
65 fs.readdirSync("cache");
67 fs.mkdirSync("cache");
70fs.writeFile("cache/data.js", fileContents, function (err) {
71 if (err) return console.error(err);
72 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