diff options
author | gabrielgio <gabriel.giovanini@pm.me> | 2020-07-11 22:35:14 +0200 |
---|---|---|
committer | gabrielgio <gabriel.giovanini@pm.me> | 2020-07-11 22:35:14 +0200 |
commit | 60fe49ea3af38d4a7d5e8de1cdb72887b167b22d (patch) | |
tree | bb05011c311b74c7c7676b7b689bbbc2c8546c9a /themes/ananke/layouts/partials/func/GetFeaturedImage.html | |
parent | 60b4299cb90a5b3f6e74ffd0ee0f51a0008fb3cf (diff) | |
download | gabrielgio.me-60fe49ea3af38d4a7d5e8de1cdb72887b167b22d.tar.gz gabrielgio.me-60fe49ea3af38d4a7d5e8de1cdb72887b167b22d.tar.bz2 gabrielgio.me-60fe49ea3af38d4a7d5e8de1cdb72887b167b22d.zip |
Moving from jekyll to hugo
Diffstat (limited to 'themes/ananke/layouts/partials/func/GetFeaturedImage.html')
-rw-r--r-- | themes/ananke/layouts/partials/func/GetFeaturedImage.html | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/themes/ananke/layouts/partials/func/GetFeaturedImage.html b/themes/ananke/layouts/partials/func/GetFeaturedImage.html new file mode 100644 index 0000000..3c0d5de --- /dev/null +++ b/themes/ananke/layouts/partials/func/GetFeaturedImage.html @@ -0,0 +1,35 @@ +{{/* + GetFeaturedImage + + 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 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). + + @return Permalink to featured image, or an empty string if not found. + +*/}} + +{{/* Declare a new string variable, $linkToCover */}} +{{ $linkToCover := "" }} + +{{/* Use the value from front matter if present */}} +{{ if .Params.featured_image }} + {{ $linkToCover = .Params.featured_image }} + +{{/* Find the first image with 'cover' in the name in this page bundle. */}} +{{ else }} + {{ $img := (.Resources.ByType "image").GetMatch "*cover*" }} + {{ with $img }} + {{ $linkToCover = .Permalink }} + {{ end }} +{{ end }} + +{{/* return either a permalink, or an empty string. Note that partials can only have a single +return statement, so this needs to be at the end of the partial (and not in the if block) */}} +{{ return $linkToCover }}
\ No newline at end of file |