Output list in multiple sort versions

Does Hugo supports the ability to publish a list in multiple sort variants?

I am working on a project in which I want to give the visitor the opportunity to sort a list of articles by title or last changed.

Ideally I would like to indicate in the font matter how I want the content sorted

---
title: My list page
url: mylist
sortOutput: [ByWeight,ByDate,ByLastmod]
---

I then expect to get the following urls

/mylist/ (sort by weight)
/mylist/bydate/ (sort by date)
/mylist/bylastmod/ (sort by last modified)

With the help of a little javascript you can then easily create a dropdown so that the user has the choice to sort the articles on the list page.

The way I would do what you need would be to create templates for:

/mylist/ (sort pages by weight)
/bydate/ (sort pages by date)
/bylastmod/ (sort pages by last modified)

In the above templates pages would be rendered by checking for the existence of the respective value of the sortOutput parameter, e.g. {{ if in .Params.sortOutput "ByDate" }} etc.

Then add the respective content files for

/mylist/ (a simple _index.md)
/mylist/bydate/ (an _index.md with a layout parameter to call the bydate template)
/mylist/bylastmod (same as above with a paramter to call the bylastmod template)

That would be a nice solution when we are talking about a single list. I think it would be a little cumbersome to apply this to multiple categories and subcategories.

image

Conceptually, I’m coming up with:

  1. Output a list page as both HTML and JSON with a default sort order.
  2. When the user visits the list page they see the default sort order, and a UI element to modify the sort order.
  3. Use JavaScript to detect the sort order change request, sort the JSON accordingly, then replace the contents of the containing DOM element (assumes no pagination).

The JSON would have to contain HTML (at least for the summary), which can be a hassle. You’d have to handle pagination within the JavaScript as well (a bigger hassle).