_check_portal2.mjs 1.3 KB

12345678910111213141516171819202122232425
  1. import { readFileSync } from 'node:fs'
  2. import { fileURLToPath } from 'node:url'
  3. import { dirname, resolve } from 'node:path'
  4. import { JSDOM, VirtualConsole } from 'jsdom'
  5. const HERE = dirname(fileURLToPath(import.meta.url))
  6. const portal = resolve(HERE, '../../../release/web/portal')
  7. const shell = readFileSync(portal + '/shell.html', 'utf8')
  8. const ids = Array.from(shell.matchAll(/<!--@TEMPLATE:([^>]+?)-->/g)).map((m) => m[1])
  9. let s = shell
  10. for (const id of ids) {
  11. const body = readFileSync(portal + '/templates/' + id + '.html', 'utf8')
  12. s = s.replace('<!--@TEMPLATE:' + id + '-->', '<template id="' + id + '">' + body + '</template>')
  13. }
  14. const gs = readFileSync(portal + '/governance_sources.json', 'utf8')
  15. s = s.replace('<!--@GOVERNANCE_SOURCES-->', gs.replace(/</g, '\\u003c'))
  16. const dom = new JSDOM(s, { virtualConsole: new VirtualConsole() })
  17. const d = dom.window.document
  18. const bodyText = (d.body ? d.body.textContent : '').replace(/\s+/g, ' ')
  19. console.log('IDS ' + ids.length)
  20. console.log('LEFT_MARKERS ' + (s.match(/<!--@TEMPLATE:/g) || []).length)
  21. console.log('TPL_ELEMENTS ' + d.querySelectorAll('template[id]').length)
  22. console.log('TITLE ' + d.title)
  23. console.log('BODY_HAS_MARKUP_TEXT ' + /utf-8|&lt;!DOCTYPE|:root\{/.test(bodyText))
  24. console.log('BODY_TEXT_HEAD ' + bodyText.slice(0, 160))