Skip to content

Commit

Permalink
Merge pull request #294 from peterbe/feedback-on-pr-3518
Browse files Browse the repository at this point in the history
feedback on pr 3518
  • Loading branch information
Elchi3 authored Apr 22, 2021
2 parents b1d4b83 + 6eba53d commit 0d4e4ac
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 58 deletions.
75 changes: 50 additions & 25 deletions build/document-extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 [
{
Expand Down
67 changes: 34 additions & 33 deletions client/src/document/spec-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,46 @@ export function SpecificationTable({
}>;
query: string;
}) {
if (specifications) {
const rows = specifications.map((spec) => (
<tr key={spec.bcdSpecificationURL}>
<td>
<a href={spec.bcdSpecificationURL}>{spec.title}</a>
</td>
</tr>
));
return (
<>
{title && !isH3 && <DisplayH2 id={id} title={title} />}
{title && isH3 && <DisplayH3 id={id} title={title} />}

return (
<>
{title && !isH3 && <DisplayH2 id={id} title={title} />}
{title && isH3 && <DisplayH3 id={id} title={title} />}
{/* 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 ? (
<table className="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
</tr>
</thead>
{rows}
<tbody>
{specifications.map((spec) => (
<tr key={spec.bcdSpecificationURL}>
<td>
<a href={spec.bcdSpecificationURL}>{spec.title}</a>
</td>
</tr>
))}
</tbody>
</table>
</>
);
} else {
return (
<>
{title && !isH3 && <DisplayH2 id={id} title={title} />}
{title && isH3 && <DisplayH3 id={id} title={title} />}
<p>
No specification data found for <code>{query}</code>.<br />
<a href="#on-github">Check for problems with this page</a> or
contribute a missing <code>spec_url</code> to{" "}
<a href="https://github.com/mdn/browser-compat-data">
mdn/browser-compat-data
</a>
. Also make sure the specification is included in{" "}
<a href="https://github.com/w3c/browser-specs">w3c/browser-specs</a>.
</p>
</>
);
}
) : (
<div className="notecard warning">
<p>
No specification data found for <code>{query}</code>.<br />
<a href="#on-github">Check for problems with this page</a> or
contribute a missing <code>spec_url</code> to{" "}
<a href="https://github.com/mdn/browser-compat-data">
mdn/browser-compat-data
</a>
. Also make sure the specification is included in{" "}
<a href="https://github.com/w3c/browser-specs">w3c/browser-specs</a>
.
</p>
</div>
)}
</>
);
}

0 comments on commit 0d4e4ac

Please sign in to comment.