Skip to content

Instantly share code, notes, and snippets.

@ulfklose
Forked from marksteele/foldergallery.html
Created October 24, 2019 21:29
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 ulfklose/1422e16e6f0216247b320851a8f2f65c to your computer and use it in GitHub Desktop.
Save ulfklose/1422e16e6f0216247b320851a8f2f65c to your computer and use it in GitHub Desktop.
<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>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.4.0/jquery.fancybox.min.css" />
<div class="gallery">
{{ $base := .Get "src" }}
{{ $path := print "static/" (.Get "src") }}
{{ range (readDir $path) }}
{{- $thumbext := "-thumb" }}
{{- $isthumb := .Name | findRE ($thumbext | printf "%s\\.") }}<!-- is the current file a thumbnail image? -->
{{- $isimg := lower .Name | findRE "\\.(gif|jpg|jpeg|tiff|png|bmp)" }}<!-- is the current file an image? -->
{{- if and $isimg (not $isthumb) }}
{{- $thumb := .Name | replaceRE "(\\.)" ($thumbext | printf "%s.") }}
<a data-fancybox="gallery" href="/{{ $base }}/{{ .Name }}">
<img src="/{{ $base }}/{{ $thumb }}"> <br/>
</a>
{{- end }}
{{ end }}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment