mfg92/hugo-shortcode-gallery

ER: Manual sort order

Opened this issue · 3 comments

This plugin looks great. I'd like to migrate from https://github.com/liwenyip/hugo-easy-gallery/ but the missing feature for me is the ability to specify a custom image order without relying on file naming.

mfg92 commented

One solution for your issue would be to implement sorting by any value found in exif or in the sidecar file (https://github.com/mfg92/hugo-shortcode-gallery#sidecar-files). Then one could add a value order to the sidecar file and use that for sorting.

I wanted to get the images sorted by EXIF Date order, so changed the layouts/shortcode/gallery.html file (line 89) from:

{{ range $original := sort $images "Name" $sortOrder}}

to :

{{ range $original := sort $images "Exif.Date" $sortOrder}}

which failed when it hit the .meta files as they had no EXIF data (as the test for the file being an image is done after the list is read via range). Moving all metadata files into a subdir within images (ie: images/meta) and updating the path to read the metadata from (line 93):

{{ $metaFileName := print "meta/" $original.Name ".meta"}}

does allow the image list to be built with the correct order, and with the metadata merged as expected when viewing the final index.html file source code, but for some reason it doesn't load the images when viewing in my browser.

My hugo skills are around 24hrs old, so I will keep working on this, but wanted to offer up this partial solution for discussion. If it's heading in the right direction then then fix for the user-facing sort aspect may be as simple as placing the current "Name" into a variable, and then it can be swapped directly for Exif.Date or any other built-in function.

Right: images sorted by EXIF Date do work - I had my meta path incorrect, and for the code fragment above it should look like this:

gallery
├── images
│   ├── image001.jpg
│   ├── image002.jpg
│   └── image003.jpg
├── index.md
└── meta
    └── images
        ├── image001.jpg.meta
        ├── image002.jpg.meta
        └── image003.jpg.meta

Obviously, that sucks as a layout !

An interesting side note: the 'vanishing' images were down to me having the filterOptions declared, but the metadata not being scanned: in this case the images flashed up and then vanished, with just the filter buttons in view.

I'm not sure if that's something worth noting, or if it falls into the "if you do bad things, other bad things happen", but it may be worth having an FAQ/Debug entry saying that if the images don't appear, remove the filterOptions and see if they come back again.