See this code:
{{ $ALL := site.RegularPages }}
{{ $used := first 9 $ALL }}
{{ $collection := (slice )}}
{{ range $ALL}}
{{ $collection = $collection | append (dict "Page" . "Sorter" 100 ) }}
{{ end }}
I’m just using 100 here, but any sortable is fine.
{{ $sorted1 := (slice ) }}
{{ range sort $collection "Sorter" "desc" }}
{{ $sorted1 = $sorted1 | append .Page }}
{{ end }}
{{ union $sorted1 $used }}
Works fine.
{{ union $used $sorted1 }}
Works fine.
{{ $sorted2 := apply (sort $collection "Sorter" "desc") "index" "." "Page" }}
{{ union $sorted2 $used }}
Works fine.
{{ union $used $sorted2 }}
Throws error:
error calling union: reflect.Set: value of type interface {} is not assignable to type page.Page
This seems to have something to do with casting in apply or union.
{{ printf "%v" $sorted1 }}
Prints out a pages collection looking something like…
Pages(123)
{{ printf "%v" $sorted2 }}
Prints out a slice of Page objects, like…
[Page(“filepath1”), Page(“filepath2”)]
It seems that there are two bugs:
-
apply does not return a page collection when it should.
-
union doesn’t handle a slice of Pages correctly (by casting to Pages) when provided as the second argument.