Section
返回给定页面所属顶层 section 的名称。
内容结构如下:
content/
├── lessons/
│ ├── math/
│ │ ├── _index.md
│ │ ├── lesson-1.md
│ │ └── lesson-2.md
│ └── _index.md
└── _index.md渲染 lesson-1.md 时:
{{ .Section }} → lessons上例中 “lessons” 就是顶层 section。
Section 方法常与 where 函数搭配使用,用来构建页面集合。
{{ range where .Site.RegularPages "Section" "lessons" }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}这与把 Type 方法与 where 函数搭配使用类似
{{ range where .Site.RegularPages "Type" "lessons" }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}不过,如果有一个或多个页面在前置元数据中定义了 type 字段,那么基于 Type 的页面集合会与基于 Section 的页面集合不同。