Skip to content

Commit

Permalink
fix(baseline): not appearing on translated docs (#9662)
Browse files Browse the repository at this point in the history
also fixes translated docs not having a `browserCompat` key in their
index/metadata.json
  • Loading branch information
LeoMcA authored Oct 18, 2023
1 parent 48ad86d commit 788c883
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,13 @@ export async function buildDocument(
let flaws: any[] = [];
let $: cheerio.CheerioAPI = null;
const liveSamples: LiveSample[] = [];
// this will get populated with the parent's frontmatter by kumascript if the document is localized:
let allMetadata = metadata;

try {
[$, flaws] = await kumascript.render(document.url);
let kumascriptMetadata;
[$, flaws, kumascriptMetadata] = await kumascript.render(document.url);
allMetadata = { ...allMetadata, ...kumascriptMetadata };
} catch (error) {
if (
error instanceof MacroInvocationError &&
Expand Down Expand Up @@ -369,7 +373,9 @@ export async function buildDocument(
doc.mdn_url = document.url;
doc.locale = metadata.locale as string;
doc.native = LANGUAGES.get(doc.locale.toLowerCase())?.native;
const browserCompat = metadata["browser-compat"];

// metadata doesn't have a browser-compat key on translated docs:
const browserCompat = allMetadata["browser-compat"];
doc.browserCompat =
browserCompat &&
(Array.isArray(browserCompat) ? browserCompat : [browserCompat]);
Expand Down
6 changes: 3 additions & 3 deletions kumascript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export async function render(
invalidateCache = false,
}: RenderOptions = {},
doc?: Doc
): Promise<[cheerio.CheerioAPI, SourceCodeError[]]> {
): Promise<[cheerio.CheerioAPI, SourceCodeError[], any]> {
const urlLC = url.toLowerCase();
if (renderCache.has(urlLC)) {
if (invalidateCache) {
renderCache.delete(urlLC);
} else {
const [renderedHtml, errors] = renderCache.get(urlLC);
return [cheerio.load(renderedHtml), errors];
return [cheerio.load(renderedHtml), errors, undefined];
}
}

Expand Down Expand Up @@ -135,5 +135,5 @@ export async function render(
allErrors,
]);
}
return [tool.cheerio(), allErrors];
return [tool.cheerio(), allErrors, metadata];
}

0 comments on commit 788c883

Please sign in to comment.