Skip to content

Instantly share code, notes, and snippets.

@jhalbrecht
Forked from sarmis/foldergallery.html
Last active July 9, 2019 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhalbrecht/0523aa2249a1c8145a05eeb99e65eed9 to your computer and use it in GitHub Desktop.
Save jhalbrecht/0523aa2249a1c8145a05eeb99e65eed9 to your computer and use it in GitHub Desktop.
Justified Image Gallery as Hugo shortcode

Forked and making some changes to better support how I'm using page resources in a Hugo Page bundle.

Usage { {< foldergallery src="imgs" >} } I changed this to;

{ {< foldergallery src="." >} } Which picks up all the files in my leaf page bundle including index.md

I want to change the "imgs" in the shortcode to something like;

{{ with .Resources.ByType "image" }} {{ end }}

Or modify the foldergallery.html

I posted the question; https://discourse.gohugo.io/t/modify-folder-based-gallery-by-thomas-sarmis/19561

<!-- \layouts\shortcodes\foldergallery.html -->
<style>
div.gallery {
display: flex;
flex-wrap: wrap;
}
div.gallery a {
flex-grow: 1;
object-fit: cover;
margin: 2px;
display: flex;
}
div.gallery a img {
height: 200px;
object-fit: cover;
flex-grow: 1;
}
</style>
<div class="gallery">
{{ $path := print "content\\" .Page.Dir (.Get "src") }}
{{ $url := print .Page.URL (.Get "src") }}
{{ range (readDir $path) }}
{{ $src := print $url "/" .Name }}
<a data-fancybox="gallery" href="{{ $src }}">
<img src="{{ $src }}"> <br/>
</a>
{{ end }}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment