Created
March 10, 2020 13:08
-
-
Save peterbe/52918ccf94c9ae1d597a4fddbbf7a261 to your computer and use it in GitHub Desktop.
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 fs = require("fs"); | |
const path = require("path"); | |
const yaml = require("js-yaml"); | |
const enUS = new Set(); | |
function walkAndLog(root) { | |
fs.readdirSync(root).forEach(file => { | |
let filepath = path.join(root, file); | |
if (fs.statSync(filepath).isDirectory()) { | |
walkAndLog(filepath); | |
} else if (filepath.endsWith("index.yaml")) { | |
const metadata = yaml.safeLoad(fs.readFileSync(filepath)); | |
enUS.add(metadata.slug); | |
// enUS[metadata.slug] | |
// if (locale !== metadata.locale.toLowerCase()) { | |
// throw new Error(filepath); | |
// } | |
} | |
}); | |
} | |
let noParent = 0; | |
function walk(root, locale) { | |
fs.readdirSync(root).forEach(file => { | |
let filepath = path.join(root, file); | |
if (fs.statSync(filepath).isDirectory()) { | |
walk(filepath, locale); | |
} else if (filepath.endsWith("index.yaml")) { | |
const metadata = yaml.safeLoad(fs.readFileSync(filepath)); | |
if (locale !== metadata.locale.toLowerCase()) { | |
throw new Error(filepath); | |
} | |
if (metadata.locale.toLowerCase() !== "en-us") { | |
if (!metadata.parent) { | |
// throw new Error(filepath); | |
console.warn(filepath, "doesn't have a parent"); | |
noParent++; | |
} | |
} | |
} | |
}); | |
} | |
let ROOT = "content/files"; | |
walkAndLog(path.join(ROOT, "en-us")); | |
const locales = fs.readdirSync(ROOT); | |
console.log(locales); | |
for (let locale of locales) { | |
walk(path.join(ROOT, locale), locale); | |
} | |
console.log(`non-en-US Documents without a parent: ${noParent}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment