Created
July 17, 2021 02:04
-
-
Save jan-martinek/24850f77d0c8954943946ded70d9c87f to your computer and use it in GitHub Desktop.
Workaround for Hugo: sorting pages by Czech alphabet (first 40 alpha chars)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ $page := .Page }} | |
{{ range .pages }} | |
{{ $alpha := "aábcčdďeéěfgh#iíjklmnňoópqrřsštťuúůvwxyýzž" }} | |
{{ $title := substr (.Title | lower | replaceRE "ch" "#" | replaceRE (print "[^" $alpha "]") "") 0 40 }} | |
{{ $sortStr := split $title "" }} | |
{{ $len := len $sortStr }} | |
{{ $score := math.Pow 100 42 }} | |
{{ range $index, $char := $sortStr }} | |
{{/* calc character rank */}} | |
{{ $num := len (index (findRE (print "^.*" $char) $alpha) 0) }} | |
{{/* calc score */}} | |
{{ $score = add $score (mul $num (math.Pow 100 (sub 40 $index))) }} | |
{{ end }} | |
{{ $sortKey := print (lang.NumFmt 0 $score "- .") $title }} | |
{{ $page.Scratch.SetInMap "pages" $sortKey (dict "Title" .Title "Permalink" .Permalink "Params" .Params) }} | |
{{ end }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment