Repository navigation
fix(seo): 统一全站多语言路由、canonical、sitemap 与 llms.txt 为带尾斜杠零跳转 URL - #30
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景与问题
线上 Coolify / Nixpacks 静态服务器通过目录索引(
dist/<route>/index.html)托管 92 条多语言 SSG 路由:https://moklu.app/zh/merge-images)时,源站返回301 -> http://moklu.app/zh/merge-images/,随后 Cloudflare 再301 -> https://moklu.app/zh/merge-images/(共 2 次重定向);<link rel="canonical">、hreflang、JSON-LD、sitemap.xml与llms.txt此前输出无尾斜杠地址,造成规范网址与最终落地 URL 互指冲突,易在 Google Search Console 触发「网页会自动重定向 / 规范网址冲突」并损耗抓取配额。改动摘要
HTTP 200):src/seo/routes.ts:buildLocalizedPath与buildCanonicalUrl将所有非根子路由统一规范为带尾斜杠格式(/、/zh/、/zh/merge-images/、/studio/等),同时resolvePathname继续兼容有/无尾斜杠入站路径;src/seo/ssg.ts:getRouteRelativeHtmlPath使用split('/').filter(Boolean)稳健解析目录段,保持dist/<route>/index.html输出结构不变;<link rel="canonical">、og:url、5 条hreflang、JSON-LD(BreadcrumbList/WebPage/WebApplication)、sitemap.xml(全部 92 条<loc>)、llms.txt及站内所有 SPA 导航链接同步切换为尾斜杠地址。src/seo/seo.test.ts(新增全量 92 条路由与sitemap.xml<loc>尾斜杠不变量断言)、src/seo/geo.test.ts、src/components/common/ChunkErrorBoundary.test.tsx、tests/e2e/seo-and-tools.spec.mjs(含无斜杠入站路径归一化到带斜杠 canonical 的回归断言)及tests/live/*.spec.mjs;src/seo/GEMINI.md、README.md、docs/analytics.md与CHANGELOG.md。验证结果
npm run typecheck:0 errornpm run lint:0 error / 0 warningnpm test:81 文件 / 958 用例全部通过npm run build:92 路由 SSG +sitemap.xml+robots.txt+llms.txt构建通过node scripts/check-headers.mjs:0 failures