ggreer / jekyll-gallery-generator

A Jekyll plugin that generates photo galleries from directories full of images.
Apache License 2.0
367 stars 68 forks source link

Feature: include a gallery on a page using Liquid Includes #33

Open nathanbirrell opened 7 years ago

nathanbirrell commented 7 years ago

See my fork of this repo for a working example of this: https://github.com/nathanbirrell/jekyll-gallery-generator

Essentially it enables you to include a specific gallery on any page using a tag, for example: {% gallery my-gallery %}.

(My repo also includes a few other bits of refactoring that can be used or ignored.)

gertoe commented 4 years ago

See my fork of this repo for a working example of this: https://github.com/nathanbirrell/jekyll-gallery-generator

Essentially it enables you to include a specific gallery on any page using a tag, for example: {% gallery my-gallery %}.

(My repo also includes a few other bits of refactoring that can be used or ignored.)

This feature is quite useful but is, currently, hard to merge and changes the gallery generator behaviour too much, I suppose. Furthermore, I have unsuccessfully been trying to make your changes work with recent gallery-generator releases since last year.

However, it is already possible to include a specific gallery using a kind-of hacky workaround for which I would like to propose a drop of the auto-capitalisation of the gallery names. The latter makes it harder to determine the correct gallery name.

My workaround is based on the answer originally posted by @Sanyen in issue https://github.com/ggreer/jekyll-gallery-generator/issues/41#issuecomment-449875605. The requested gallery (test album in the example below) is determined from the galleries found on all (gallery) pages jekyll may build. This solution is not the most performant one due to the determination procedure, but it works sufficiently well, at least for my purposes; we are not building the next global multimedia platform with the the help of Jekyll, aren't we?

Notwithstanding this, hidden galleries cannot be found/included this way!

A better approach might still be to store the galleries in a dictionary or something similar which can be accessed by the liquid includes directly.

To handle special characters (as well as whitespaces if not replaced by the gallery generator), the url_encode.rb plugin may be used.

Maybe, it is possible to create a wrapper for the snippet to include a gallery using a single Liquid macro only.

{% for p in site.pages %}
  {% for gallery in p.galleries %}
  <div class="gallery">
    {% if gallery['gallery'] == "test album" %}
      {% for image in gallery.images %}
      <div class="gallery-image-wrapper">
        <a name="{{ image.name }}"></a>

        <!-- link correct gallery folder/image:
          site.gallery.dir   -> dir of galleries
          gallery['gallery'] -> directory of gallery requested (see above), "gallery name"
          Do so for the thumbnail, respectively...
        -->
        <a href="{{ site.gallery.dir }}/{{ gallery['gallery'] }}/{{ image.src }}">
          <img class="gallery-image" src="{{ site.gallery.dir }}/{{ gallery['gallery'] }}/thumbs/{{ image.src }}" />
        </a>
      </div>
      {% endfor %}
    {% endif %}
  </div>
  {% endfor %}
{% endfor %}