Skip to content

Instantly share code, notes, and snippets.

@Kmaschta
Created April 29, 2019 11:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kmaschta/b6e17a2b7f5620feb03c00674027467a to your computer and use it in GitHub Desktop.
Save Kmaschta/b6e17a2b7f5620feb03c00674027467a to your computer and use it in GitHub Desktop.
Parse International Days
// https://www.journee-mondiale.com/les-journees-mondiales.htm
(() => {
const links = {};
const articles = document.querySelectorAll('article');
articles.forEach((article, monthIndex) => {
const items = article.querySelectorAll('li');
items.forEach((li) => {
const t = li.querySelector('time').dateTime;
const date = t.split(' ')[0].replace('er', '')
const day = date.padStart(2, '0');
const month = (monthIndex + 1).toString().padStart(2, '0');
const text = li.querySelector('a').textContent.split(':')[1].trim()
const href = li.querySelector('a').getAttribute('href');
if (!links[`${month}-${day}`]) {
links[`${month}-${day}`] = []
}
links[`${month}-${day}`].push({ text, href })
})
});
console.log(JSON.stringify(links, undefined, 4))
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment