-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68fbcf3
commit e80bd7c
Showing
22 changed files
with
502 additions
and
392 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
import fs from 'fs' | ||
|
||
const queue = ['https://seattlejs.com/', 'https://seattlejs.com/events'] | ||
/** @type {Set<string>} */ | ||
// eslint-disable-next-line no-undef | ||
const visited = new Set() | ||
|
||
async function crawl() { | ||
while (queue.length) { | ||
let url = queue.shift() | ||
if (!url || visited.has(url)) continue | ||
|
||
visited.add(url) | ||
console.log(`Crawling ${url}`) | ||
|
||
let res = await fetch(url) | ||
let text = await res.text() | ||
let matches = text.match(/https?:\/\/[^'"\s)]+/g) || [] | ||
|
||
const links = text.match(/href="([^"]+)"/g) || [] | ||
matches = matches.concat( | ||
...links | ||
.map(m => { | ||
const url = m.match(/href="([^"]+)"/)[1] | ||
if (url.match(/^https?:\/\/seattlejs.com/)) return url | ||
if (url.startsWith('/')) return `https://seattlejs.com${url}` | ||
return null | ||
}) | ||
.filter(m => !!m), | ||
) | ||
|
||
// console.log(matches) | ||
|
||
for (let match of matches) { | ||
if (match.match(/^https?:\/\/seattlejs.com/)) { | ||
queue.push(match) | ||
} | ||
} | ||
} | ||
} | ||
|
||
await crawl() | ||
fs.writeFileSync('urls.json', JSON.stringify(Array.from(visited), null, 2)) |
Oops, something went wrong.