diff --git a/build/index.ts b/build/index.ts index cd165e4a7228..b251679c3308 100644 --- a/build/index.ts +++ b/build/index.ts @@ -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 && @@ -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]); diff --git a/kumascript/index.ts b/kumascript/index.ts index 9e6cbb7c6a63..51f1a0b09716 100644 --- a/kumascript/index.ts +++ b/kumascript/index.ts @@ -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]; } } @@ -135,5 +135,5 @@ export async function render( allErrors, ]); } - return [tool.cheerio(), allErrors]; + return [tool.cheerio(), allErrors, metadata]; }