File: imgproc.html

package info (click to toggle)
hugo 0.155.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 43,600 kB
  • sloc: javascript: 31,879; ansic: 2,350; xml: 350; makefile: 196; sh: 110
file content (39 lines) | stat: -rw-r--r-- 1,472 bytes parent folder | download | duplicates (3)
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
{{/* prettier-ignore-start */ -}}
{{- /*
Renders the given image using the given process specification.

@param {string} path The path to the image, either a page resource or a global resource.
@param {string} spec The image processing specification.
@param {string} alt The alt attribute of the img element.

@example {{< imgproc path="sunset.jpg" spec="resize 300x" alt="A sunset" >}}
*/ -}}
{{/* prettier-ignore-end */ -}}
{{- with $.Get "path" }}
  {{- with $i := or ($.Page.Resources.Get .) (resources.Get .) }}
    {{- with $spec := $.Get "spec" }}
      {{- with $i.Process . }}
        <figure>
          <img
            src="{{ .RelPermalink }}"
            width="{{ .Width }}"
            height="{{ .Height }}"
            alt="{{ $.Get `alt` }}">
          <figcaption class="not-prose text-sm">
            {{- with $.Inner }}
              {{ . }}
            {{- else }}
              {{ $spec }}
            {{- end }}
          </figcaption>
        </figure>
      {{- end }}
    {{- else }}
      {{- errorf "The %q shortcode requires a 'spec' argument containing the image processing specification. See %s" $.Name $.Position }}
    {{- end }}
  {{- else }}
    {{- errorf "The %q shortcode was unable to find %q. See %s" $.Name . $.Position }}
  {{- end }}
{{- else }}
  {{- errorf "The %q shortcode requires a 'path' argument indicating the image path. The image must be a page resource or a global resource. See %s" $.Name $.Position }}
{{- end }}