Skip to content

Instantly share code, notes, and snippets.

@marksteele
Created February 10, 2019 02:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marksteele/38aa7ce30608da6c5182527105e79b0e to your computer and use it in GitHub Desktop.
Save marksteele/38aa7ce30608da6c5182527105e79b0e 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