/* 静态预渲染:把 LandingPage 渲染为静态 HTML 注入 dist/index.html 的 #root, 让 Google / Bing / ChatGPT / Perplexity 等不执行 JS 的爬虫也能读到真实正文。 同时生成 robots.txt 与 sitemap.xml。 */ const esbuild = require('esbuild'); const React = require('react'); const ReactDOMServer = require('react-dom/server'); const fs = require('fs'); const path = require('path'); const FRONT = '/app/frontend'; const OUT = path.join(FRONT, 'dist'); // 1) 用 esbuild 把组件打包成 CJS(react/react-dom/react-router-dom 保持 external,复用运行时同一实例) esbuild.buildSync({ entryPoints: [path.join(FRONT, 'prerender-entry.tsx')], bundle: true, format: 'cjs', platform: 'node', outfile: path.join(FRONT, 'prerender-bundle.cjs'), alias: { '@': path.join(FRONT, 'src') }, loader: { '.css': 'empty', '.tsx': 'tsx', '.ts': 'ts' }, jsx: 'automatic', external: ['react', 'react-dom', 'react-router-dom'], logLevel: 'info', }); // 2) 服务端渲染为静态标记 const mod = require(path.join(FRONT, 'prerender-bundle.cjs')); const ssrHtml = ReactDOMServer.renderToStaticMarkup(React.createElement(mod.App)); console.log('[prerender] ssrHtml length =', ssrHtml.length); // 3) 注入 dist/index.html 的 #root let html = fs.readFileSync(path.join(OUT, 'index.html'), 'utf8'); const rootOpen = '
'; if (html.includes(rootOpen)) { html = html.replace(rootOpen, ''); } // 4) SEO/GEO
元数据:替换已有 title/description(避免重复),再注入 og/canonical/JSON-LD const title = '七虎AI · 个人体验 AI、办公提效与 AI 创收的一站式平台'; const desc = '七虎AI 是面向个人与职场用户的 AI 平台:低价订阅无限 Token、垂直办公模板、可交易技能市场、AI 创作试炼场与低成本养模型,让每个人用 AI 把事做成。'; const jsonLd = { '@context': 'https://schema.org', '@type': 'SoftwareApplication', name: '七虎AI', applicationCategory: 'BusinessApplication', operatingSystem: 'Web', offers: { '@type': 'Offer', price: '0', priceCurrency: 'CNY' }, aggregateRating: { '@type': 'AggregateRating', ratingValue: '4.8', reviewCount: '1000' }, url: 'https://ai.qihuyun.com/', }; // 替换/新增 title 与 description(避免与源模板重复) html = html.replace(/