Arbitrary sorting based on weight parameter

I often need (want) to arbitrary sort (and re-sort) content pages (and the order they appear in, in menus). The only way I know to do this is by opening all of the pages for a specific content type and manually edit the weight parameter in the front matter of the Markdown file. This is a tedious process when you have lots of content files.

Ideally, I’d like to use a ‘drag and drop’ interface for this (web based, probably) that lists all pages and writes the updated weight parameter directly to the file, based on the visual order. I could go and build that in Node.js or something. It would be a fun little project, but perhaps there’s an easier way, or someone has already built this. Or maybe Hugo has an easier way to do this that I don’t know yet.

Any ideas?

In Hugo there is the shuffle function, that can be used with range to display content in a random order whenever the site is generated.

Thanks. I realise I haven’t made myself clear :slight_smile: I said ‘arbitrary’, but what I really mean is that I want to manually change the order. Not randomized, but however I want it.

(The shuffle function might come in handy as well, for other things;)

I ended up finding a solution to that problem, but it only works if you manage your content in Org mode instead of Markdown.

In Org, if I create 5 posts like this:

* Auto post-weight calculation                                       :auto:
:PROPERTIES:
:EXPORT_HUGO_WEIGHT: auto
:END:
** Post with auto weight calc 1 (EXPORT_HUGO_WEIGHT as subtree property)
:PROPERTIES:
:EXPORT_FILE_NAME: hugo-post-weight-1
:END:
** Post with auto weight calc 2 (EXPORT_HUGO_WEIGHT as subtree property)
:PROPERTIES:
:EXPORT_FILE_NAME: hugo-post-weight-2
:END:
** Post with auto weight calc 3 (EXPORT_HUGO_WEIGHT as subtree property)
:PROPERTIES:
:EXPORT_FILE_NAME: hugo-post-weight-3
:END:
** Post with auto weight calc 4 (EXPORT_HUGO_WEIGHT as subtree property)
:PROPERTIES:
:EXPORT_FILE_NAME: hugo-post-weight-4
:END:
** Post with auto weight calc 5 (EXPORT_HUGO_WEIGHT as subtree property)
:PROPERTIES:
:EXPORT_FILE_NAME: hugo-post-weight-5
:END:

they export from Org to Markdown as 1, 2, 3, 4, 5.

Note that they got their weights 4001, 4002, etc. based on a little formula that uses the depth and mutual order of those posts. If I were to swap the order of hugo-post-weight-1 and hugo-post-weight-2 posts (in Org, you do that by just hitting the Alt+up or Alt+down key), hugo-post-weight-1 would now get a weight of 4002 instead of 4001.

These are test posts that test this auto weight assignment feature of my ox-hugo package.

Even if you don’t use Org, I believe you can port this logic to a perl/sed/etc. script based solution, that probably uses the alphabetical sorting of files to derive an auto-weight.


… and similar for auto assignment of taxonomy weights too: t1, t2.