TEMPLATES

Sitemap templates

概述

Hugo 的內建網站地圖模板符合 網站地圖協議 v0.9。

對於單語專案,Hugo 會使用 內建網站地圖模板 在根目錄的 publishDir 生成 sitemap.xml 檔案。

對於多語專案,Hugo 會生成:

設定

以下是網站地圖的預設設定值,除非在 front matter 中覆寫,否則會應用於所有頁面。

hugo.
     
sitemap:
  changeFreq: ""
  disable: false
  filename: sitemap.xml
  priority: -1
[sitemap]
  changeFreq = ''
  disable = false
  filename = 'sitemap.xml'
  priority = -1
{
   "sitemap": {
      "changeFreq": "",
      "disable": false,
      "filename": "sitemap.xml",
      "priority": -1
   }
}
changefreq
(string) 頁面可能變更的頻率。有效值為 alwayshourlydailyweeklymonthlyyearlynever。預設值為 "",此時 Hugo 會在網站地圖中省略此欄位。詳情請參見 網站地圖協議
disable New in v0.125.0
(bool) 是否禁用頁面納入網站地圖。預設為 false。在 front matter 中設為 true 可排除此頁面。
filename
(string) 生成的檔案名稱。預設為 sitemap.xml
priority
(float) 頁面相對於網站上其他頁面的優先級。有效值範圍為 0.0 到 1.0。預設為 -1,此時 Hugo 會在網站地圖中省略此欄位。詳情請參見 網站地圖協議

覆寫預設值

在 front matter 中覆寫特定頁面的預設值。

news.md
     
---
sitemap:
  changefreq: weekly
  disable: true
  priority: 0.8
title: 新聞
---
+++
title = '新聞'
[sitemap]
  changefreq = 'weekly'
  disable = true
  priority = 0.8
+++
{
   "sitemap": {
      "changefreq": "weekly",
      "disable": true,
      "priority": 0.8
   },
   "title": "新聞"
}

覆寫內建模板

要覆寫內建的 sitemap.xml 模板,可以在以下位置建立新檔案:

  • layouts/sitemap.xml
  • layouts/_default/sitemap.xml

在遍歷頁面集合時,可使用 .Sitemap.ChangeFreq.Sitemap.Priority 訪問 變更頻率優先級

要覆寫內建的 sitemapindex.xml 模板,可以在以下位置建立新檔案:

  • layouts/sitemapindex.xml
  • layouts/_default/sitemapindex.xml

停用網站地圖生成

您可以在網站配置中停用網站地圖的生成:

hugo.
     
disableKinds:
- sitemap
disableKinds = ['sitemap']
{
   "disableKinds": [
      "sitemap"
   ]
}