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

Melroy van den Berg
22.22.2024 960725d838d0512aac8159ce2a2b85774ecfb067
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{{/* 
    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 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 */}}
{{ with .Params.featured_image }}
  {{/* This is the default case, the image lives in the static directory.
    In which case we'll use the static dir */}}
  {{ $linkToCover = trim . "/" | absURL }}
  {{/* 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 }}
  {{ 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) */}}
{{ return $linkToCover }}