aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/partials/gallery-walk.html
blob: 6a43eaf14c2f2650266cf4d8aed6e0cf96225edc (plain)
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
60
61
62
63
64
65
66
67
68
69
70
{{- $folder := . -}}
{{- $files := slice -}}
{{- $dimensions := "320x320" -}}
{{- $author := strings.TrimPrefix "public/" (strings.TrimSuffix "/media/" $folder) -}}

{{- if fileExists $folder -}}
  {{- range readDir $folder -}}

    {{- $name      := index (split .Name ".") 0 -}}
    {{- $extension := path.Ext .Name -}}

    {{- if or
      (eq $extension ".apng")
      (eq $extension ".avif")
      (eq $extension ".gif")
      (eq $extension ".jfif")
      (eq $extension ".jpeg")
      (eq $extension ".jpg")
      (eq $extension ".pjp")
      (eq $extension ".pjpeg")
      (eq $extension ".png")
      (eq $extension ".svg")
      (eq $extension ".webp")
    -}}
      {{-
        $files = $files | append (dict
          "Name" .Name
          "Path" (path.Join $folder .Name)
        )
      -}}
    {{- end -}}
  {{- end -}}

  {{- if $files }}

    {{- range first 6 $files }}
      {{- with $image := resources.Get .Path -}}
      {{- $image = (
        .Content |
        resources.FromString
        (print (partial "function-paths.html" "media") "/" $author "/gallery-walker_" (path.Base .))).Fit
        (print $dimensions " webp")
      }}
        <picture>
          <source srcset="{{- $image.RelPermalink -}}" type="image/webp" />
          {{- $image = (.Content |
            resources.FromString (print (partial "function-paths.html" "media") "/" $author "/gallery-walker_" (path.Base .))).Fit
            (print $dimensions " png")
           }}
          <img loading="lazy"
            alt="{{- .Name }}"
            title="{{- .Name }}"
            width="{{ $image.Width }}"
            height="{{ $image.Height }}"
            src="{{ $image.RelPermalink }}"
          />
        </picture>
     {{- end -}}
    {{- end -}}

  {{- else -}}
    <footer>
      <code>No media found!</code>
    </footer>
  {{- end -}}
{{- else -}}
  <footer>
    <code>No media found!</code>
  </footer>
{{- end }}