index.mjs 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import checkSanitizeOptions from './checkSanitizeOptions.mjs'
  2. import Scrape from './scrape.mjs'
  3. import { fileURLToPath } from 'node:url'
  4. const { getAllPagesAndCache, scrapeAndCachePage } = Scrape
  5. async function main() {
  6. const BASE_URL = process.argv.pop()
  7. if (!BASE_URL.startsWith('http')) {
  8. throw new Error(
  9. 'Usage: node scripts/learn/checkSanitize/index.mjs https://LEARN_WIKI'
  10. )
  11. }
  12. const pages = await getAllPagesAndCache(BASE_URL)
  13. for (const page of pages) {
  14. try {
  15. const parsed = await scrapeAndCachePage(BASE_URL, page)
  16. const title = parsed.title
  17. const text = parsed.text ? parsed.text['*'] : ''
  18. checkSanitizeOptions(page, title, text)
  19. } catch (e) {
  20. console.error('---')
  21. console.error(page, e)
  22. throw e
  23. }
  24. }
  25. }
  26. if (fileURLToPath(import.meta.url) === process.argv[1]) {
  27. try {
  28. await main()
  29. process.exit(0)
  30. } catch (error) {
  31. console.error(error)
  32. process.exit(1)
  33. }
  34. }