Skip to content

Instantly share code, notes, and snippets.

@joehonton
Last active March 21, 2021 19:13
Show Gist options
  • Save joehonton/88231590e645d8dfdf49d9cc8eece227 to your computer and use it in GitHub Desktop.
Save joehonton/88231590e645d8dfdf49d9cc8eece227 to your computer and use it in GitHub Desktop.
const articleUrls = [
'/feb-28-2021.html',
'/feb-21-2021.html',
'/feb-14-2021.html',
'/feb-07-2021.html'
];
const nextIndex = 0;
async fetchNextArticle() {
// fetch the article using HTTP
const response = await fetch(articleUrls[nextIndex++]);
if (response.status != 200 && response.status != 304)
return;
const templateText = await response.text();
// get the <body> of the article's HTML
const template = document.createElement('template');
template.innerHTML = templateText;
const body = template.content.querySelector('body');
// create a new <article> and insert it
const nextArticle = document.createElement('article')
nextArticle.innerHTML = body.innerHTML;
bottomOfPage.parentNode.insertBefore(nextArticle, bottomOfPage);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment