Skip to content

Commit

Permalink
updated sidebar lint script
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten committed Jul 18, 2024
1 parent 9d8a84f commit 960007b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .sidebarignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
policies/validate-json-schema-inbound
policies/api-key-auth-inbound
sample-apis
conferences/conference-prize-terms
23 changes: 19 additions & 4 deletions scripts/find-unlinked-docs.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import fs from "fs";
import { glob } from "glob";

const ignoredDocs = await fs.promises
.readFile(".sidebarignore", "utf8")
.then((content) => content.split("\n"));

const sidebar = await fs.promises
.readFile("./sidebar.json", "utf8")
.then(JSON.parse);
Expand All @@ -20,6 +24,8 @@ function listDocs(items) {
allDocs.push(item);
} else if ("items" in item && typeof item.items === "object") {
listDocs(item.items);
} else if ("type" in item && item.type === "doc") {
allDocs.push(item.id);
}
if (typeof item === "object" && "link" in item) {
if (typeof item.link === "string") {
Expand All @@ -37,11 +43,20 @@ function listDocs(items) {

listDocs(sidebar);

const uniqueDocs = [...new Set(docs), ...new Set(policies)];
const uniqueDocs = [...new Set(docs), ...new Set(policies)].filter(
(doc) => !ignoredDocs.includes(doc),
);

const unlinkedDocs = uniqueDocs.filter((doc) => !allDocs.includes(doc));

console.log(unlinkedDocs);
console.log(
`Total Docs: ${uniqueDocs.length}, Unlinked Docs: ${unlinkedDocs.length}`,
console.group();
console.log("The following docs are not linked to in the sidebar:");
console.group();
for (const doc of unlinkedDocs) {
console.log(doc);
}
console.groupEnd();

console.warn(
`There are ${unlinkedDocs.length} that are not linked to in the sidebar.`,
);

0 comments on commit 960007b

Please sign in to comment.