Skip to content

Instantly share code, notes, and snippets.

@ssube
Last active May 24, 2022 13:55
Show Gist options
  • Save ssube/dbc1005ed312f8dfbbbf8fa66d18d1e4 to your computer and use it in GitHub Desktop.
Save ssube/dbc1005ed312f8dfbbbf8fa66d18d1e4 to your computer and use it in GitHub Desktop.

Revisions

  1. ssube revised this gist May 24, 2022. 3 changed files with 5 additions and 6 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    A basic image gallery shortcode for Hugo, using https://www.lightgalleryjs.com/.

    Image metadata, such as alt text, can be added to the frontmatter using the `gallery` key and filename. If the page contains any `{{< gallery >}}` tags, the param is required, but can be an empty list: `gallery: []`.
    Image metadata, such as alt text, can be added to the frontmatter using the `resources` key and filename: https://gohugo.io/content-management/page-resources/#resources-metadata-example

    The gallery features and transition can be set through the lightgallery plugins and options, please see:

    3 changes: 1 addition & 2 deletions layouts-shortcodes-gallery.html
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,10 @@

    <div id="gallery-{{ $.Get 1 }}" class="gallery-frame">
    {{ range $gallery }}
    {{ $meta := index (where $.Page.Params.gallery "name" .Name) 0 }}
    {{ $resized := .Fit $size }}
    <div class="gallery-item" data-src="{{ .Permalink }}">
    <a class="thumbnail" href="{{ .Permalink }}" data-lightbox="{{ $.Get 1 }}">
    <img src="{{ $resized.Permalink }}" alt="{{ default "no alt text provided" $meta.alt }}" />
    <img src="{{ $resized.Permalink }}" alt="{{ default "no alt text provided" .Title }}" />
    </a>
    </div>
    {{ end }}
    6 changes: 3 additions & 3 deletions post-example-index.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    ---
    title: Example Gallery

    gallery:
    - name: 'img/test.png'
    alt: 'an image full of testing'
    resources:
    - src: 'img/test.png'
    title: 'an image full of testing'
    ---

    Some words.
  2. ssube revised this gist May 19, 2022. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    A basic image gallery shortcode for Hugo, using https://www.lightgalleryjs.com/.

    Image metadata, such as alt text, can be added to the frontmatter using the `gallery` key and filename.
    Image metadata, such as alt text, can be added to the frontmatter using the `gallery` key and filename. If the page contains any `{{< gallery >}}` tags, the param is required, but can be an empty list: `gallery: []`.

    The gallery features and transition can be set through the lightgallery plugins and options, please see:

    2 changes: 1 addition & 1 deletion post-example-index.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,6 @@ gallery:

    Some words.

    {{< gallery "img/*.png" "test" >}}
    {{< gallery "img/*.png" "test" "300x200 q75" >}}

    An image gallery, and some more words.
  3. ssube revised this gist May 19, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion layouts-shortcodes-gallery.html
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,11 @@
    {{ $filter := default "images/*" (.Get 0) }}
    {{ $gallery := (.Page.Resources.Match $filter) }}
    {{ $size := default "200x120 q50" (.Get 2) }}

    <div id="gallery-{{ $.Get 1 }}" class="gallery-frame">
    {{ range $gallery }}
    {{ $meta := index (where $.Page.Params.gallery "name" .Name) 0 }}
    {{ $resized := .Fill "200x120 q50" }}
    {{ $resized := .Fit $size }}
    <div class="gallery-item" data-src="{{ .Permalink }}">
    <a class="thumbnail" href="{{ .Permalink }}" data-lightbox="{{ $.Get 1 }}">
    <img src="{{ $resized.Permalink }}" alt="{{ default "no alt text provided" $meta.alt }}" />
    @@ -15,6 +16,7 @@

    <script type="text/javascript">
    lightGallery(document.getElementById('gallery-{{ $.Get 1 }}'), {
    mode: 'lg-fade',
    plugins: [lgPager, lgZoom],
    selector: '.gallery-item',
    speed: 250,
  4. ssube revised this gist May 19, 2022. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    A basic image gallery shortcode for Hugo, using https://www.lightgalleryjs.com/.

    Image metadata, such as alt text, can be added to the frontmatter using the `gallery` key and filename.

    The gallery features and transition can be set through the lightgallery plugins and options, please see:

    - https://www.lightgalleryjs.com/docs/settings/
    - https://www.lightgalleryjs.com/demos/transitions/
  5. ssube revised this gist May 19, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    A basic image gallery shortcode for Hugo, using https://www.lightgalleryjs.com/.

    Image metadata, such as alt text, can be added to the frontmatter using the `gallery` key and filename.
  6. ssube revised this gist May 19, 2022. No changes.
  7. ssube created this gist May 19, 2022.
    18 changes: 18 additions & 0 deletions layouts-partials-css.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <!-- light gallery -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/2.4.0/css/lightgallery-bundle.min.css" integrity="sha384-dBF8MEM2phKRyLDWAAiv46eog697GrUsdB8kIwEzCgyaIQkCNu08OjhnC8cSZOqh" crossorigin="anonymous" />

    <style>

    .gallery-frame {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;

    padding: 1rem;
    }

    .gallery-item {
    margin: 1rem;
    }

    </style>
    4 changes: 4 additions & 0 deletions layouts-partials-js.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    <!-- light gallery -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/2.4.0/lightgallery.min.js" integrity="sha384-SMXsJkdv0pWRFF7S1lZPUvnBOw2WnTKw88DRxOqLysifuSomt1/jdArjX6c+d8yu" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/2.4.0/plugins/pager/lg-pager.min.js" integrity="sha384-KWUYFmH9+fIKCHDl+8GwbHvmGw3Q4qk0mVB1BBRznlQIZma3czxxpeVQtD71bM64" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/2.4.0/plugins/zoom/lg-zoom.min.js" integrity="sha384-B2e5p5SHlYQtPrvEdMpFrKtwNN5cJgFgKWpZBLdEmgjDjaPKl7bVh0masHqDdHoc" crossorigin="anonymous"></script>
    22 changes: 22 additions & 0 deletions layouts-shortcodes-gallery.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    {{ $filter := default "images/*" (.Get 0) }}
    {{ $gallery := (.Page.Resources.Match $filter) }}

    <div id="gallery-{{ $.Get 1 }}" class="gallery-frame">
    {{ range $gallery }}
    {{ $meta := index (where $.Page.Params.gallery "name" .Name) 0 }}
    {{ $resized := .Fill "200x120 q50" }}
    <div class="gallery-item" data-src="{{ .Permalink }}">
    <a class="thumbnail" href="{{ .Permalink }}" data-lightbox="{{ $.Get 1 }}">
    <img src="{{ $resized.Permalink }}" alt="{{ default "no alt text provided" $meta.alt }}" />
    </a>
    </div>
    {{ end }}
    </div>

    <script type="text/javascript">
    lightGallery(document.getElementById('gallery-{{ $.Get 1 }}'), {
    plugins: [lgPager, lgZoom],
    selector: '.gallery-item',
    speed: 250,
    });
    </script>
    13 changes: 13 additions & 0 deletions post-example-index.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    ---
    title: Example Gallery

    gallery:
    - name: 'img/test.png'
    alt: 'an image full of testing'
    ---

    Some words.

    {{< gallery "img/*.png" "test" >}}

    An image gallery, and some more words.