Skip to content

Commit

Permalink
Fetch title from nightly in preference to main URL
Browse files Browse the repository at this point in the history
(no less buggy than for existing sources per #360)
  • Loading branch information
dontcallmedom committed Dec 10, 2021
1 parent bed45aa commit a8aab11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 0 additions & 1 deletion specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"url": "https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis",
"shortname": "rfc6265bis",
"organization": "IETF",
"title": "Cookies: HTTP State Management Mechanism",
"groups": [
{
"name": "HTTP Working Group",
Expand Down
11 changes: 6 additions & 5 deletions src/fetch-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ async function fetchInfoFromSpecref(specs, options) {

async function fetchInfoFromSpecs(specs, options) {
const info = await Promise.all(specs.map(async spec => {
const dom = await JSDOM.fromURL(spec.url);
const url = spec.nightly?.url || spec.url;
const dom = await JSDOM.fromURL(url);

if (spec.url.startsWith("https://tc39.es/")) {
// Title is either flagged with specific class or the second h1
Expand All @@ -264,7 +265,7 @@ async function fetchInfoFromSpecs(specs, options) {
dom.window.document.querySelectorAll("h1")[1];
if (h1ecma) {
return {
nightly: { url: spec.url },
nightly: { url: url },
title: h1ecma.textContent.replace(/\n/g, '').trim()
};
}
Expand All @@ -273,7 +274,7 @@ async function fetchInfoFromSpecs(specs, options) {
const h1 = dom.window.document.querySelector("h1");
if (h1) {
return {
nightly: { url: spec.url },
nightly: { url: url },
title: h1.textContent.replace(/\n/g, '').trim()
};
}
Expand All @@ -283,12 +284,12 @@ async function fetchInfoFromSpecs(specs, options) {
const title = dom.window.document.querySelector("title");
if (title) {
return {
nightly: { url: spec.url },
nightly: { url: url },
title: title.textContent.replace(/\n/g, '').trim()
};
}

throw `Could not find title in ${spec.url} for spec "${spec.shortname}"`;
throw `Could not find title in ${url} for spec "${spec.shortname}"`;
}));

const results = {};
Expand Down

0 comments on commit a8aab11

Please sign in to comment.