up seo
This commit is contained in:
261
scripts/seo-static-generator/generateStaticPages.js
Normal file
261
scripts/seo-static-generator/generateStaticPages.js
Normal file
@@ -0,0 +1,261 @@
|
||||
/**
|
||||
* 静态页面生成器
|
||||
* 基于路由和SEO配置自动生成静态HTML页面
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { generateStaticHTML, generateContentByRoute } from './pageTemplates.js';
|
||||
|
||||
// 获取当前文件的目录
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
// SEO配置 - 直接从useSEO.js复制过来
|
||||
const seoConfigs = {
|
||||
'/': {
|
||||
title: '天远查官网_企业与婚姻关联风险核验_综合履约背景核验',
|
||||
description: '天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。数据实时同步,助您精准规避投资、交易及家庭结合中的经济与法律风险。',
|
||||
keywords: '天远查,婚姻状态风险, 配偶背景核验,企业信用查询,司法诉讼记录,资产风险评估'
|
||||
},
|
||||
'/inquire/category/lawsuit': {
|
||||
title: '司法涉诉核验_个人及企业法律诉讼记录_履约风险评估_天远查',
|
||||
description: '天远查司法风险检测中心,聚合全国法院公开公示数据。一键筛查开庭公告、裁判文书、立案信息及执行记录。帮助用户快速识别法律纠纷隐患,全方位扫除合作盲区。',
|
||||
keywords: '司法案件核验,法律诉讼记录,个人涉诉详情,法院公告查询,案件执行状态'
|
||||
},
|
||||
'/inquire/marriage': {
|
||||
title: '婚前背景核验_婚姻关联司法风险筛查_情感综合保障_天远查',
|
||||
description: '天远查婚恋风险报告为您提供深度的背景核实服务。基于合法公开数据,排查对象的重婚司法记录、家庭暴力涉诉历史、潜在债务风险及不良嗜好风险。拒绝盲目信任,用数据守护您的情感与财产安全。',
|
||||
keywords: '婚前背景核实,婚恋对象评估,婚姻司法风险,个人情感风险,婚前背调工具'
|
||||
},
|
||||
'/inquire/category/vehicle': {
|
||||
title: '车辆档案报告_二手车车况与产权风险检测_机动车报告_天远查',
|
||||
description: '天远查车辆数据中心,让车辆交易更透明。支持通过车牌号或VIN码,核验车辆的初次登记信息、抵押查封状态、事故维修记录及产权属性。数据同步权威行业系统,精准识别问题车。',
|
||||
keywords: '车辆维修记录,二手车出险报告,车辆抵押报告,车况报告,机动车档案'
|
||||
},
|
||||
'/inquire/category/marriageStatus': {
|
||||
title: '个人婚姻关联风险核验_家庭背景合规报告_天远查',
|
||||
description: '天远查提供基于大数据的婚姻关联风险评估。通过分析司法文书及公开社会关系,辅助判断目标的真实家庭状况与情感履历。合法合规,保障知情权。',
|
||||
keywords: '婚史风险排查,家庭背景核实,婚姻诚信评估,情感状态评估,涉婚法律记录'
|
||||
},
|
||||
'/agent': {
|
||||
title: '天远查代理 - 免费开通代理权限 | 大数据风险报告代理',
|
||||
description: '天远查代理平台,免费开通代理权限,享受大数据风险报告查询服务代理收益。专业的大数据风险报告、婚姻查询、个人信用评估等服务的代理合作。',
|
||||
keywords: '天远查代理, 免费代理, 大数据风险报告代理, 代理权限, 代理收益'
|
||||
},
|
||||
'/help': {
|
||||
title: '帮助中心 - 天远查使用指南 | 常见问题解答',
|
||||
description: '天远查帮助中心,提供详细的使用指南、常见问题解答、操作教程等,帮助用户更好地使用大数据风险报告查询服务。',
|
||||
keywords: '天远查帮助, 使用指南, 常见问题, 操作教程, 客服支持'
|
||||
},
|
||||
'/help/guide': {
|
||||
title: '使用指南 - 天远查操作教程 | 功能说明',
|
||||
description: '天远查详细使用指南,包含各功能模块的操作教程、功能说明、注意事项等,让用户快速上手使用。',
|
||||
keywords: '使用指南, 操作教程, 功能说明, 快速上手, 天远查教程'
|
||||
},
|
||||
'/example': {
|
||||
title: '示例报告 - 天远查报告展示 | 大数据风险报告样例',
|
||||
description: '天远查示例报告展示,包含大数据风险报告、婚姻状况查询、个人信用评估等服务的报告样例,让用户了解报告内容和格式。',
|
||||
keywords: '示例报告, 报告展示, 报告样例, 大数据风险报告, 婚姻查询报告'
|
||||
},
|
||||
'/service': {
|
||||
title: '客服中心 - 天远查在线客服 | 技术支持',
|
||||
description: '天远查客服中心,提供在线客服支持、技术咨询、问题反馈等服务,确保用户获得及时有效的帮助。',
|
||||
keywords: '客服中心, 在线客服, 技术支持, 问题反馈, 天远查客服'
|
||||
},
|
||||
'/inquire': {
|
||||
title: '核验工具多场景数据核验服务天远查',
|
||||
description: '提供车辆、企业、个人等多场景核验,包括状态、信用、身份等查询,权威高效,保护隐私。',
|
||||
keywords: '核验工具,数据核验服务,车辆核验,企业核验,天远查'
|
||||
},
|
||||
};
|
||||
|
||||
// 额外的路由配置(从router.js提取)
|
||||
const additionalRoutes = [
|
||||
{ path: '/historyQuery', title: '历史报告' },
|
||||
{ path: '/withdraw', title: '提现' },
|
||||
{ path: '/complaint', title: '投诉' },
|
||||
{ path: '/report', title: '报告结果' },
|
||||
{ path: '/agent/promote', title: '代理推广' },
|
||||
{ path: '/me', title: '个人中心' },
|
||||
];
|
||||
|
||||
// 输出目录配置
|
||||
const OUTPUT_DIR = path.resolve(__dirname, 'static-pages');
|
||||
|
||||
// 确保输出目录存在
|
||||
function ensureOutputDir() {
|
||||
try {
|
||||
if (!fs.existsSync(OUTPUT_DIR)) {
|
||||
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
|
||||
console.log(`📁 创建输出目录: ${OUTPUT_DIR}`);
|
||||
}
|
||||
console.log(`📂 输出目录已存在: ${OUTPUT_DIR}`);
|
||||
} catch (error) {
|
||||
console.error(`❌ 创建目录失败: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// 将路径转换为文件名
|
||||
function pathToFilename(routePath) {
|
||||
// 替换特殊字符
|
||||
let filename = routePath
|
||||
.replace(/^\//, '') // 移除开头的 /
|
||||
.replace(/\/+/g, '-') // 将 / 替换为 -
|
||||
.replace(/:/g, '-') // 将 : 替换为 -
|
||||
|
||||
// 如果是根路径,使用 index
|
||||
if (!filename) {
|
||||
filename = 'index';
|
||||
}
|
||||
|
||||
return `${filename}.html`;
|
||||
}
|
||||
|
||||
// 生成静态页面
|
||||
function generatePage(routePath, seoConfig) {
|
||||
const filename = pathToFilename(routePath);
|
||||
const filepath = path.join(OUTPUT_DIR, filename);
|
||||
|
||||
// 生成页面内容
|
||||
const content = generateContentByRoute(routePath, seoConfig);
|
||||
|
||||
// 生成完整的HTML
|
||||
const html = generateStaticHTML(seoConfig, {
|
||||
path: routePath,
|
||||
content: content,
|
||||
canonical: 'https://www.tianyuancha.cn'
|
||||
});
|
||||
|
||||
// 写入文件
|
||||
fs.writeFileSync(filepath, html, 'utf-8');
|
||||
process.stdout.write(`✅ 生成成功: ${filename}\n`);
|
||||
|
||||
return filepath;
|
||||
}
|
||||
|
||||
// 生成所有静态页面
|
||||
function generateAllPages() {
|
||||
console.log('🚀 开始生成静态页面...\n');
|
||||
|
||||
ensureOutputDir();
|
||||
|
||||
// 生成主要路由的页面
|
||||
console.log('📝 生成主要路由页面:');
|
||||
let count = 0;
|
||||
for (const [routePath, seoConfig] of Object.entries(seoConfigs)) {
|
||||
try {
|
||||
generatePage(routePath, seoConfig);
|
||||
count++;
|
||||
} catch (error) {
|
||||
console.error(`❌ 生成失败 [${routePath}]:`, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成额外路由的页面
|
||||
console.log('\n📝 生成额外路由页面:');
|
||||
for (const route of additionalRoutes) {
|
||||
try {
|
||||
const seoConfig = {
|
||||
title: `${route.title} - 天远查`,
|
||||
description: `天远查${route.title}页面,提供专业的大数据风险管控服务。`,
|
||||
keywords: `天远查,${route.title}`
|
||||
};
|
||||
generatePage(route.path, seoConfig);
|
||||
count++;
|
||||
} catch (error) {
|
||||
console.error(`❌ 生成失败 [${route.path}]:`, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成sitemap
|
||||
generateSitemap();
|
||||
|
||||
console.log(`\n✨ 完成!共生成 ${count} 个静态页面`);
|
||||
console.log(`📁 输出目录: ${OUTPUT_DIR}`);
|
||||
}
|
||||
|
||||
// 生成sitemap.xml
|
||||
function generateSitemap() {
|
||||
const sitemapPath = path.join(OUTPUT_DIR, 'sitemap.xml');
|
||||
|
||||
const baseUrl = 'https://www.tianyuancha.cn';
|
||||
const currentDate = new Date().toISOString().split('T')[0];
|
||||
|
||||
let sitemap = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
`;
|
||||
|
||||
// 添加主要路由
|
||||
for (const [routePath] of Object.entries(seoConfigs)) {
|
||||
const priority = routePath === '/' ? '1.0' : '0.8';
|
||||
sitemap += ` <url>
|
||||
<loc>${baseUrl}${routePath}</loc>
|
||||
<lastmod>${currentDate}</lastmod>
|
||||
<changefreq>weekly</changefreq>
|
||||
<priority>${priority}</priority>
|
||||
</url>
|
||||
`;
|
||||
}
|
||||
|
||||
// 添加额外路由
|
||||
for (const route of additionalRoutes) {
|
||||
sitemap += ` <url>
|
||||
<loc>${baseUrl}${route.path}</loc>
|
||||
<lastmod>${currentDate}</lastmod>
|
||||
<changefreq>weekly</changefreq>
|
||||
<priority>0.6</priority>
|
||||
</url>
|
||||
`;
|
||||
}
|
||||
|
||||
sitemap += `</urlset>`;
|
||||
|
||||
fs.writeFileSync(sitemapPath, sitemap, 'utf-8');
|
||||
console.log(`✅ 生成成功: ${sitemapPath}`);
|
||||
}
|
||||
|
||||
// 生成robots.txt
|
||||
function generateRobots() {
|
||||
const robotsPath = path.join(OUTPUT_DIR, 'robots.txt');
|
||||
|
||||
const robotsContent = `User-agent: *
|
||||
Allow: /
|
||||
|
||||
# 禁止爬取后台管理页面
|
||||
Disallow: /admin
|
||||
Disallow: /api
|
||||
|
||||
# Sitemap
|
||||
Sitemap: https://www.tianyuancha.cn/sitemap.xml
|
||||
`;
|
||||
|
||||
fs.writeFileSync(robotsPath, robotsContent, 'utf-8');
|
||||
console.log(`✅ 生成成功: ${robotsPath}`);
|
||||
}
|
||||
|
||||
// 主函数
|
||||
function main() {
|
||||
console.log('='.repeat(60));
|
||||
console.log(' 天远查 - 静态页面生成器');
|
||||
console.log('='.repeat(60));
|
||||
console.log();
|
||||
|
||||
try {
|
||||
generateAllPages();
|
||||
generateRobots();
|
||||
console.log('\n🎉 所有文件生成完成!');
|
||||
} catch (error) {
|
||||
console.error('\n❌ 生成失败:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果直接运行此脚本
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
main();
|
||||
}
|
||||
|
||||
export { generateAllPages, generatePage };
|
||||
Reference in New Issue
Block a user