Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): sort meta files #9899

Merged
merged 5 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions build/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async function buildDocuments(
cliProgress.Presets.shades_grey
);

const docPerLocale = {};
const docPerLocale: Record<string, { slug: string; modified: string }[]> = {};
const searchIndex = new SearchIndex();

if (!documents.count) {
Expand Down Expand Up @@ -307,12 +307,17 @@ async function buildDocuments(
}

for (const [locale, meta] of Object.entries(metadata)) {
const sortedMeta = meta
.slice()
.sort((a, b) => a.mdn_url.localeCompare(b.mdn_url));
fs.writeFileSync(
path.join(BUILD_OUT_ROOT, locale.toLowerCase(), "metadata.json"),
JSON.stringify(meta)
JSON.stringify(sortedMeta)
);
}

// allBrowserCompat.txt is used by differy, see:
// https://github.com/search?q=repo%3Amdn%2Fdiffery+allBrowserCompat&type=code
const allBrowserCompat = new Set<string>();
Object.values(metadata).forEach((localeMeta) =>
localeMeta.forEach(
Expand All @@ -322,7 +327,7 @@ async function buildDocuments(
);
fs.writeFileSync(
path.join(BUILD_OUT_ROOT, "allBrowserCompat.txt"),
[...allBrowserCompat].join(" ")
[...allBrowserCompat].sort().join(" ")
);

return { slugPerLocale: docPerLocale, peakHeapBytes, totalFlaws };
Expand Down
17 changes: 12 additions & 5 deletions build/sitemaps.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
export function makeSitemapXML(locale, docs) {
export function makeSitemapXML(
locale: string,
docs: { slug: string; modified: string }[]
) {
const sortedDocs = docs.slice().sort((a, b) => a.slug.localeCompare(b.slug));

// Based on https://support.google.com/webmasters/answer/183668?hl=en
return [
'<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
...docs.map((doc) => {
...sortedDocs.map((doc) => {
const loc = `<loc>https://developer.mozilla.org/${locale}/docs/${doc.slug}</loc>`;
const modified = doc.modified
? `<lastmod>${doc.modified.toString().split("T")[0]}</lastmod>`
Expand All @@ -15,15 +20,17 @@ export function makeSitemapXML(locale, docs) {
].join("\n");
}

export function makeSitemapIndexXML(pathnames) {
export function makeSitemapIndexXML(paths: string[]) {
const sortedPaths = paths.slice().sort();

// Based on https://support.google.com/webmasters/answer/75712
return [
'<?xml version="1.0" encoding="UTF-8"?>',
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
...pathnames.map((pathname) => {
...sortedPaths.map((path) => {
return (
"<sitemap>" +
`<loc>https://developer.mozilla.org${pathname}</loc>` +
`<loc>https://developer.mozilla.org${path}</loc>` +
`<lastmod>${new Date().toISOString().split("T")[0]}</lastmod>` +
"</sitemap>"
);
Expand Down