From 6d80ead2cf396234acaf630c2c3122d3d566715a Mon Sep 17 00:00:00 2001 From: Gabriel Sroka Date: Thu, 23 Feb 2023 10:47:43 -0800 Subject: [PATCH 1/3] Update head.html this regex allows you to get next or prev, etc --- .../2-async-iterators-generators/head.html | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/1-js/12-generators-iterators/2-async-iterators-generators/head.html b/1-js/12-generators-iterators/2-async-iterators-generators/head.html index 03f21e2bd8..a87cc4becb 100644 --- a/1-js/12-generators-iterators/2-async-iterators-generators/head.html +++ b/1-js/12-generators-iterators/2-async-iterators-generators/head.html @@ -7,16 +7,13 @@ headers: {'User-Agent': 'Our script'}, // github requires user-agent header }); - const body = await response.json(); // parses response as JSON (array of commits) + const commits = await response.json(); // parses response as JSON (array of commits) // the URL of the next page is in the headers, extract it - let nextPage = response.headers.get('Link').match(/<(.*?)>; rel="next"/); - nextPage = nextPage?.[1]; - - url = nextPage; + url = response.headers.get('Link').match(/<([^>]+)>; rel="next"/)?.[1]; // yield commits one by one, when they finish - fetch a new page url - for(let commit of body) { + for (const commit of commits) { yield commit; } } From 4904ac29be205193374b05fc2d23f505889dd37e Mon Sep 17 00:00:00 2001 From: Gabriel Sroka Date: Thu, 23 Feb 2023 10:49:56 -0800 Subject: [PATCH 2/3] Update article.md --- .../2-async-iterators-generators/article.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/1-js/12-generators-iterators/2-async-iterators-generators/article.md b/1-js/12-generators-iterators/2-async-iterators-generators/article.md index d4e9f78616..5412757814 100644 --- a/1-js/12-generators-iterators/2-async-iterators-generators/article.md +++ b/1-js/12-generators-iterators/2-async-iterators-generators/article.md @@ -341,15 +341,12 @@ async function* fetchCommits(repo) { headers: {'User-Agent': 'Our script'}, // github needs any user-agent header }); - const body = await response.json(); // (2) response is JSON (array of commits) + const commits = await response.json(); // (2) response is JSON (array of commits) // (3) the URL of the next page is in the headers, extract it - let nextPage = response.headers.get('Link').match(/<(.*?)>; rel="next"/); - nextPage = nextPage?.[1]; + url = response.headers.get('Link').match(/<([^>]+)>; rel="next"/)?.[1]; - url = nextPage; - - for(let commit of body) { // (4) yield commits one by one, until the page ends + for (const commit of commits) { // (4) yield commits one by one, until the page ends yield commit; } } From 6b93f8ebeb3588485fa86ca7ef858b80214eb797 Mon Sep 17 00:00:00 2001 From: Gabriel Sroka Date: Thu, 23 Feb 2023 10:53:11 -0800 Subject: [PATCH 3/3] `link` should be lowercase --- .../2-async-iterators-generators/article.md | 2 +- .../2-async-iterators-generators/head.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/12-generators-iterators/2-async-iterators-generators/article.md b/1-js/12-generators-iterators/2-async-iterators-generators/article.md index 5412757814..8704d2986f 100644 --- a/1-js/12-generators-iterators/2-async-iterators-generators/article.md +++ b/1-js/12-generators-iterators/2-async-iterators-generators/article.md @@ -344,7 +344,7 @@ async function* fetchCommits(repo) { const commits = await response.json(); // (2) response is JSON (array of commits) // (3) the URL of the next page is in the headers, extract it - url = response.headers.get('Link').match(/<([^>]+)>; rel="next"/)?.[1]; + url = response.headers.get('link').match(/<([^>]+)>; rel="next"/)?.[1]; for (const commit of commits) { // (4) yield commits one by one, until the page ends yield commit; diff --git a/1-js/12-generators-iterators/2-async-iterators-generators/head.html b/1-js/12-generators-iterators/2-async-iterators-generators/head.html index a87cc4becb..2993ffb019 100644 --- a/1-js/12-generators-iterators/2-async-iterators-generators/head.html +++ b/1-js/12-generators-iterators/2-async-iterators-generators/head.html @@ -10,7 +10,7 @@ const commits = await response.json(); // parses response as JSON (array of commits) // the URL of the next page is in the headers, extract it - url = response.headers.get('Link').match(/<([^>]+)>; rel="next"/)?.[1]; + url = response.headers.get('link').match(/<([^>]+)>; rel="next"/)?.[1]; // yield commits one by one, when they finish - fetch a new page url for (const commit of commits) {