preview-reports.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // 临时预览服务:http://localhost:8787 -> 列出 reports/ 下所有 html
  2. const http = require('http');
  3. const fs = require('fs');
  4. const path = require('path');
  5. const ROOT = path.join(process.cwd(), 'reports');
  6. const PORT = 8787;
  7. function buildIndex() {
  8. const files = fs.readdirSync(ROOT).filter((f) => f.endsWith('.html'));
  9. const links = files.map((f) => {
  10. const size = (fs.statSync(path.join(ROOT, f)).size / 1024).toFixed(1);
  11. return `<a href="${f}">📄 ${f} <span class="size">${size}KB</span></a>`;
  12. }).join('');
  13. return `<!doctype html>
  14. <meta charset="utf-8">
  15. <title>VOC Reports</title>
  16. <style>
  17. body{font-family:'Inter',system-ui;background:#0a0e1a;color:#ecf2ff;padding:48px;margin:0;}
  18. h1{color:#FE2C55;font-size:1.8rem;margin:0 0 8px;}
  19. .sub{color:#8795a9;margin-bottom:28px;font-size:.9rem;}
  20. a{color:#25F4EE;display:block;padding:16px 22px;background:#121827;border-radius:10px;margin:10px 0;text-decoration:none;font-size:1.05rem;border-left:3px solid #25F4EE;transition:all .15s;}
  21. a:hover{background:#1a2238;transform:translateX(4px);}
  22. .size{float:right;color:#8795a9;font-family:'JetBrains Mono',monospace;font-size:.85rem;}
  23. .tips{margin-top:30px;padding:18px;background:#121827;border-radius:10px;border-left:3px solid #FE2C55;font-size:.85rem;line-height:1.7;}
  24. .tips strong{color:#FE2C55;}
  25. </style>
  26. <h1>📊 VOC 报告(含 TikTok 海外阵地 slide)</h1>
  27. <div class="sub">Total slides per report: <strong style="color:#25F4EE">12</strong> (基础 10 + TikTok + 抖音)</div>
  28. ${links}
  29. <div class="tips">
  30. <strong>TikTok slide 关键字</strong>:<br>
  31. · liver → milk thistle / liver cleanse detox / silymarin / liver support supplement<br>
  32. · probiotic → kids probiotics / children probiotics gummy / probiotics gummies for kids / daily probiotic for kids<br>
  33. · monkey → lions mane mushroom supplement / lion mane mushroom / stomach gut health supplement / lions mane gummies
  34. </div>`;
  35. }
  36. http.createServer((req, res) => {
  37. const url = decodeURIComponent((req.url || '/').split('?')[0]);
  38. if (url === '/' || url === '/index.html') {
  39. res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
  40. res.end(buildIndex());
  41. return;
  42. }
  43. const fp = path.join(ROOT, url.replace(/^\/+/, ''));
  44. if (!fp.startsWith(ROOT) || !fs.existsSync(fp)) {
  45. res.writeHead(404); res.end('Not Found'); return;
  46. }
  47. res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
  48. fs.createReadStream(fp).pipe(res);
  49. }).listen(PORT, () => console.log('Preview server → http://localhost:' + PORT));