Skip to content

Commit

Permalink
feat: add the collection _weight parameter for sorting (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang authored Jan 24, 2024
1 parent d2a0a1c commit 7db2bd1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions layouts/partials/decap-cms/functions/format.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{{/* Format the configurations:
1. Remove internal used parameters.
2. Trasnlate labels.
3. Sort collections.
*/}}
{{- $config := . }}
{{- $collections := default slice ($config.Get "collections") }}
{{- $sortedCollections := sort (default slice (where $collections "_weight" "ne" nil)) "_weight" }}
{{- $unsortedCollections := sort (default slice (where $collections "_weight" nil)) "name" }}
{{- $collections = $sortedCollections | append $unsortedCollections }}
{{- $config.Set "collections" slice }}
{{- range $collections }}
{{- $tmp := newScratch }}
Expand Down Expand Up @@ -49,3 +53,4 @@
{{- end }}
{{- $config.Add "collections" (slice ($tmp.Get "c")) }}
{{- end }}
{{- $config.Set "collections" $collections }}

0 comments on commit 7db2bd1

Please sign in to comment.