Skip to content

Instantly share code, notes, and snippets.

@peterbe
Created March 10, 2020 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterbe/52918ccf94c9ae1d597a4fddbbf7a261 to your computer and use it in GitHub Desktop.
Save peterbe/52918ccf94c9ae1d597a4fddbbf7a261 to your computer and use it in GitHub Desktop.
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