Created
February 23, 2019 04:06
-
-
Save lannonbr/14d8c71929a7f7d1b6b21c69c9494fed to your computer and use it in GitHub Desktop.
A small node script to figure out the number of stubs in gatsby's docs compared to the total number of docs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const yamlParser = require("js-yaml"); | |
const fs = require("fs"); | |
const path = require("path"); | |
const doc = yamlParser.safeLoad( | |
fs.readFileSync(path.join(__dirname, "doc-links.yaml")) | |
); | |
const doc2 = yamlParser.safeLoad( | |
fs.readFileSync(path.join(__dirname, "contributing-links.yaml")) | |
); | |
console.log(traverse([...doc, ...doc2])); | |
function traverse(arr) { | |
let stubCount = 0; | |
let pageCount = 0; | |
arr.forEach(obj => { | |
if (obj.title !== undefined && obj.link !== undefined) { | |
// Found a page | |
pageCount++; | |
if (obj.title.endsWith("*")) { | |
// found a stub | |
console.log({ title: obj.title, link: obj.link }); | |
stubCount++; | |
} | |
} | |
if (obj.title !== undefined && obj.items !== undefined) { | |
// Recurse down | |
const [stubCount_, pageCount_] = traverse(obj.items); | |
stubCount += stubCount_; | |
pageCount += pageCount_; | |
} | |
}); | |
return [stubCount, pageCount]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment