Title

为页面生成带有分隔符、栏目和国际化的分页信息的标题。

配置

hugo.yaml

1params:
2  title_sections: true
3  title_separator: '-'

hugo.toml

1[params]
2  title_sections = true
3  title_separator = '-'

hugo.json

1{
2   "params": {
3      "title_sections": true,
4      "title_separator": "-"
5   }
6}

参数

title_separator

名称类型必填默认值版本
title_separatorstring---

标题分隔符。

title_sections

名称类型必填默认值版本
title_sectionsboolean-true-

false 时隐藏栏目标题。

title_sections_depth

名称类型必填默认值版本
title_sections_depthnumber---

栏目的最大深度。

title_sections_depth_dir

名称类型必填默认值版本
title_sections_depth_dirstring-end-

栏目数目计算方向,为 start 时,深度是从根部开始计算的。

用法

 1{{/* baseof.html */}}
 2<html>
 3  <head>
 4    <title>
 5      {{ block "title" . }}{{ partial "base/title" . }}{{ end }}
 6    </title>
 7  </head>
 8  <body>
 9    {{ block "main" . }}{{ end }}
10  </body>
11</html>
 1{{/* list.html */}}
 2{{ define "title" }}
 3  {{ $mainSections := slice "blog" }}
 4  {{ $pages := where .Site.RegularPages "Type" "in" $mainSections }}
 5  {{/* We MUST initialize the paginator first. */}}
 6  { $paginator := .Paginate $pages 10 }}
 7  {{/* Then include the title partial. */}}
 8  {{ partial "base/title" . }}
 9{{ end }}
10
11{{ define "main" }}
12  {{/* Use the initialized paginator above. */}}
13  {{ range .Paginator.Pages }}
14    {{/* List pages. */}}
15  {{ end }}
16  {{ template "_internal/pagination.html" . }}
17{{ end }}

示例

PageKindTitle
/HomeMy Site.
/page/1ListMy Site - Page 1 of N.
/page/2ListMy Site - Page 2 of N.
/blogSectionBlog - My Site.
/blog/page/1SectionBlog - Page 1 of N. - My Site.
/blog/page/2SectionBlog - Page 1 of N. - My Site.
/blog/helloPageHello world - Blog - My Site.
/blog/fooSectionFoo - My Site.
/blog/foo/barPageBar - Foo - My Site.