Skip to content

Instantly share code, notes, and snippets.

@NSBum
Last active January 1, 2025 19:02
Show Gist options
  • Select an option

  • Save NSBum/56a3779ee62793a3597f9aa2e29ec47c to your computer and use it in GitHub Desktop.

Select an option

Save NSBum/56a3779ee62793a3597f9aa2e29ec47c to your computer and use it in GitHub Desktop.
Adaptation of this fancybox-based folder gallery: https://greekdeveloper.com/2018/folder-based-gallery-for-hugo/
<!-- /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 "static/img/" (.Get "src") }}
{{ $url := print (.Get "src") }}
{{ range (readDir $path) }}
{{ $src := print "/img" "/" $url "/" .Name }}
{{/*
troubleshoot the $src variable as needed
<!-- <p>{{ $src }}</p> -->
*/}}
<a data-fancybox="gallery" href="{{ $src }}">
<img src="{{ $src }}"> <br/>
</a>
{{ end }}
</div>
@warnotte
Copy link
Copy Markdown

warnotte commented Jan 1, 2025

Usefull, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment