按 Enter 键跳转到正文

SEO 优化与部署上线

内置 SEO 层(移植自 PaperMod 思路)

全部由 Hugo 模板实现,零插件:

能力说明
robots 索引控制生产构建 index, followhugo server 输出 noindex, nofollow;单篇 robotsNoIndex: true 屏蔽
robots.txt主题自带模板:生产放行 + 指向 sitemap;开发环境 Disallow: /
结构化数据首页 Organization(含 sameAs 社交链接)、全站 BreadcrumbList、文章 BlogPosting(headline/全文/作者/publisher)
分享卡片Open Graph(og:image 自动取 featured/封面/正文首图)与 Twitter Cards(summary_large_image)
元数据keywords(回退 tags)、authorcanonical(支持 canonicalURL 覆盖)、四种站长验证 meta
性能CSS 指纹 + preload + SRI、favicon 家族 + theme-color

关键开关:

 1[params.seo]
 2  enableOpenGraph    = true
 3  enableTwitterCards = true
 4  enableSchema       = true
 5  alwaysInclude      = false    # true = 开发环境也输出 OG/JSON-LD(调试用)
 6  [params.seo.verification]
 7    google = ""   # Google Search Console 验证码
 8    bing   = ""
 9    yandex = ""
10    naver  = ""

默认仅在生产环境输出 OG/Twitter/JSON-LD,避免开发环境污染索引。 验证 meta 在 Google/Bing/Yandex/Naver 站长后台"添加站点"时获得,粘贴即生效。

部署

Netlify(推荐)

1# netlify.toml
2[build]
3  command = "hugo --minify && npx pagefind --site public"
4  publish = "public"

Vercel

Framework Preset 选 Hugo,构建命令同上,输出目录 public

GitHub Pages(Actions)

1# .github/workflows/hugo.yml(要点)
2- uses: peaceiris/actions-hugo@v2
3  with: { hugo-version: '0.165.0', extended: true }
4- run: hugo --minify && npx pagefind --site public
5- uses: peaceiris/actions-gh-pages@v3
6  with: { github_token: ${{ secrets.GITHUB_TOKEN }}, publish_dir: ./public }

上线前检查清单

  • config.tomlbaseURL 改为正式域名(Pagefind 索引依赖)
  • params.seo.verification 填入各搜索引擎验证码
  • params.social 配置社交链接(供 sameAs 与 twitter:site 使用)
  • params.comments 配置评论(如需);替换示例图片;删除 draft: true
  • 本地 hugo --minify && npx pagefind --site public 构建无报错
  • 部署后访问 /robots.txt/sitemap.xml 确认存在且指向正确域名

验证工具

发表评论