kc0bfv / autophugo

AutoPhugo [ˌɔtoʊˈfjuːgəʊ] is a gallery/photoblog theme for Hugo that's a little more automatic than Phugo.
Other
97 stars 56 forks source link

Feature sort by weight #28

Closed githubmonkey closed 2 years ago

githubmonkey commented 2 years ago

Another small change for your consideration.

This feature does not change the default behavior but will allow those of us who want to tinker with the sort order to do so.

Some use cases:

kc0bfv commented 2 years ago

So - I was thinking there's gotta be a way to do this without needing an extra param - if the user specifies a weight then sort would happen by weight with non-specified weights defaulting to 0. Specifying the weight becomes the signal that a user opts-in to the feature. I adapted the same sort you did for images to the sections and sorted by date first, then weight afterwards. Fortunately Hugo keeps equal-weights in the same order they were before running sort (stable algorithm I guess).

I think - now if users add weights then the images will be sorted by them, with all unspecified weights defaulting to 0 and those being sorted by date/filename. So - users opt into using this feature simply by adding weights. I think that's awesome and simple - I hope...

I changed the cat album demo to illustrate this sorting feature. cat_01 is normally the first image in the album, but weight is set to 1 and it gets sorted last (grass cat). cat_03 is normally third in the album, but weight is -1 so it gets sorted first. cat_02 and cat_04 have no weights and they are in the middle in order of filename.

I changed the base album directory demo to illustrate it too for albums/subalbums. I rejiggered the dates around so that the order doesn't change when I reupload the demo - but "many_simple" should be first by date, and the weight is set to 1 so it still is last. cats should be next by date, but weight isn't specified so it's after dogs which has weight -1. fish has the latest date but is third because weight is unspecified and therefore 0.

I left weights in the archetype for images regardless - I figured the images will get their default weight set matching their filename order. That's probably the easier workflow then for folks who want to reorder things... If all images had weight 0 there'd be no way to reorder images in between others easily. With how you have it - it's easy.

kc0bfv commented 2 years ago

On main now.