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

Patrick Kollitsch
10 hours ago c70b22c0c65d21fc25eda46a8182eb042da11da0
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{{/*
    GetFeaturedImageResource
 
    This partial gets the featured image resource for a given page.
 
    If a featured_image was set in the page's front matter and it matches a page
    resource, then that resource will be used. Otherwise, assets are searched.
 
    If no featured_image was set, this will use the first matching page resource from
    the page's images front matter array.
 
    If not set, this will search page resources to find an image that contains the word
    "cover" or "feature", and if found, returns that resource.
 
    If no matching page or asset resource can be found, this partial returns false.
 
    @return Featured image resource, or false if not found.
 
*/}}
 
{{ $resource := false }}
{{ $matches := "feature,cover" }}
{{ $path := "" }}
{{ with .Params.featured_image }}
  {{ $path = . }}
  {{ with $.Resources.GetMatch . }}
    {{ $resource = . }}
  {{ end }}
{{ else }}
  {{ with .Params.images }}
    {{ range first 1 . }}
      {{ with . }}
        {{ $path = . }}
        {{ with $.Resources.GetMatch . }}
          {{ $resource = . }}
        {{ end }}
      {{ end }}
    {{ end }}
  {{ else }}
    {{ with .Resources.ByType "image" }}
      {{ with .GetMatch (fmt.Printf "**{%s}*" $matches) }}
        {{ $resource = . }}
      {{ end }}
    {{ end }}
  {{ end }}
{{ end }}
 
{{ if and (not $resource) $path }}
  {{ with resources.Get (strings.TrimPrefix "/" $path) }}
    {{ $resource = . }}
  {{ end }}
{{ end }}
{{ if $resource }}
  {{ if ne $resource.ResourceType "image" }}
    {{ $resource = false }}
  {{ end }}
{{ end }}
 
{{ return $resource }}