-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve WHATWG spec titles from WHATWG database (#1666)
Build code used to rely on Specref to get the title of WHATWG specifications. This update makes it fetch info for WHATWG specs from the WHATWG database directly. To save one request, the code leverages the workstreams database, also used by fetch-groups, instead of the biblio file. On top of adding a new `whatwg` value to the `"source"` field, this update will also fix the titles of the WHATWG specs: they end with "Standard" in Specref but, while that matches the `<title>` tag, the actual spec title in the `<h1>` and the title in the WHATWG database don't end with "Standard". #docallmeDOM The update turns the `fetchJSON` function into a utility function. This is going to save a few requests (not that many!) that are common between fetch-info and fetch-groups. Specific functions in fetch-info were also adjusted not to do anything when there are no specs of interest in the list (this speeds up tests a bit, but has no impact on a full build since, by definition, there are specs of interest in the full list...)
- Loading branch information
Showing
5 changed files
with
136 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import ThrottledQueue from "./throttled-queue.js"; | ||
|
||
// Make sure we remain "friendly" with servers | ||
const fetchQueue = new ThrottledQueue({ maxParallel: 2 }); | ||
|
||
// Maintain a cache of fetched JSON resources in memory to avoid sending the | ||
// same fetch request again and again | ||
const cache = {}; | ||
|
||
/** | ||
* Fetch a JSON URL | ||
*/ | ||
export default async function (url, options) { | ||
if (cache[url]) { | ||
return structuredClone(cache[url]); | ||
} | ||
const res = await fetchQueue.runThrottled(fetch, url, options); | ||
if (res.status === 404) { | ||
return null; | ||
} | ||
if (res.status !== 200) { | ||
throw new Error(`Server returned an error for ${url}, status code is ${res.status}`); | ||
} | ||
|
||
try { | ||
const body = await res.json(); | ||
cache[url] = body; | ||
return structuredClone(body); | ||
} | ||
catch (err) { | ||
throw new Error(`Server returned invalid JSON for ${url}`); | ||
} | ||
} |
Oops, something went wrong.