logoPay4SaaS
增长

全自动 Sitemap 与 Robots

Sitemap 告诉搜索引擎你有哪些页面,加速收录。robots.txt 告诉爬虫哪些页面可以抓取、哪些不可以,并指向 Sitemap 地址。

Pay4SaaS 内置了全自动的 sitemap(app/sitemap.ts)和 robots.txt(app/robots.ts)。不需要任何配置,也不用手动维护——部署即生效。

自动收录的页面

sitemap 会在构建时自动扫描并收录以下页面:

页面类型来源URL 格式优先级
首页app/page.tsx/1.0
定价页app/pricing/page.tsx/pricing(lifetime 模式下排除)0.8
隐私政策 & 服务条款app/privacy/, app/terms//privacy, /terms0.2
文档(英文)content/docs/**/*.mdx/docs/{slug}0.6
文档(中文)content/docs/**/*.cn.mdx/cn/docs/{slug}0.6
博客(英文)content/blog/*.mdx/blog/{slug}0.6
博客(中文)content/blog/*.cn.mdx/cn/blog/{slug}0.6

每次新增文档或博客后,sitemap 会在下次构建时自动更新。

文档部分的判断逻辑很简单:构建时检查 content/docs/ 文件夹是否存在,存在就递归扫描里面所有 .mdx 文件并加入 sitemap,不存在就跳过。如果你不需要文档功能,删掉 content/docs/ 文件夹即可,sitemap 会自动忽略。

lastModified 的工作原理

sitemap 不会用 new Date() 给所有页面打上当前时间(那样会让 Google 误以为每个页面都在频繁更新),而是通过 git log 读取每个文件的最后一次 Git 提交时间

这意味着:

  • 只有真正修改过的页面才会获得新的时间戳
  • Google 能准确判断哪些页面需要重新抓取
  • 爬虫资源不会被浪费

robots.txt 的行为

app/robots.ts 会根据站点模式生成不同的规则:

主站(默认):

User-agent: *
Allow: /
Sitemap: https://yourdomain.com/sitemap.xml

副站NEXT_PUBLIC_LOCALE_SITE=cn):

User-agent: *
Disallow: /

副站会屏蔽所有爬虫,避免和主站产生重复内容问题。只有主站会被搜索引擎收录。副站的目的是方便国内用户支付以及分担运营风险,不需要被搜索引擎收录。

验证方法

部署后,检查以下 URL:

  • https://yourdomain.com/sitemap.xml — 应该能看到所有页面列表
  • https://yourdomain.com/robots.txt — 应该显示 Allow: / 和 sitemap 地址

然后在 Google Search Console → 编制索引 → 站点地图,提交 sitemap。

自定义

从 sitemap 中排除某个页面

sitemap 只收录 app/sitemap.tsstaticPages 数组里的静态页面,以及 content/docs/content/blog/ 下的内容页面。/dashboard/login/api/* 等私有路由不会被收录。

如果需要排除某个静态页面,从 app/sitemap.tsstaticPages 数组中移除即可。

修改优先级或更新频率

直接编辑 app/sitemap.ts 中的值:

const staticPages = [
  { url: '/', file: 'app/page.tsx', priority: 1.0, changeFrequency: 'daily' },
  { url: '/pricing', file: 'app/pricing/page.tsx', priority: 0.8, changeFrequency: 'monthly' },
  // ...
]

文档和博客的默认值是 priority: 0.6changeFrequency: 'weekly'。如需调整,修改 getContentPages() 函数中的对应值。

On this page