{{ $pages := where .Site.RegularPages "Section""posts" }}
{{ range $pages }} {{ with .Params.categories }} {{ if in . "your_category" }} <!-- 在这里处理符合条件的文章 --> <h2>{{ .Title }}</h2> <p>{{ .Content }}</p> {{ end }} {{ end }} {{ end }}
在上面的示例中:
where .Site.RegularPages "Section" "posts" 用于获取content/posts文件夹下的所有Markdown文件。
{{ with .Params.categories }} 用于检查文章是否有categories元数据。
{{ if in . "your_category" }} 用于检查文章的categories中是否包含你感兴趣的特定类别(在这里用”your_category”作为示例,你需要替换为实际的类别名称)。
{{ $yearDifference := sub $currentYear .Params.year_enrollment_PhD }} {{ index $numMapping (printf "%02d" $yearDifference) }}
默认功能:排序`date
1 2 3 4 5 6 7 8 9 10 11 12
<!-- 遍历所有页面,按照发布日期进行降序排序。.Pages表示网站的所有页面,.ByPublishDate表示按照发布日期排序,.Reverse表示降序排列。 --> {{ range .Pages.ByPublishDate.Reverse }} <p> <!-- RelPermalink是相对于网站根目录的页面链接。 --> <h3><aclass="title"href="{{ .RelPermalink }}">{{ .Title }}</a></h3> {{ partial "metadata.html" . }} <aclass="summary"href="{{ .RelPermalink }}"> <!-- Hugo automatically takes the first 70 words of your content as its summary and stores it into the .Summary variable --> <p>{{ .Summary }}</p> </a> </p> {{ end }}
是非判断
1 2 3 4 5 6 7 8 9 10 11 12
{{ if .Param "display_toc" }} {{ .TableOfContents }} {{ else }} <!-- 如果 display_toc 参数不存在或为 false,执行这里的内容 --> {{ end }} // other {{ if eq (.Param "display_toc") "A" }} {{ .TableOfContents }} {{ else }} <!-- 如果 display_toc 参数不等于 "A",执行这里的内容 --> {{ end }}
navigation bar & footer
config in config.yml
range site.Params is the global site configuration.
range 使用
1 2 3
{{ range site.Params.plugins.css }} <linkrel="stylesheet"href="{{ .link | absURL }}"> {{ end }}
according toml
1 2 3 4 5 6
[[params.plugins.css]] link = "plugins/bootstrap/bootstrap.min.css" [[params.plugins.css]] link = "https://fonts.googleapis.com/css?family=Rubik:300,400,500,700,900&display=swap" [[params.plugins.css]] link = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css"