4o1x5.dev/layouts/partials/utils/sort-pages.html

33 lines
907 B
HTML
Raw Normal View History

2024-04-28 11:42:37 +02:00
{{- $page := .page -}}
{{- $by := .by | default "weight" -}}
{{- $order := .order | default "asc" -}}
{{- $pages := slice }}
{{- if eq $by "weight" }}
{{- $pages = $page.Pages.ByWeight }}
{{- else if eq $by "date" }}
{{- $pages = $page.Pages.ByDate }}
{{- else if eq $by "title" }}
{{- $pages = $page.Pages.ByTitle }}
{{- else if eq $by "expiryDate" }}
{{- $pages = $page.Pages.ByExpiryDate }}
{{- else if eq $by "publishDate" }}
{{- $pages = $page.Pages.ByPublishDate }}
{{- else if eq $by "lastmod" }}
{{- $pages = $page.Pages.ByLastmod }}
{{- else if eq $by "linkTitle" }}
{{- $pages = $page.Pages.ByLinkTitle }}
{{- else if eq $by "length" }}
{{- $pages = $page.Pages.ByLength }}
{{- else }}
{{- warnf "sort-pages: unknown sort field %q" $by -}}
{{- $pages = $page.Pages }}
{{ end -}}
{{- if eq $order "desc" }}
{{- $pages = $pages.Reverse }}
{{- end -}}
{{- return $pages -}}