Skip to content

Commit f5ed81d

Browse files
authored
chore(menu): update missing docs in parallel (#1046)
1 parent 9bf1c21 commit f5ed81d

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

components/menu/update-missing-docs.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,37 @@ console.log(`Checking ${slugs.length} slugs in ${locales.length} locales…`);
3737
const result = {};
3838
for (const locale of locales) {
3939
console.log(`\n=== ${locale} ===`);
40-
result[locale] = [];
40+
const missingSlugs = await Promise.all(
41+
slugs.map(
42+
/**
43+
* @param {string} slug
44+
* @returns {Promise<string[]>}
45+
*/
46+
async (slug) => {
47+
const url = `https://developer.mozilla.org/${locale}/docs/${slug}`;
4148

42-
for (const slug of slugs) {
43-
const url = `https://developer.mozilla.org/${locale}/docs/${slug}`;
44-
process.stdout.write(`.`);
49+
try {
50+
const res = await fetch(url, { method: "HEAD" });
51+
process.stdout.write(`.`);
4552

46-
try {
47-
const res = await fetch(url, { method: "HEAD" });
53+
if (res.status === 200) {
54+
// All good.
55+
return [];
56+
} else if (res.status === 404) {
57+
// Not found.
58+
} else {
59+
console.log(`\n⚠️ HTTP ${res.status} [${url}]`);
60+
}
61+
} catch (error) {
62+
console.log(`\n🔥 ERROR: ${error} [${url}]`);
63+
}
4864

49-
if (res.status === 200) {
50-
// All good.
51-
continue;
52-
} else if (res.status === 404) {
53-
// Not found.
54-
} else {
55-
console.log(`\n⚠️ HTTP ${res.status} [${url}]`);
56-
}
57-
} catch (error) {
58-
console.log(`\n🔥 ERROR: ${error} [${url}]`);
59-
}
65+
return [slug];
66+
},
67+
),
68+
);
6069

61-
result[locale].push(slug);
62-
}
70+
result[locale] = missingSlugs.flat();
6371
}
6472

6573
const file = path.join(import.meta.dirname, "missing-docs.json");

0 commit comments

Comments
 (0)