mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-24 21:56:05 +02:00
Add sort and grouping functions for publish date and param of Page
`GroupBy` is modified to allow it to receive a method name argument for example `Type` as its first argument. It is only allowed to call with a method which takes no arguments and returns a result or a pair of a result and an error. The functions discussed at #443 are also added - `ByPublishDate`: Order contents by `PublishDate` front matter variable - `GroupByPublishDate(format, order)`: Group contents by `PublishDate` front matter variable formatted in string like `GroupByDate` - `GroupByParam(key, order)`: Group contents by `Param` front matter variable specified by `key` argument - `GroupByParamDate(key, format, order)`: Group contents by `Param` front matter variable specified by `key` argument and formatted in string like `GroupByDate`. It's effective against `time.Time` type front matter variable
This commit is contained in:
@@ -178,6 +178,15 @@ your list templates:
|
||||
</li>
|
||||
{{ end }}
|
||||
|
||||
### Order by PublishDate
|
||||
|
||||
{{ range .Data.Pages.ByPublishDate }}
|
||||
<li>
|
||||
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
||||
<div class="meta">{{ .PublishDate.Format "Mon, Jan 2, 2006" }}</div>
|
||||
</li>
|
||||
{{ end }}
|
||||
|
||||
### Order by Length
|
||||
|
||||
{{ range .Data.Pages.ByLength }}
|
||||
@@ -219,7 +228,7 @@ Can be applied to any of the above. Using Date for an example.
|
||||
## Grouping Content
|
||||
|
||||
Hugo provides some grouping functions for list pages. You can use them to
|
||||
group pages by Section, Date etc.
|
||||
group pages by Section, Type, Date etc.
|
||||
|
||||
Here are a variety of different ways you can group the content items in
|
||||
your list templates:
|
||||
@@ -252,6 +261,48 @@ your list templates:
|
||||
</ul>
|
||||
{{ end }}
|
||||
|
||||
### Grouping by Page publish date
|
||||
|
||||
{{ range .Data.Pages.GroupByPublishDate "2006-01" }}
|
||||
<h3>{{ .Key }}</h3>
|
||||
<ul>
|
||||
{{ range .Pages }}
|
||||
<li>
|
||||
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
||||
<div class="meta">{{ .PublishDate.Format "Mon, Jan 2, 2006" }}</div>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
|
||||
### Grouping by Page param
|
||||
|
||||
{{ range .Data.Pages.GroupByParam "param_key" }}
|
||||
<h3>{{ .Key }}</h3>
|
||||
<ul>
|
||||
{{ range .Pages }}
|
||||
<li>
|
||||
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
||||
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
|
||||
### Grouping by Page param in date format
|
||||
|
||||
{{ range .Data.Pages.GroupByParamDate "param_key" "2006-01" }}
|
||||
<h3>{{ .Key }}</h3>
|
||||
<ul>
|
||||
{{ range .Pages }}
|
||||
<li>
|
||||
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
||||
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
|
||||
### Reversing Key Order
|
||||
|
||||
The ordering of the groups is performed by keys in alpha-numeric order (A–Z,
|
||||
|
Reference in New Issue
Block a user