Skip to content

Commit

Permalink
Sort sidebar, add all top level exports for each package
Browse files Browse the repository at this point in the history
  • Loading branch information
crucialfelix committed Jan 9, 2020
1 parent 1d0a320 commit 5095df6
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions tasks/make-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ const docsRoot = "http://localhost:3000/#";

const packageNames = async () => {
const names = (await fsp.readdir(path.join(root, "packages"))).filter(name => name.match(/^[a-z\-]+$/));
// sort favored first
return names;
// preferred order
const nn = ["supercolliderjs", "server", "server-plus", "lang", "dryads", "osc"];
// add any not already in that list
names.forEach(n => {
if (!nn.includes(n)) {
nn.push(n);
}
});

return nn;
};

async function fileExists(...paths) {
Expand Down Expand Up @@ -88,6 +96,10 @@ async function renderTpl(tpl, destPath, data) {
const mdLink = (title, links) => `[${title}](${links.join("/")})`;
const isString = thing => typeof thing === "string";

/**
* Generate _sidebar.md
* and return
*/
async function generateSidebar(packages) {
const sb = [];
sb.push("- " + mdLink("Getting started", ["README.md"]));
Expand All @@ -102,9 +114,10 @@ async function generateSidebar(packages) {
sb.push(` - ` + mdLink("API", ["packages", short, "api.md"]));
// push one for each top level export
for (const [key, value] of Object.entries(index)) {
autos[short].push(
isString(value) ? { title: value, filename: value + ".md" } : { title: key, filename: key + ".md" },
);
const page = isString(value) ? { title: value, filename: value + ".md" } : { title: key, filename: key + ".md" };
autos[short].push(page);
// top level export
sb.push(` - ` + mdLink(page.title, ["packages", short, page.filename]));
}
});
sb.push("- Guide");
Expand Down Expand Up @@ -151,7 +164,6 @@ ${content}

async function main(version) {
const packages = await packageNames();

const pkg = readJson("package.json");

const rootData = {
Expand All @@ -168,7 +180,6 @@ async function main(version) {
api: () => renderApi,
};

// _coverpage
await renderTplPath("docs/src/_coverpage.md", "docs/_coverpage.md", rootData);

const autos = await generateSidebar(packages);
Expand Down

0 comments on commit 5095df6

Please sign in to comment.