mirror of https://github.com/theNewDynamic/gohugo-theme-ananke.git

Regis Philibert
23.42.2021 718a85aaf663a6b90f8a344e91f72a77c406ba06
Featured image detection refactoring:

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
2 files modified
20 ■■■■ changed files
README.md 4 ●●●● patch | view | raw | blame | history
layouts/partials/func/GetFeaturedImage.html 16 ●●●●● patch | view | raw | blame | history
README.md
@@ -107,6 +107,10 @@
For any page or post you can add a featured image by including the local path in front matter (see content in the `exampleSite/content/_readme.md` file for examples): `featured_image: '/images/gohugo-default-sample-hero-image.jpg'`
#### Featured image as Page Resources
If user is using [Page Resources](https://gohugo.io/content-management/page-resources/), the theme will try and match the `featured_image` from with a page resource of type `image` and use its relative permalink. If no `featured_image` is set, the theme will look for a Page Resource of type `image` whose filepath incudes either `cover` or `feature`
#### Other hero settings
If you would like to hide the header text on the featured image on a page, set `omit_header_text` to `true`. See `exampleSite/content/contact.md` for an example.
You don't need an image though. The default background color is black, but you can change the color, by changing the default color class in the config.toml file. Choose a background color from any on the [Tachyons](http://tachyons.io/docs/themes/skins/) library site, and preface it with "bg-"
layouts/partials/func/GetFeaturedImage.html
@@ -17,18 +17,22 @@
{{/* 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 }}
  {{ 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
return statement, so this needs to be at the end of the partial (and not in the if block) */}}