Figure shortcode can specify page for page resource; redo one 2008 post
This commit is contained in:
@@ -8,26 +8,30 @@ Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/
|
||||
{{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="/css/hugo-easy-gallery.css" />{{ end }}
|
||||
{{- $.Page.Scratch.Add "figurecount" 1 -}}
|
||||
|
||||
<!-- Some constants: -->
|
||||
<!-- What page to find images as Page Resources in -->
|
||||
{{ $pagename := "images" }}
|
||||
<!-- if 'resource' is given, look for a page resource by that name. -->
|
||||
<!-- if 'page' is given, find the page resource there. -->
|
||||
<!-- if not, find the page resource in the current page. -->
|
||||
<!-- (yes, my description is probably at least 50% wrong) -->
|
||||
|
||||
<!-- Thumbnail image size/type -->
|
||||
{{ $resize_opts := "600x jpg" }}
|
||||
<!-- TODO: This isn't generating a JPEG on my configuration. Not sure why. -->
|
||||
<!-- TODO: This isn't generating a JPEG on my configuration. Not sure
|
||||
why. Hugo version issue? -->
|
||||
|
||||
<!-- if 'resource' is given, look there in the "images" bundle -->
|
||||
<!-- (yes, my description is probably at least 50% wrong) -->
|
||||
{{ $thumb := "" }}
|
||||
{{ $href := "" }}
|
||||
{{ if .Get "resource" }}
|
||||
{{ $page := $.Site.GetPage $pagename }}
|
||||
{{- if eq $page nil -}}
|
||||
{{- errorf "Error: Can't find page %s" $pagename -}}
|
||||
{{ $page := $.Page }}
|
||||
{{ with .Get "page" }}
|
||||
{{ $page = $.Site.GetPage . }}
|
||||
{{ end }}
|
||||
{{- if not $page -}}
|
||||
{{- errorf "Error: Can't find page %s" (.Get "page") -}}
|
||||
{{- end -}}
|
||||
{{ $resource := (.Get "resource") }}
|
||||
{{ $original := $page.Resources.GetMatch (printf "*%s*" $resource) }}
|
||||
{{- if eq $original nil -}}
|
||||
{{- errorf "Error: Can't find resource %s on page %s" $resource $pagename -}}
|
||||
{{- errorf "Error: Can't find resource %s on page %s" $resource (.Get "page") -}}
|
||||
{{- end -}}
|
||||
{{ .Scratch.Set "image" ($original.Resize $resize_opts) }}
|
||||
{{ $image := .Scratch.Get "image" }}
|
||||
|
||||
Reference in New Issue
Block a user