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

github.com/budparr/gohugo-theme-ananke.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRegis Philibert <login@regisphilibert.com>2021-12-23 23:45:27 +0300
committerGitHub <noreply@github.com>2021-12-23 23:45:27 +0300
commit1f11fbe012c8def45b5b9dfa9f6ad4f56b831a97 (patch)
treec94ec6256a51d63bfcc9b5e019205dddbee4f9d8 /layouts
parent3b30dfbac339546d9ae6cd185217699f2044b360 (diff)
Featured image detection refactoring: (#462)
We look for .Params.featured_image If found > we use that as URL If we find a Page resource matching the value of the above, we use its .RelPermalink If none of the above we look for an resource whose filepath contains `featured` or `cover` and use its .RelPermalink if found Fixes #233 Fixes #407
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/func/GetFeaturedImage.html34
1 files changed, 19 insertions, 15 deletions
diff --git a/layouts/partials/func/GetFeaturedImage.html b/layouts/partials/func/GetFeaturedImage.html
index a6219c7..12ffe1c 100644
--- a/layouts/partials/func/GetFeaturedImage.html
+++ b/layouts/partials/func/GetFeaturedImage.html
@@ -1,33 +1,37 @@
{{/*
- GetFeaturedImage
+ GetFeaturedImage
- This partial gets the url for featured image for a given page.
+ This partial gets the url for featured image for a given page.
- If a featured_image was set in the page's front matter, then that will be used.
+ If a featured_image was set in the page's front matter, then that will be used.
- If not set, this will search page resources to find an image that contains the word
- "cover", and if found, returns the path to that resource.
+ If not set, this will search page resources to find an image that contains the word
+ "cover", and if found, returns the path to that resource.
- If no featured_image was set, and there's no "cover" image in page resources, then
- this partial returns an empty string (which evaluates to false).
+ If no featured_image was set, and there's no "cover" image in page resources, then
+ this partial returns an empty string (which evaluates to false).
- @return RelPermalink to featured image, or an empty string if not found.
+ @return RelPermalink to featured image, or an empty string if not found.
*/}}
{{/* Declare a new string variable, $linkToCover */}}
{{ $linkToCover := "" }}
-
+{{ $matches := "feature,cover" }}
{{/* Use the value from front matter if present */}}
-{{ if .Params.featured_image }}
- {{ $linkToCover = .Params.featured_image }}
-
+{{ with .Params.featured_image }}
+ {{ $linkToCover = . }}
+ {{/* If we find a Page Resource matching the exact value, we use it instead. */}}
+ {{ with $.Resources.GetMatch . }}
+ {{ $linkToCover = .RelPermalink }}
+ {{ end }}
{{/* Find the first image with 'cover' in the name in this page bundle. */}}
{{ else }}
- {{ $img := (.Resources.ByType "image").GetMatch "*cover*" }}
- {{ with $img }}
- {{ $linkToCover = .RelPermalink }}
+ {{ with .Resources.ByType "image" }}
+ {{ with .GetMatch (printf "**{%s}*" $matches) }}
+ {{ $linkToCover = .RelPermalink }}
{{ end }}
+ {{ end }}
{{ end }}
{{/* return either a permalink, or an empty string. Note that partials can only have a single