Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/2-REC/hugo-myportfolio-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'layouts/partials/gallery.html')
-rw-r--r--layouts/partials/gallery.html84
1 files changed, 84 insertions, 0 deletions
diff --git a/layouts/partials/gallery.html b/layouts/partials/gallery.html
new file mode 100644
index 0000000..72e11d2
--- /dev/null
+++ b/layouts/partials/gallery.html
@@ -0,0 +1,84 @@
+<!--
+Input Parameters:
+- Mandatory:
+ - "page": Page
+ - $.Page.Scratch => $.page.Scratch
+ - .Site.BaseURL => $.page.Site.BaseURL
+ - $.Page.Dir => $.page.Dir
+- Optional:
+ - "dir": String (directory)
+ - .Get "dir" => $.dir (if defined, else using ".Inner")
+ - "static": Boolean
+ - $.Get "static" => $.static (if defined, else "false" by default)
+ - "thumb": String (suffix)
+ - $.Get "thumb" => $.thumb (if defined, else "-thumb" by default)
+
+TODO:
+- .Get "caption-position"
+ default "bottom"
+- .Get "caption-effect"
+ default "slide"
+- .Get "hover-effect"
+ default "zoom"
+- .Get "hover-transition"
+
++captions...
+(& copyrights, etc.)
+-->
+
+<!--
+Put this file in /layouts/shortcodes/gallery.html
+Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/
+-->
+<!-- count how many times we've called this shortcode; load the css if it's the first time -->
+{{- if not (.page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="/css/hugo-easy-gallery.css" />{{ end }}
+{{- .page.Scratch.Add "figurecount" 1 }}
+{{ $baseURL := .page.Site.BaseURL }}
+<div class="gallery caption-position-{{ with .caption_position | default "bottom" }}{{.}}{{end}} caption-effect-{{ with .caption_effect | default "slide" }}{{.}}{{end}} hover-effect-{{ with .hover_effect | default "zoom" }}{{.}}{{end}} {{ if ne (.hover_transition) "none" }}hover-transition{{end}}" itemscope itemtype="http://schema.org/ImageGallery">
+ {{- with .dir -}}
+ <!-- If a directory was specified, generate figures for all of the images in the directory -->
+ {{- if eq $.static "true" -}}
+ {{ $.page.Scratch.Set "dirURL" (print .) }}
+ {{ $.page.Scratch.Set "dirFiles" (print "/static/" .) }}
+ {{- else -}}
+ {{- $tmpDir := print (replace $.page.Dir "\\" "/") "/" . }}
+ {{ $.page.Scratch.Set "dirURL" $tmpDir }}
+ {{ $.page.Scratch.Set "dirFiles" (print "/content/" $tmpDir "/") }}
+ {{- end -}}
+ {{- $dir := $.page.Scratch.Get "dirURL" }}
+ {{ if (fileExists $dir) -}}
+ {{- $files := readDir ($.page.Scratch.Get "dirFiles" ) }}
+
+ {{- range $files -}}
+ <!-- skip files that aren't images, or that inlcude the thumb suffix in their name -->
+ {{- $thumbext := $.thumb | default "-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) }}
+ {{- $caption := .Name | replaceRE "\\..*" "" | humanize }}<!-- humanized filename without extension -->
+ {{- $linkURL := print $baseURL $dir "/" .Name | absURL }}<!-- absolute URL to hi-res image -->
+ {{- $thumb := .Name | replaceRE "(\\.)" ($thumbext | printf "%s.") }}<!-- filename of thumbnail image -->
+ {{- $thumbexists := where $files "Name" $thumb }}<!-- does a thumbnail image exist? -->
+ {{- $thumbURL := print $baseURL $dir "/" $thumb | absURL }}<!-- absolute URL to thumbnail image -->
+ <div class="box">
+ <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
+ <div class="img" style="background-image: url('{{ if $thumbexists }}{{ $thumbURL }}{{ else }}{{ $linkURL }}{{ end }}');" >
+ <img itemprop="thumbnail" src="{{ if $thumbexists }}{{ $thumbURL }}{{ else }}{{ $linkURL }}{{ end }}" alt="{{ $caption }}" /><!-- <img> hidden if in .gallery -->
+ </div>
+ <figcaption>
+ <p>{{ $caption }}</p>
+ </figcaption>
+ <a href="{{ $linkURL }}" itemprop="contentUrl"></a><!-- put <a> last so it is stacked on top -->
+ </figure>
+ </div>
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ {{ $.page.Scratch.Delete "dirURL" }}
+ {{ $.page.Scratch.Delete "dirFiles" }}
+
+ {{- else -}}
+ <!-- If no directory was specified, include any figure shortcodes called within the gallery -->
+ {{ .Inner }}
+ {{- end }}
+</div>