liwenyip / hugo-easy-gallery

Automagical css image gallery in Hugo using shortcodes, with optional lightbox/carousel gadget using PhotoSwipe and jQuery.
MIT License
576 stars 111 forks source link

Images in subfolders #12

Closed iammatthias closed 6 years ago

iammatthias commented 7 years ago

Is it possible to create a "master gallery" of all images in subfolders? I'd like to have one gallery that includes everything, and then multiple sub-galleries.

My images are organized within the img folder like so:

- img
-- people
-- places
-- events

Is there a way to target all of those at once with the Gallery shortcode? Something like {{< gallery dir="/img/**/**/" />}} {{< load-photoswipe >}}?

Edit: I am using the Victor-Hugo boilerplate, if that has anything to do with it.

Folder structure is:

|--site                // Everything in here will be built with hugo
|  |--content          // Pages and collections - ask if you need extra pages
|  |--data             // YAML data files with any data for use in examples
|  |--layouts          // This is where all templates go
|  |  |--partials      // This is where includes live
|  |  |--index.html    // The index page
|  |--static           // Files in here ends up in the public folder
|--src                 // Files that will pass through the asset pipeline
|  |--css              // CSS files in the root of this folder will end up in /css/...
|  |--js               // app.js will be compiled to /app.js with babel

All static assets are in /static/img/ which builds to ./img/

Master gallery example (not working): https://staging.iammatthias.com/gal/ Individual gallery example (working): https://staging.iammatthias.com/gal/flatframe

iammatthias commented 7 years ago

Away from my personal computer at the moment, so I haven't been able to test this yet. Is this functionality that could be achieved with the Hugo 'Delimit' function?

~~+++ title: Delimit galleries

gal: [ "gal1", "gal2", "gal3" ]

+++~~

Then use {{< gallery dir="/img/{{ delimit .Params.gal }}" />}} {{< load-photoswipe >}}?

Edit: didn't work. At a loss for this.

iammatthias commented 7 years ago

Tried modifying the Gallery shortcode, but it either loads a blank page, or causes an error when building.

Any advice? Would really love to get the galleries working soon.

liwenyip commented 6 years ago

You need to do something like:

    {{- with (.Get "dir") -}}
        <!-- If a directory was specified, generate figures for all of the images in the directory -->
        {{- $subdirs := readDir (print "/static/" .) }} <!-- new line of code -->
        {{- range $subdirs }} <!-- new line of code -->
            {{- $files := readDir . }} <!-- modified line of code -->
            {{- range $files -}}

Don't forget to add a {{- end }} to close off the range function.