Skip to content

Instantly share code, notes, and snippets.

@peterbe
Last active August 31, 2023 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterbe/2fb2e68762716497dbc9579cb3390699 to your computer and use it in GitHub Desktop.
Save peterbe/2fb2e68762716497dbc9579cb3390699 to your computer and use it in GitHub Desktop.
import got from 'got'
import cheerio from 'cheerio'
async function getTags(url) {
const response = await got(url)
return countTags(response.body)
}
function countTags(body) {
const tags = {}
const $ = cheerio.load(body)
$('#article-contents *').each((i, el) => {
tags[el.tagName] = (tags[el.tagName] || 0) + 1
})
return tags
}
async function main(args) {
const tags = await getTags(args[0])
if (args.length === 1) {
const { pathname } = new URL(args[0])
args.push('https://docs.github.com' + pathname)
}
const tags2 = await getTags(args[1])
// console.log(tags)
// console.log(tags2)
let differences = 0
for (const [tag, count] of Object.entries(tags)) {
if (count !== tags2[tag]) {
console.log(`<${tag}>: ${count} ≠ ${tags2[tag]}`)
differences++
}
}
if (differences === 0) {
console.log("THEY'RE IDENTICAL!")
} else {
console.log('Differences:', differences)
}
}
main(process.argv.slice(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment