Note how there is only a single reference to .Data.Pages, and the value returned by the where call is passed to the sort function as the first argument.
This seems like a bug to me… Paginate should really accept a []*hugolib.Page. It would be great if you could file that. If you have a minute it would be great if you could file it.
In the meantime, you can get around it with something like this:
{{ $uselessPaginator := .Paginate .Data.Pages }}
{{ range $page := last $uselessPaginator.NumberOfElements (first (sub (mul $uselessPaginator.PageNumber $uselessPaginator.PageSize) 1) $pages) }}
Do stuff here
{{ end }}
The idea is that you create a paginator just to get Hugo to generate the pages, but instead of actually using it to output data you use your own array ($pages can be whatever you want), sorted however you please. It’s a bit of a hack, but not too bad.