192 lines
8.2 KiB
JavaScript
192 lines
8.2 KiB
JavaScript
/**
|
||
* SEO模板生成器
|
||
* 根据 useSEO.js 的页面配置自动生成静态 HTML 模板,供爬虫访问时返回
|
||
* 配置与 src/composables/useSEO.js 保持一致
|
||
*
|
||
* 多站点:通过环境变量 SEO_BASE_URL 指定 canonical/og:url 域名后生成
|
||
* 例:SEO_BASE_URL=https://www.tianyuandb.com node generate-seo-templates.cjs
|
||
*/
|
||
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
|
||
const BASE_URL = process.env.SEO_BASE_URL || 'https://www.zhinengcha.cn'
|
||
|
||
// 页面 SEO 配置(与 useSEO.js 的 routeConfigs 保持一致)
|
||
const pageSEOConfigs = {
|
||
'index.html': {
|
||
title: '天远助手|大数据风险报告查询与代理平台,支持个人和企业多场景风控应用',
|
||
description: '天远助手,专业大数据风险报告查询与代理平台,支持个人信用查询、小微企业风控、贷前风险背调等多场景报告应用,免费开通代理权限,助力高效识别信用与风险。',
|
||
keywords: '大数据风险报告查询、大数据风险评估、大数据分析报告、个人大数据风险查询、小微企业风险、贷前风险背调、代理管理平台、免费开通代理、风险管控平台、信用风险分析、企业风险报告、贷前信用审核、失信人名单查询、被执行人信息、信用黑名单查询',
|
||
url: BASE_URL
|
||
},
|
||
'agent.html': {
|
||
title: '天远助手代理 - 免费开通代理权限 | 大数据风险报告代理',
|
||
description: '天远助手代理平台,免费开通代理权限,享受大数据风险报告查询服务代理收益。专业的大数据风险报告、婚姻查询、个人信用评估等服务的代理合作。',
|
||
keywords: '天远助手代理, 免费代理, 大数据风险报告代理, 代理权限, 代理收益',
|
||
url: `${BASE_URL}/agent`
|
||
},
|
||
'help.html': {
|
||
title: '帮助中心 - 天远助手使用指南 | 常见问题解答',
|
||
description: '天远助手帮助中心,提供详细的使用指南、常见问题解答、操作教程等,帮助用户更好地使用大数据风险报告查询服务。',
|
||
keywords: '天远助手帮助, 使用指南, 常见问题, 操作教程, 客服支持',
|
||
url: `${BASE_URL}/help`
|
||
},
|
||
'help-guide.html': {
|
||
title: '使用指南 - 天远助手操作教程 | 功能说明',
|
||
description: '天远助手详细使用指南,包含各功能模块的操作教程、功能说明、注意事项等,让用户快速上手使用。',
|
||
keywords: '使用指南, 操作教程, 功能说明, 快速上手, 天远助手教程',
|
||
url: `${BASE_URL}/help/guide`
|
||
},
|
||
'example.html': {
|
||
title: '示例报告 - 天远助手报告展示 | 大数据风险报告样例',
|
||
description: '天远助手示例报告展示,包含大数据风险报告、婚姻状况查询、个人信用评估等服务的报告样例,让用户了解报告内容和格式。',
|
||
keywords: '示例报告, 报告展示, 报告样例, 大数据风险报告, 婚姻查询报告',
|
||
url: `${BASE_URL}/example`
|
||
},
|
||
'service.html': {
|
||
title: '客服中心 - 天远助手在线客服 | 技术支持',
|
||
description: '天远助手客服中心,提供在线客服支持、技术咨询、问题反馈等服务,确保用户获得及时有效的帮助。',
|
||
keywords: '客服中心, 在线客服, 技术支持, 问题反馈, 天远助手客服',
|
||
url: `${BASE_URL}/service`
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 规范化文案:统一为中文标点,避免乱码
|
||
*/
|
||
function normalizeText(str) {
|
||
if (typeof str !== 'string') return str
|
||
return str
|
||
.replace(/\uFFFD/g, '')
|
||
.replace(/。/g, '。')
|
||
.replace(/、/g, '、')
|
||
}
|
||
|
||
/**
|
||
* 转义 HTML 属性值
|
||
*/
|
||
function escapeAttr(str) {
|
||
if (typeof str !== 'string') return ''
|
||
return str
|
||
.replace(/&/g, '&')
|
||
.replace(/"/g, '"')
|
||
.replace(/</g, '<')
|
||
.replace(/>/g, '>')
|
||
}
|
||
|
||
/**
|
||
* 生成单页 HTML 模板
|
||
*/
|
||
function generateHTMLTemplate(config) {
|
||
const title = normalizeText(config.title)
|
||
const description = normalizeText(config.description)
|
||
const keywords = normalizeText(config.keywords)
|
||
const structuredData = {
|
||
'@context': 'https://schema.org',
|
||
'@type': 'WebPage',
|
||
name: title,
|
||
description: description,
|
||
url: config.url,
|
||
mainEntity: {
|
||
'@type': 'Organization',
|
||
name: '天远助手',
|
||
url: 'https://www.zhinengcha.cn/',
|
||
description: '专业大数据风险报告查询与代理平台,支持个人和企业多场景风控应用'
|
||
}
|
||
}
|
||
|
||
return `<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
|
||
<title>${escapeAttr(title)}</title>
|
||
|
||
<meta name="description" content="${escapeAttr(description)}">
|
||
<meta name="keywords" content="${escapeAttr(keywords)}">
|
||
|
||
<meta property="og:title" content="${escapeAttr(title)}">
|
||
<meta property="og:description" content="${escapeAttr(description)}">
|
||
<meta property="og:url" content="${escapeAttr(config.url)}">
|
||
<meta property="og:type" content="website">
|
||
<meta property="og:site_name" content="天远助手">
|
||
<meta property="og:locale" content="zh_CN">
|
||
|
||
<meta name="twitter:card" content="summary">
|
||
<meta name="twitter:title" content="${escapeAttr(title)}">
|
||
<meta name="twitter:description" content="${escapeAttr(description)}">
|
||
<meta name="twitter:url" content="${escapeAttr(config.url)}">
|
||
|
||
<link rel="canonical" href="${escapeAttr(config.url)}">
|
||
|
||
<script type="application/ld+json">
|
||
${JSON.stringify(structuredData, null, 8)}
|
||
</script>
|
||
|
||
<meta name="robots" content="index, follow">
|
||
<meta name="googlebot" content="index, follow">
|
||
<meta name="baiduspider" content="index, follow">
|
||
|
||
<style>
|
||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; margin: 0; padding: 0; line-height: 1.6; }
|
||
.seo-content { max-width: 1200px; margin: 0 auto; padding: 20px; }
|
||
h1 { color: #333; }
|
||
p { color: #666; }
|
||
.redirect-notice { background: #fff3cd; border: 1px solid #ffc107; color: #856404; padding: 10px; margin: 20px 0; border-radius: 4px; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="seo-content">
|
||
<h1>${escapeAttr(title)}</h1>
|
||
<div class="redirect-notice">
|
||
<p>正在跳转到完整版网站...</p>
|
||
<p>如果浏览器没有自动跳转,请 <a href="${escapeAttr(config.url)}">点击这里</a></p>
|
||
</div>
|
||
<p>${escapeAttr(description)}</p>
|
||
<section>
|
||
<h2>关于天远助手</h2>
|
||
<p>天远助手,专业大数据风险报告查询与代理平台,支持个人信用查询、小微企业风控、贷前风险背调等多场景报告应用,免费开通代理权限,助力高效识别信用与风险。</p>
|
||
</section>
|
||
<section>
|
||
<h2>核心服务</h2>
|
||
<ul>
|
||
<li>大数据风险报告查询</li>
|
||
<li>个人信用查询服务</li>
|
||
<li>小微企业风控</li>
|
||
<li>贷前风险背调</li>
|
||
<li>代理管理平台</li>
|
||
<li>风险管控服务</li>
|
||
</ul>
|
||
</section>
|
||
</div>
|
||
</body>
|
||
</html>`
|
||
}
|
||
|
||
function main() {
|
||
const outputDir = path.join(__dirname, '../public/seo-templates')
|
||
|
||
if (!fs.existsSync(outputDir)) {
|
||
fs.mkdirSync(outputDir, { recursive: true })
|
||
console.log(`✓ 创建模板目录: ${outputDir}`)
|
||
}
|
||
|
||
let successCount = 0
|
||
Object.entries(pageSEOConfigs).forEach(([filename, config]) => {
|
||
const htmlContent = generateHTMLTemplate(config)
|
||
const filePath = path.join(outputDir, filename)
|
||
fs.writeFileSync(filePath, htmlContent, 'utf-8')
|
||
console.log(`✓ 生成模板: ${filename}`)
|
||
successCount++
|
||
})
|
||
|
||
console.log(`\n✓ 成功生成 ${successCount} 个 SEO 模板文件`)
|
||
console.log(`📁 模板目录: ${outputDir}`)
|
||
console.log(`💡 配置与 useSEO.js 一致,当前域名: ${BASE_URL}`)
|
||
}
|
||
|
||
main()
|