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