-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathimage-set.html
More file actions
61 lines (55 loc) · 2.23 KB
/
image-set.html
File metadata and controls
61 lines (55 loc) · 2.23 KB
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
{{/*
Copyright © 2022 - 2025 The Hinode Team / Mark Dumay. All rights reserved.
Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
Visit gethinode.com/license for more details.
*/}}
{{/* Initialize arguments */}}
{{ $args := partial "utilities/InitArgs.html" (dict "structure" "image-set" "args" . "group" "partial") }}
{{ if or $args.err $args.warnmsg }}
{{ partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "assets/helpers/image-set.html"
"warnid" "warn-invalid-arguments"
"msg" "Invalid arguments"
"details" ($args.errmsg | append $args.warnmsg)
"file" page.File
)}}
{{ end }}
{{/* Initialize local arguments */}}
{{- $src := $args.src -}}
{{ $absoluteURL := or $args.absoluteUrl $args.absoluteURL }}
{{ $hook := $args.hook }}
{{ $host := (urls.Parse $src).Hostname }}
{{ $dir := (urls.Parse $src).Path }}
{{ $file := index ((split $dir "/") | collections.Reverse) 0 }}
{{ $dir = strings.TrimSuffix $file $dir }}
{{ $adapter := (printf "assets/adapters/%s.html" $hook) }}
{{ if not (fileExists (path.Join "/layouts/_partials" $adapter)) }}
{{ warnf "Cannot find adapter: %s" (path.Join "/layouts/_partials" $adapter) }}
{{ $hook = "hugo" }}
{{ $adapter = "assets/adapters/hugo.html" }}
{{ end }}
{{ $imgset := slice }}
{{ if not $args.err }}
{{- range $index, $dim := $args.dims -}}
{{ $width := (int (index (split $dim "x") 0)) }}
{{ $height := (int (index (split $dim "x") 1)) }}
{{- $element := partial $adapter (dict
"url-host" $host
"url-dir" $dir
"url-file" $file
"img" $args.img
"absolute-url" $absoluteURL
"transform" $args.transform
"image-width" $width
"image-height" $height
"format" $args.format
"anchor" $args.anchor
)}}
{{ if $args.includeWidth }}
{{ $imgset = $imgset | append (printf "%s %dw" $element $width) }}
{{ else }}
{{ $imgset = $imgset | append $element }}
{{ end }}
{{- end -}}
{{- end -}}
{{ return (delimit $imgset ", ") }}