Try to fix broken thumbnail URLs

This commit is contained in:
Chris Hodapp 2020-04-27 13:23:58 -04:00
parent d12056092a
commit dc951d1590

View File

@ -5,7 +5,7 @@ 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 --> <!-- 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 }} {{- if not ($.Page.Scratch.Get "figurecount") -}}<link rel="stylesheet" href="/css/hugo-easy-gallery.css" />{{- end -}}
{{- $.Page.Scratch.Add "figurecount" 1 -}} {{- $.Page.Scratch.Add "figurecount" 1 -}}
<!-- if 'resource' is given, look for a page resource by that name. --> <!-- if 'resource' is given, look for a page resource by that name. -->
@ -14,52 +14,51 @@ Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/
<!-- (yes, my description is probably at least 50% wrong) --> <!-- (yes, my description is probably at least 50% wrong) -->
<!-- Thumbnail image size/type --> <!-- Thumbnail image size/type -->
{{ $resize_opts := "600x jpg" }} {{- $resize_opts := "600x jpg" -}}
<!-- TODO: This isn't generating a JPEG on my configuration. Not sure <!-- TODO: This isn't generating a JPEG on my configuration. Not sure
why. Hugo version issue? --> why. Hugo version issue? -->
{{- $thumb := "" -}}
{{ $thumb := "" }} {{- $href := "" -}}
{{ $href := "" }} {{- if .Get "resource" -}}
{{ if .Get "resource" }} {{- $page := $.Page -}}
{{ $page := $.Page }} {{- with .Get "page" -}}
{{ with .Get "page" }} {{- $page = $.Site.GetPage . -}}
{{ $page = $.Site.GetPage . }} {{- end -}}
{{ end }}
{{- if not $page -}} {{- if not $page -}}
{{- errorf "Error: Can't find page %s" (.Get "page") -}} {{- errorf "Error: Can't find page %s" (.Get "page") -}}
{{- end -}} {{- end -}}
{{ $resource := (.Get "resource") }} {{- $resource := (.Get "resource") -}}
{{ $original := $page.Resources.GetMatch (printf "*%s*" $resource) }} {{- $original := $page.Resources.GetMatch (printf "*%s*" $resource) -}}
{{- if eq $original nil -}} {{- if eq $original nil -}}
{{- errorf "Error: Can't find resource %s on page %s" $resource (.Get "page") -}} {{- errorf "Error: Can't find resource %s on page %s" $resource (.Get "page") -}}
{{- end -}} {{- end -}}
{{ .Scratch.Set "image" ($original.Resize $resize_opts) }} {{- .Scratch.Set "image" ($original.Resize $resize_opts) -}}
{{ $image := .Scratch.Get "image" }} {{- $image := .Scratch.Get "image" -}}
{{- $thumb = $image.RelPermalink }} {{- $thumb = $image.RelPermalink -}}
{{- $href = $original.RelPermalink }} {{- $href = $original.RelPermalink -}}
{{ else }} {{- else -}}
<!-- use either src or link-thumb for thumbnail image --> <!-- use either src or link-thumb for thumbnail image -->
{{- $thumb = .Get "src" | default (printf "%s." (.Get "thumb") | replace (.Get "link") ".") }} {{- $thumb = .Get "src" | default (printf "%s." (.Get "thumb") | replace (.Get "link") ".") -}}
{{- $href = .Get "link" | default (.Get "src") }} {{- $href = .Get "link" | default (.Get "src") -}}
{{ end }} {{- end -}}
<div class="box{{ with .Get "caption-position" }} fancy-figure caption-position-{{.}}{{end}}{{ with .Get "caption-effect" }} caption-effect-{{.}}{{end}}" {{ with .Get "width" }}style="max-width:{{.}}"{{end}}> <div class="box{{ with .Get "caption-position" }} fancy-figure caption-position-{{.}}{{end}}{{ with .Get "caption-effect" }} caption-effect-{{.}}{{end}}" {{ with .Get "width" }}style="max-width:{{.}}"{{end}}>
<figure {{ with .Get "class" }}class="{{.}}"{{ end }} itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject"> <figure {{ with .Get "class" }}class="{{.}}"{{ end }} itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<div class="img"{{ if .Parent }} style="background-image: url('{{ $thumb | relURL }}');"{{ end }}{{ with .Get "size" }} data-size="{{.}}"{{ end }}> <div class="img"{{ if .Parent }} style="background-image: url('{{ $thumb }}');"{{ end }}{{ with .Get "size" }} data-size="{{.}}"{{ end }}>
<img itemprop="thumbnail" src="{{ $thumb | relURL }}" {{ with .Get "alt" | default (.Get "caption" | markdownify) }}alt="{{.}}"{{ end }}/><!-- <img> hidden if in .gallery --> <img itemprop="thumbnail" src="{{ $thumb }}" {{ with .Get "alt" | default (.Get "caption" | markdownify) }}alt="{{.}}"{{ end }}/><!-- <img> hidden if in .gallery -->
</div> </div>
<a href="{{ $href }}" itemprop="contentUrl"></a> <a href="{{ $href }}" itemprop="contentUrl"></a>
{{- if or (or (.Get "title") (.Get "caption" | markdownify)) (.Get "attr")}} {{- if or (or (.Get "title") (.Get "caption" | markdownify)) (.Get "attr") -}}
<figcaption> <figcaption>
{{- with .Get "title" }}<h4>{{.}}</h4>{{ end }} {{- with .Get "title" -}}<h4>{{.}}</h4>{{ end }}
{{- if or (.Get "caption" | markdownify) (.Get "attr")}} {{- if or (.Get "caption" | markdownify) (.Get "attr")}}
<p> <p>
{{- .Get "caption" -}} {{- .Get "caption" -}}
{{- with .Get "attrlink"}}<a href="{{.}}">{{ .Get "attr" }}</a>{{ else }}{{ .Get "attr"}}{{ end -}} {{- with .Get "attrlink"}}<a href="{{.}}">{{ .Get "attr" }}</a>{{ else }}{{ .Get "attr"}}{{ end -}}
</p> </p>
{{- end }} {{- end -}}
</figcaption> </figcaption>
{{- end }} {{- end -}}
</figure> </figure>
</div> </div>