index.js 836 B

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