Files
shencaisuan/tmp/seo-indexing-test.js
2026-07-20 10:55:20 +08:00

93 lines
2.9 KiB
JavaScript

const fs = require("fs");
function read(path) {
return fs.readFileSync(path, "utf8");
}
function assert(condition, message) {
if (!condition) throw new Error(message);
}
const robots = read("robots.txt");
const sitemap = read("sitemap.xml");
const index = read("html/index.html");
const article = read("html/mianfei.html");
const commonUtil = read("utils/CommonUtil.js");
assert(!robots.includes("3d.3dyjs.cn"), "robots should not reference the old domain");
assert(!sitemap.includes("3d.3dyjs.cn"), "sitemap should not reference the old domain");
assert(
robots.includes("Sitemap: https://www.scs8888.cn/sitemap.xml"),
"robots should advertise the production sitemap",
);
const sitemapLocations = Array.from(sitemap.matchAll(/<loc>([^<]+)<\/loc>/g), (match) => match[1]);
assert(sitemapLocations.length === 1, "static sitemap should contain only the confirmed homepage");
assert(
sitemapLocations[0] === "https://www.scs8888.cn/",
"static sitemap homepage should use the canonical production origin",
);
[
"login",
"reg",
"usercenter",
"chongzhi",
"tixian",
"fabumianfeiwenzhang",
"fufei",
].forEach((privateRoute) => {
assert(!sitemap.includes(privateRoute), `private route must not appear in sitemap: ${privateRoute}`);
});
assert(/<meta\s+name="description"/i.test(index), "homepage description metadata missing");
assert(
/<link\s+rel="canonical"\s+href="https:\/\/www\.scs8888\.cn\/"/i.test(index),
"homepage canonical metadata missing",
);
assert(
index.includes('<h1 class="seo-heading">神彩算彩票数据分析与免费预测文章</h1>'),
"homepage crawlable H1 missing",
);
assert(
index.includes("开奖数据、走势分析和免费文章"),
"homepage crawlable site description missing",
);
assert(/<meta\s+name="description"/i.test(article), "article default description metadata missing");
assert(
/<meta\s+name="robots"\s+content="index, follow"/i.test(article),
"article robots metadata missing",
);
assert(
/<link\s+id="canonicalUrl"\s+rel="canonical"/i.test(article),
"article canonical hook missing",
);
assert(article.includes("function updateArticleSeo(data)"), "article SEO updater missing");
assert(article.includes("updateArticleSeo(data);"), "article renderer should update SEO metadata");
assert(
article.includes("https://www.scs8888.cn/mianfei/"),
"article canonical should use the public pretty URL",
);
assert(
/return `\/mianfei\/\$\{id\}\.html`/.test(commonUtil),
"CommonUtil.freeArticleHref should own the public article URL",
);
const deploymentDocPath = "docs/baidu-indexing-deployment.md";
assert(fs.existsSync(deploymentDocPath), "backend deployment handoff missing");
const deploymentDoc = read(deploymentDocPath);
[
"/mianfei/{id}.html",
"404",
"301",
"动态 sitemap",
"Baiduspider",
"预渲染",
].forEach((requiredText) => {
assert(deploymentDoc.includes(requiredText), `deployment handoff missing: ${requiredText}`);
});
console.log("SEO indexing checks passed");