_check_portal_links.mjs 1.2 KB

1234567891011121314151617181920
  1. import { readFileSync } from 'node:fs'
  2. import { fileURLToPath } from 'node:url'
  3. import { dirname, resolve } from 'node:path'
  4. const HERE = dirname(fileURLToPath(import.meta.url))
  5. const portal = resolve(HERE, '../../../release/web/portal')
  6. let s = readFileSync(portal + '/shell.html', 'utf8')
  7. const ids = Array.from(s.matchAll(/<!--@TEMPLATE:([^>]+?)-->/g)).map((m) => m[1])
  8. for (const id of ids) s = s.replace('<!--@TEMPLATE:' + id + '-->', '<template id="' + id + '">' + readFileSync(portal + '/templates/' + id + '.html', 'utf8') + '</template>')
  9. const T = [
  10. [/<a([^>]*?)href="#cms"/g, '<a$1target="_top" href="/detail/v2#tab=vibration"'],
  11. [/<a([^>]*?)href="#documents"/g, '<a$1target="_top" href="/detail/v2#tab=documents"'],
  12. [/<a([^>]*?)href="#recalc"/g, '<a$1target="_top" href="/detail/v2#tab=recalc"'],
  13. [/<a([^>]*?)href="(?:https?:\/\/[^"]*)?\/(?:detail\/v2|v2)[^"]*"/g, '<a$1target="_top" href="/detail/v2#workbench"'],
  14. ]
  15. for (const [re, to] of T) s = s.replace(re, to)
  16. for (const k of ['tab=vibration', 'tab=documents', 'tab=recalc', 'detail/v2#workbench']) {
  17. console.log(k + ' → ' + (s.includes(k) ? '已写入' : '缺失'))
  18. }
  19. console.log('target_top 次数 ' + (s.match(/target="_top"/g) || []).length)