diff --git a/build/document-extractor.js b/build/document-extractor.js index 761024b6f2d7..cadf0d11a290 100644 --- a/build/document-extractor.js +++ b/build/document-extractor.js @@ -287,28 +287,44 @@ function _addSingleSpecialSection($) { } const query = dataQuery.replace(/^bcd:/, ""); const { browsers, data } = packageBCD(query); - if (data === undefined) { - return [ - { - type: specialSectionType, - value: { - title, - id, - isH3, - data: null, - query, - browsers: null, - }, - }, - ]; - } if (specialSectionType === "browser_compatibility") { + if (data === undefined) { + return [ + { + type: specialSectionType, + value: { + title, + id, + isH3, + data: null, + query, + browsers: null, + }, + }, + ]; + } return _buildSpecialBCDSection(); } else if (specialSectionType === "specifications") { + if (data === undefined) { + return [ + { + type: specialSectionType, + value: { + title, + id, + isH3, + query, + specifications: [], + }, + }, + ]; + } return _buildSpecialSpecSection(); } + throw new Error(`Unrecognized special section type '${specialSectionType}'`); + function _buildSpecialBCDSection() { // First extract a map of all release data, keyed by (normalized) browser // name and the versions. @@ -400,17 +416,26 @@ function _addSingleSpecialSection($) { // Use BCD specURLs to look up more specification data // from the browser-specs package - let specifications = []; + const specifications = specURLs + .map((specURL) => { + const spec = specs.find( + (spec) => + specURL.startsWith(spec.url) || specURL.startsWith(spec.nightly.url) + ); + if (spec) { + // We only want to return exactly the keys that we will use in the + // client code that renders this in React. + return { + bcdSpecificationURL: specURL, + title: spec.title, + shortTitle: spec.shortTitle, + }; + } + }) + .filter(Boolean); - specURLs.forEach((url) => { - let spec = specs.find( - (spec) => url.startsWith(spec.url) || url.startsWith(spec.nightly.url) - ); - if (spec) { - spec.bcdSpecificationURL = url; - specifications.push(spec); - } - }); + console.log("HERE!!"); + console.log(specifications); return [ { diff --git a/client/src/document/spec-table.tsx b/client/src/document/spec-table.tsx index 201c423c71b0..cc2e8450d7f5 100644 --- a/client/src/document/spec-table.tsx +++ b/client/src/document/spec-table.tsx @@ -17,45 +17,46 @@ export function SpecificationTable({ }>; query: string; }) { - if (specifications) { - const rows = specifications.map((spec) => ( - - - {spec.title} - - - )); + return ( + <> + {title && !isH3 && } + {title && isH3 && } - return ( - <> - {title && !isH3 && } - {title && isH3 && } + {/* XXX We could have a third condition; the specURL worked but yielded + exactly 0 specifications. If that's the case, perhaps the messaging + should be different. */} + {specifications.length > 0 ? ( - {rows} + + {specifications.map((spec) => ( + + + + ))} +
Specification
+ {spec.title} +
- - ); - } else { - return ( - <> - {title && !isH3 && } - {title && isH3 && } -

- No specification data found for {query}.
- Check for problems with this page or - contribute a missing spec_url to{" "} - - mdn/browser-compat-data - - . Also make sure the specification is included in{" "} - w3c/browser-specs. -

- - ); - } + ) : ( +
+

+ No specification data found for {query}.
+ Check for problems with this page or + contribute a missing spec_url to{" "} + + mdn/browser-compat-data + + . Also make sure the specification is included in{" "} + w3c/browser-specs + . +

+
+ )} + + ); }