Welcome to mirror list, hosted at ThFree Co, Russian Federation.

render-image.html « _markup « _default « layouts - gitlab.com/rmaguiar/hugo-theme-color-your-world.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 22b034fd02c5f4a6e16e8a23e3c47b049bf33dd1 (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
{{ $file    := .Destination }}
{{ $altText := .Text }}
{{ $class   := .Page.Param "markupImgClass" }}

<!-- Get image processing options -->
{{ $imageProc := .Page.Scratch.Get "imageProc" }}

<!-- Default image path -->
{{ $imgPath := .Page.Param "imgPath" }}

{{ if $imgPath }}
  {{ $file = path.Join $imgPath $file }}
{{ end }}

<!-- Assume file is local if found -->
{{ with $.Page.Resources.GetMatch $file }}

  <!-- If image width is equal or greater than X, process it -->
  {{ if ge .Width $imageProc.markupAutoResizeWidth }}

    {{ $mediumRes := (index $imageProc.mediumRes 0) }}

    {{ $outputSet := slice }}
    {{ $inputFile := . }}
    
    {{ range $imageProc }}
      {{ $outputSet = $outputSet | append (printf "%s %s" (($inputFile.Resize (index . 0)).RelPermalink) (index . 1)) }}
    {{ end }}
    
    <img
      {{ with $class }}class="{{ . }}"{{ end }}
      loading="lazy"
      srcset='{{ delimit $outputSet ", " }}'
      src="{{ (.Resize $mediumRes).RelPermalink }}"
      width="{{ (.Resize $mediumRes).Width }}"
      height="{{ (.Resize $mediumRes).Height }}"
      {{ with $altText }}alt="{{ . }}"{{ end }}
    />

  {{ else }}

    {{ $processed := (.Resize (printf "%vx" .Width)) }}

    <img
      {{ with $class }}class="{{ . }}"{{ end }}
      loading="lazy"
      src="{{ $processed.RelPermalink }}"
      width="{{ .Width }}"
      height="{{ .Height }}"
      {{ with $altText }}alt="{{ . }}"{{ end }}
    />

  {{ end }}
    
{{ else }}
  <!-- If local file isn't found, assume it's a remote file -->
  {{ with (.Destination | safeURL) }}

    <img
      {{ with $class }}class="{{ . }}"{{ end }}
      loading="lazy"
      src="{{ . }}"
      {{ with $altText }}alt="{{ . }}"{{ end }}
    />

  {{ end }}
{{ end }}