From 43e5f5971006d59b58f81879cdc01dd9bbda03e7 Mon Sep 17 00:00:00 2001 From: Derek Severin Date: Sun, 10 Feb 2019 17:53:06 +0700 Subject: Image gallery: Added caption & copyright handling --- layouts/_default/single.html | 4 +++- layouts/partials/gallery.html | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/layouts/_default/single.html b/layouts/_default/single.html index b4d3641..7fa2910 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -44,7 +44,9 @@ */}} {{ $images_directory := .Params.images_directory | default "images" }} {{ $images_static := .Params.images_static | default "false" }} - {{ partial "gallery.html" (dict "page" . "dir" $images_directory "static" $images_static) }} + {{ $images_copyright := .Params.images_copyright }} + {{ $images_params := .Params.images }} + {{ partial "gallery.html" (dict "page" . "dir" $images_directory "static" $images_static "images_params" $images_params "images_copyright" $images_copyright) }} {{ partial "load-photoswipe.html" (dict "page" .) }} {{ end }} diff --git a/layouts/partials/gallery.html b/layouts/partials/gallery.html index ca77ac0..e8f2084 100644 --- a/layouts/partials/gallery.html +++ b/layouts/partials/gallery.html @@ -13,6 +13,17 @@ Input Parameters: - "thumb": String (suffix) - $.Get "thumb" => $.thumb (if defined, else "-thumb" by default) +(TODO: detail/document...) +- "images_copyright" +("MULTITEL") +- images: + - "src" +("1.png") + - "title" +("Plan") + - "copyright" +(...) + TODO: - .Get "caption-position" default "bottom" @@ -47,7 +58,7 @@ Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/ {{- end -}} {{- $dir := $.page.Scratch.Get "dirURL" }} {{- $dirFiles := $.page.Scratch.Get "dirFiles" }} - {{ if (fileExists $dirFiles) -}} + {{- if (fileExists $dirFiles) -}} {{- $files := readDir $dirFiles }} {{- range $files -}} @@ -56,7 +67,28 @@ Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/ {{- $isthumb := .Name | findRE ($thumbext | printf "%s\\.") }} {{- $isimg := lower .Name | findRE "\\.(gif|jpg|jpeg|tiff|png|bmp)" }} {{- if and $isimg (not $isthumb) }} - {{- $caption := .Name | replaceRE "\\..*" "" | humanize }} + {{ $name := .Name }} + {{ with $.images_copyright }} + {{ $.page.Scratch.Set "copyright" (print " - © " .) }} + {{ end }} + + {{ range $.images_params }} + {{ if eq .src $name }} + {{ with .title }} + {{ $.page.Scratch.Set "title" . }} + {{ end }} + {{ with .copyright }} + {{ $.page.Scratch.Set "copyright" (print " - © " .) }} + {{ end }} + {{ end }} + {{ end }} + + {{- $title := ($.page.Scratch.Get "title") | default (.Name | replaceRE "\\..*" "") }} + {{- $copyright := ($.page.Scratch.Get "copyright") | default "" }} + + {{- $captionthumb := $title }} + {{- $caption := (print $title $copyright) }} + {{- $linkURL := print $baseURL $dir "/" .Name | absURL }} {{- $thumb := .Name | replaceRE "(\\.)" ($thumbext | printf "%s.") }} {{- $thumbexists := where $files "Name" $thumb }} @@ -67,17 +99,18 @@ Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/ {{ $caption }}
-

{{ $caption }}

+

{{ $captionthumb }}

+ {{ $.page.Scratch.Delete "title" }} + {{ $.page.Scratch.Delete "copyright" }} {{- end }} {{- end }} {{- end }} {{ $.page.Scratch.Delete "dirURL" }} {{ $.page.Scratch.Delete "dirFiles" }} - {{- else -}} {{/* TODO: Need to change the "figure" shortcode to a partial. -- cgit v1.2.3