@thulite/images 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ # Changesets
2
+
3
+ Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4
+ with multi-package repos, or single-package repos to help you version and publish your code. You can
5
+ find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6
+
7
+ We have a quick list of common questions to get you started engaging with this project in
8
+ [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
3
+ "changelog": ["@changesets/changelog-github", { "repo": "thuliteio/images" }],
4
+ "commit": false,
5
+ "fixed": [],
6
+ "linked": [],
7
+ "access": "restricted",
8
+ "baseBranch": "main",
9
+ "updateInternalDependencies": "patch",
10
+ "ignore": []
11
+ }
@@ -0,0 +1,14 @@
1
+ *.html
2
+ *.ico
3
+ *.png
4
+ *.jp*g
5
+ *.toml
6
+ *.*ignore
7
+ *.svg
8
+ *.xml
9
+ LICENSE
10
+ .npmrc
11
+ .gitkeep
12
+ *.woff*
13
+ *.json
14
+ flexsearch.js
@@ -0,0 +1,19 @@
1
+ # Default config
2
+ tabWidth: 4
3
+ endOfLine: crlf
4
+ singleQuote: true
5
+ printWidth: 100000
6
+ trailingComma: none
7
+ bracketSameLine: true
8
+ quoteProps: consistent
9
+ experimentalTernaries: true
10
+
11
+ # Overrided config
12
+ overrides:
13
+ - files: ["*.md", "*.json", "*.yaml"]
14
+ options:
15
+ tabWidth: 2
16
+ singleQuote: false
17
+ - files: ["*.scss"]
18
+ options:
19
+ singleQuote: false
@@ -0,0 +1,7 @@
1
+ {
2
+ "editor.wordWrap": "off",
3
+ "files.trimTrailingWhitespace": true,
4
+ "files.insertFinalNewline": true,
5
+ "editor.tabSize": 2,
6
+ "editor.insertSpaces": true
7
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @thulite/images
2
+
3
+ ## 3.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#24](https://github.com/thuliteio/images/pull/24) [`1783868`](https://github.com/thuliteio/images/commit/17838683bf74e0d11df779a7e53e55922680ffd5) Thanks [@h-enk](https://github.com/h-enk)! - Update for migration from Hyas to Thulite
8
+
9
+ ## 3.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#23](https://github.com/gethyas/images/pull/23) [`0e09814`](https://github.com/gethyas/images/commit/0e098140dbc9287f43ca2aaa2ba519d71c58d33f) Thanks [@h-enk](https://github.com/h-enk)! - Update for new Hyas setup
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-2024 Thulite
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Thulite images
2
+
3
+ Official images integration for Thulite.
4
+
5
+ ## Getting Started
6
+
7
+ See the Doks documentation:
8
+
9
+ - [Images](https://images.thulite.io/docs/start-here/getting-started/)
@@ -0,0 +1,33 @@
1
+ img {
2
+ max-width: 100%;
3
+ height: auto;
4
+ }
5
+
6
+ img[data-sizes="auto"] {
7
+ display: block;
8
+ }
9
+
10
+ img,
11
+ picture {
12
+ font-size: 0;
13
+ }
14
+
15
+ figcaption {
16
+ font-size: 1rem;
17
+ margin-top: 0.5rem;
18
+ font-style: italic;
19
+ }
20
+
21
+ .content .gitpod-mark-monochrome.icon {
22
+ margin-bottom: 0.125rem;
23
+ margin-right: 0.5rem;
24
+ }
25
+
26
+ .blur-up {
27
+ filter: blur(5px);
28
+ transition: filter 400ms;
29
+ }
30
+
31
+ .blur-up.lazyloaded {
32
+ filter: unset;
33
+ }
@@ -0,0 +1,172 @@
1
+ {{- /* Based on https://www.veriphor.com/articles/link-and-image-render-hooks/#image-render-hook */}}
2
+
3
+ {{- /* Last modified: 2023-12-09T16:29:48-08:00 */}}
4
+
5
+ {{- /*
6
+ Copyright 2023 Veriphor LLC
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
+ use this file except in compliance with the License. You may obtain a copy of
10
+ the License at
11
+
12
+ https://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+ License for the specific language governing permissions and limitations under
18
+ the License.
19
+ */}}
20
+
21
+ {{- /*
22
+ This render hook resolves internal destinations by looking for a matching:
23
+
24
+ 1. Page resource (an image in the current page bundle)
25
+ 2. Section resource (an image in the current section)
26
+ 3. Global resource (an image in the assets directory)
27
+
28
+ It skips the section resource lookup if the current page is a leaf bundle, and
29
+ captures external destinations as resources for local hosting.
30
+
31
+ You must place global resources in the assets directory. If you have placed
32
+ your resources in the static directory, and you are unable or unwilling to move
33
+ them, you must mount the static directory to the assets directory by including
34
+ both of these entries in your site configuration:
35
+
36
+ [[module.mounts]]
37
+ source = 'assets'
38
+ target = 'assets'
39
+
40
+ [[module.mounts]]
41
+ source = 'static'
42
+ target = 'assets'
43
+
44
+ By default, if this render hook is unable to resolve a destination, it passes
45
+ the destination through without modification. To emit a warning or error, set
46
+ the error level in your site configuration:
47
+
48
+ [params.render_hooks.image]
49
+ errorLevel = 'warning' # ignore (default), warning, or error (fails the build)
50
+
51
+ Image render hooks are also used to:
52
+
53
+ - Resize, crop, rotate, filter, and convert images
54
+ - Build responsive images using srcset and sizes attributes
55
+ - Wrap images inside of a picture element
56
+ - Transform standalone images into figure elements
57
+
58
+ To perform any of these operations, you can “hook” into this render hook with a
59
+ partial template, after the render hook has captured the resource.
60
+
61
+ @context {map} Attributes The markdown attributes, available if (a) markup.goldmark.parser.attribute.block is true, and (b) markup.goldmark.parser.wrapStandAloneImageWithinParagraph is false in site configuration.
62
+ @context {string} Destination The image destination.
63
+ @context {bool} IsBlock Returns true if a standalone image is not wrapped within a paragraph element.
64
+ @context {int} Ordinal The zero-based ordinal of the image on the page.
65
+ @context {page} Page A reference to the page containing the image.
66
+ @context {string} PlainText The image description as plain text.
67
+ @context {string} Text The image description.
68
+ @context {string} Title The image title.
69
+
70
+ @returns {template.html}
71
+ */}}
72
+
73
+ {{- /* Initialize. */}}
74
+ {{- $renderHookName := "image" }}
75
+
76
+ {{- /* Verify minimum required version. */}}
77
+ {{- $minHugoVersion := "0.114.0" }}
78
+ {{- if lt hugo.Version $minHugoVersion }}
79
+ {{- errorf "The %q render hook requires Hugo v%s or later." $renderHookName $minHugoVersion }}
80
+ {{- end }}
81
+
82
+ {{- /* Error level when unable to resolve destination: ignore, warning, or error. */}}
83
+ {{- $errorLevel := or site.Params.render_hooks.image.errorLevel "ignore" | lower }}
84
+
85
+ {{- /* Validate error level. */}}
86
+ {{- if not (in (slice "ignore" "warning" "error") $errorLevel) }}
87
+ {{- errorf "The %q render hook is misconfigured. The errorLevel %q is invalid. Please check your site configuration." $renderHookName $errorLevel }}
88
+ {{- end }}
89
+
90
+ {{- /* Determine content path for warning and error messages. */}}
91
+ {{- $contentPath := "" }}
92
+ {{- with .Page.File }}
93
+ {{- $contentPath = .Path }}
94
+ {{- else }}
95
+ {{- $contentPath = .Path }}
96
+ {{- end }}
97
+
98
+ {{- /* Parse destination. */}}
99
+ {{- $u := urls.Parse .Destination }}
100
+
101
+ {{- /* Set common message. */}}
102
+ {{- $msg := printf "The %q render hook was unable to resolve the destination %q in %s" $renderHookName $u.String $contentPath }}
103
+
104
+ {{- /* Get image resource. */}}
105
+ {{- $r := "" }}
106
+ {{- if $u.IsAbs }}
107
+ {{- with resources.GetRemote $u.String }}
108
+ {{- with .Err }}
109
+ {{- if eq $errorLevel "warning" }}
110
+ {{- warnf "%s. See %s" . $contentPath }}
111
+ {{- else if eq $errorLevel "error" }}
112
+ {{- errorf "%s. See %s" . $contentPath }}
113
+ {{- end }}
114
+ {{- else }}
115
+ {{- /* Destination is a remote resource. */}}
116
+ {{- $r = . }}
117
+ {{- end }}
118
+ {{- else }}
119
+ {{- if eq $errorLevel "warning" }}
120
+ {{- warnf $msg }}
121
+ {{- else if eq $errorLevel "error" }}
122
+ {{- errorf $msg }}
123
+ {{- end }}
124
+ {{- end }}
125
+ {{- else }}
126
+ {{- with .Page.Resources.Get (strings.TrimPrefix "./" $u.Path) }}
127
+ {{- /* Destination is a page resource. */}}
128
+ {{- $r = . }}
129
+ {{- else }}
130
+ {{- with (and (ne .Page.BundleType "leaf") (.Page.CurrentSection.Resources.Get (strings.TrimPrefix "./" $u.Path))) }}
131
+ {{- /* Destination is a section resource, and current page is not a leaf bundle. */}}
132
+ {{- $r = . }}
133
+ {{- else }}
134
+ {{- with resources.Get $u.Path }}
135
+ {{- /* Destination is a global resource. */}}
136
+ {{- $r = . }}
137
+ {{- else }}
138
+ {{- if eq $errorLevel "warning" }}
139
+ {{- warnf $msg }}
140
+ {{- else if eq $errorLevel "error" }}
141
+ {{- errorf $msg }}
142
+ {{- end }}
143
+ {{- end }}
144
+ {{- end }}
145
+ {{- end }}
146
+ {{- end }}
147
+
148
+ {{- /* Determine id attribute. */}}
149
+ {{- $id := printf "h-rh-i-%d" .Ordinal }}
150
+ {{- with .Attributes.id }}
151
+ {{- $id = . }}
152
+ {{- end }}
153
+
154
+ {{/* Convert to webp. */}}
155
+ {{- if ne $r.MediaType.SubType "gif" }}
156
+ {{- $r = $r.Resize (printf "%dx%d webp" $r.Width $r.Height) }}
157
+ {{- end }}
158
+
159
+ {{- /* Render image element. */ -}}
160
+ <img
161
+ src="{{ $r.RelPermalink }}"
162
+ width="{{ string $r.Width }}"
163
+ height="{{ string $r.Height }}"
164
+ decoding="{{ site.Params.thulite_images.defaults.decoding }}"
165
+ fetchpriority="{{ site.Params.thulite_images.defaults.fetchpriority }}"
166
+ loading="{{ site.Params.thulite_images.defaults.loading }}"
167
+ alt="{{ .PlainText }}"
168
+ {{- with .Title -}}title="{{ . }}"{{- end -}}
169
+ id="{{ $id }}"
170
+ />
171
+
172
+ {{- /**/ -}}
@@ -0,0 +1,289 @@
1
+ {{- /* Based on https://www.veriphor.com/articles/link-and-image-render-hooks/#image-render-hook */}}
2
+
3
+ {{- /* Last modified: 2023-09-05T11:48:34-07:00 */}}
4
+
5
+ {{- /*
6
+ Copyright 2023 Veriphor LLC
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
+ use this file except in compliance with the License. You may obtain a copy of
10
+ the License at
11
+
12
+ https://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+ License for the specific language governing permissions and limitations under
18
+ the License.
19
+ */}}
20
+
21
+ {{- /*
22
+ Renders an HTML figure element, in multiple formats and sizes.
23
+
24
+ It resolves internal destinations by looking for a matching:
25
+
26
+ 1. Page resource (an image in the current page bundle)
27
+ 2. Section resource (an image in the current section)
28
+ 3. Global resource (an image in the assets directory)
29
+
30
+ It skips the section resource lookup if the current page is a leaf bundle, and
31
+ captures external destinations as resources for local hosting. The build will
32
+ fail if this partial is unable to resolve a destination.
33
+
34
+ You must place global resources in the assets directory. If you have placed
35
+ your resources in the static directory, and you are unable or unwilling to move
36
+ them, you must mount the static directory to the assets directory by including
37
+ both of these entries in your site configuration:
38
+
39
+ [[module.mounts]]
40
+ source = 'assets'
41
+ target = 'assets'
42
+
43
+ [[module.mounts]]
44
+ source = 'static'
45
+ target = 'assets'
46
+
47
+ Add this CSS to your site to enable responsive image behavior:
48
+
49
+ img {
50
+ height: auto;
51
+ max-width: 100%;
52
+ }
53
+
54
+ Add this CSS to your site to remove small gaps between adjacent elements:
55
+
56
+ img, picture {
57
+ font-size: 0;
58
+ }
59
+
60
+ @context {page} [page] The current page.
61
+ @context {string} [src] The path to the base image: a page resource, a global resource, or a remote resource.
62
+ @contect {int} [width] The display width of the image, in pixels, falling back to 100% of the viewport width.
63
+ @context {string} [sizes] = "" # "100vw", "75vw", or "auto" for example
64
+ @context {string slice} [formats] A slice of image formats, ordered by precedence, to use when creating images for the srcset attribute of each source element.
65
+ @context {string} [process] = "" # "fill 1600x900" for example
66
+ @context {string} [lqip] = "" # "16x webp q20" or "21x webp q20" for example
67
+ @context {string} [decoding] The img element's decoding attribute.
68
+ @context {string} [fetchpriority] The img element's fetchpriority attribute.
69
+ @context {string} [loading] The img element's loading attribute.
70
+ @context {string} [alt] The img element's alt attribute.
71
+ @context {string} [title] The img element's title attribute.
72
+ @context {string} [caption] The figure element's caption attribute.
73
+ @context {string} [class] The img element's class attribute.
74
+
75
+ @returns {template.HTML}
76
+
77
+ @example (required args only)
78
+
79
+ {{- partial "figure.html" (dict "page" . "src" "images/zion.jpg") }}
80
+
81
+ @example (all args)
82
+ {{- $opts := dict
83
+ "page" .
84
+ "src" "images/bryce-canyon-national-park.jpg"
85
+ "width" 768
86
+ "sizes" "auto"
87
+ "formats" (slice "webp" "jpeg")
88
+ "process" "fill 1600x900"
89
+ "lqip" "16x webp q20"
90
+ "decoding" "async"
91
+ "fetchpriority" "auto"
92
+ "loading" "eager"
93
+ "alt" "Bryce Canyon National Park"
94
+ "title" "A beautiful day in Bryce Canyon National Park"
95
+ "caption" "Bryce Canyon National Park"
96
+ "class" "foo"
97
+ }}
98
+ {{- partial "figure.html" $opts }}
99
+
100
+ */}}
101
+
102
+ {{- /* Initialize. */}}
103
+ {{- $partialName := "figure" }}
104
+
105
+ {{- /* Verify minimum required version. */}}
106
+ {{- $minHugoVersion := "0.118.0" }}
107
+ {{- if lt hugo.Version $minHugoVersion }}
108
+ {{- errorf "The %q partial requires Hugo v%s or later." $partialName $minHugoVersion }}
109
+ {{- end }}
110
+
111
+ {{- /* Validate page arg. */}}
112
+ {{- if not .page }}
113
+ {{- errorf "The %q partial requires a page argument." $partialName }}
114
+ {{- end }}
115
+
116
+ {{- /* Determine content path for warning and error messages. */}}
117
+ {{- $contentPath := "" }}
118
+ {{- with .page.File }}
119
+ {{- $contentPath = .Path }}
120
+ {{- else }}
121
+ {{- $contentPath = .Path }}
122
+ {{- end }}
123
+
124
+ {{- /* Set defaults and get args. */}}
125
+ {{- $alt := or .alt "" }}
126
+ {{- $class := or .class "" }}
127
+ {{- $formats := or .formats (slice "webp") }}
128
+ {{- $decoding := or .decoding site.Params.thulite_images.defaults.decoding }}
129
+ {{- $fetchPriority := or .fetchpriority site.Params.thulite_images.defaults.fetchpriority }}
130
+ {{- $loading := or .loading site.Params.thulite_images.defaults.loading }}
131
+ {{- $process := or .process site.Params.thulite_images.defaults.process }}
132
+ {{- $lqip := or .lqip site.Params.thulite_images.defaults.lqip }}
133
+ {{- $src := or .src "" }}
134
+ {{- $title := or .title "" }}
135
+ {{- $caption := or .caption "" }}
136
+ {{- $width := or (int .width) 0 }}
137
+ {{- $fallbackFormat := "jpeg" }}
138
+ {{- $stdWidths := site.Params.thulite_images.defaults.widths }}
139
+ {{- $stdSizes := or .sizes site.Params.thulite_images.defaults.sizes }}
140
+
141
+ {{- /* Validate args. */}}
142
+ {{- $validFormats := slice "gif" "jpg" "jpeg" "png" "webp"}}
143
+ {{- if reflect.IsSlice $formats }}
144
+ {{- $formats = apply $formats "strings.ToLower" "." }}
145
+ {{- range $formats }}
146
+ {{- if not (in $validFormats .) }}
147
+ {{- errorf "The formats argument passed to the %q partial is invalid. Valid formats are %s. See %s" $partialName (delimit $validFormats ", " ", and ") $contentPath }}
148
+ {{- end }}
149
+ {{- end }}
150
+ {{- else }}
151
+ {{- errorf "The formats argument passed to the %q partial is not a slice. See %s" $partialName $contentPath }}
152
+ {{- end }}
153
+
154
+ {{- if not $src }}
155
+ {{- errorf "The %q partial requires an image path, relative to the assets directory. See %s" $partialName $contentPath }}
156
+ {{- end }}
157
+
158
+ {{- /* Capture image as a resource. */}}
159
+ {{- $r := "" }}
160
+ {{- $ctx := dict
161
+ "page" .page
162
+ "path" $src
163
+ "partialName" $partialName
164
+ "contentPath" $contentPath
165
+ }}
166
+ {{- with partial "inline/capture-resource.html" $ctx }}
167
+ {{- $r = . }}
168
+ {{- end }}
169
+
170
+ {{- /* Process image. */}}
171
+ {{- with $process }}
172
+ {{- $r = $r.Process $process }}
173
+ {{- end }}
174
+
175
+ {{- /* Process LQIP. */}}
176
+ {{- $l := "" }}
177
+ {{- with $lqip }}
178
+ {{- $l = $r.Resize . }}
179
+ {{- end }}
180
+
181
+ {{- /* Determine widths for srcset generation. */}}
182
+ {{- $widths := slice }}
183
+ {{- if $width }}
184
+ {{- /* The width was specified; generate 1x, 2x, 3x, and 4x images. */}}
185
+ {{- $widths = slice $r.Width }}
186
+ {{- range seq 4 }}
187
+ {{- with mul . $width }}
188
+ {{- if and (le . $r.Width) (le . (math.Max $stdWidths)) }}
189
+ {{- /* Do not enlarge, and do not exceed maximum of $stdWidths. */}}
190
+ {{- $widths = $widths | append . }}
191
+ {{- end }}
192
+ {{- end }}
193
+ {{- end }}
194
+ {{- else }}
195
+ {{- /* The width was not speficied, will be using $stdWidths. */}}
196
+ {{- $stdWidths = $stdWidths | append $r.Width | sort }}
197
+ {{- range $stdWidths }}
198
+ {{- /* Do not enlarge. */}}
199
+ {{- if (le . $r.Width) }}
200
+ {{- $widths = $widths | append . }}
201
+ {{- end }}
202
+ {{- end }}
203
+ {{- end }}
204
+ {{- $widths = $widths | uniq | sort}}
205
+
206
+ {{- /* Create fallback image (fi) with the smallest of widths. */}}
207
+ {{- $fi := $r.Resize (printf "%dx %s" (math.Min $widths | int) $fallbackFormat) }}
208
+
209
+ {{- /* Create the image map. */}}
210
+ {{- $im := dict }}
211
+ {{- range $format := $formats }}
212
+ {{- $sizes := slice }}
213
+ {{- range sort $widths }}
214
+ {{- $sizes = $sizes | append ($r.Resize (printf "%dx %s" . $format)) }}
215
+ {{- end }}
216
+ {{- $im = merge $im (dict $format $sizes) }}
217
+ {{- end }}
218
+
219
+ {{- /* Render. */}}
220
+ <figure>
221
+ <img
222
+ srcset="data:{{ $l.MediaType }};base64,{{ $l.Content | base64Encode }}"
223
+ {{- range $formats }}
224
+ {{- with index $im . }}
225
+ {{- $sizes := $stdSizes }}
226
+ {{- with $width }}
227
+ {{- $sizes = printf "%dpx" . }}
228
+ {{- end }}
229
+ data-srcset="
230
+ {{- range $k, $_ := . }}
231
+ {{- if $k }},{{- end }}
232
+ {{- printf `%s %dw` .RelPermalink .Width }}
233
+ {{- end }}"
234
+ data-sizes="{{ $stdSizes }}"
235
+ {{- end }}
236
+ {{- end }}
237
+ src="{{ $fi.RelPermalink }}"
238
+ width="{{ string $r.Width }}"
239
+ height="{{ string $r.Height }}"
240
+ decoding="{{ $decoding }}"
241
+ fetchpriority="{{ $fetchPriority }}"
242
+ loading="{{ $loading }}"
243
+ alt="{{ $alt }}"
244
+ {{- with .title }}title="{{ $title }}"{{- end }}
245
+ class="lazyload blur-up{{- with .class }} {{ . }}{{- end }}"
246
+ >
247
+ {{- with $caption }}<figcaption>{{ . }}</figcaption>{{- end }}
248
+ </figure>
249
+
250
+ {{- define "partials/inline/capture-resource.html" }}
251
+ {{- /* Parse destination. */}}
252
+ {{- $u := urls.Parse .path }}
253
+
254
+ {{- /* Set common message. */}}
255
+ {{- $msg := printf "The %q partial was unable to get %q in %s" .partialName $u.String .contentPath }}
256
+
257
+ {{- /* Get image resource. */}}
258
+ {{- $r := "" }}
259
+ {{- if $u.IsAbs }}
260
+ {{- with resources.GetRemote $u.String }}
261
+ {{- with .Err }}
262
+ {{- errorf "%s. See %s" . $.contentPath }}
263
+ {{- else }}
264
+ {{- /* Destination is a remote resource. */}}
265
+ {{- $r = . }}
266
+ {{- end }}
267
+ {{- else }}
268
+ {{- errorf $msg }}
269
+ {{- end }}
270
+ {{- else }}
271
+ {{- with .page.Resources.Get (strings.TrimPrefix "./" $u.Path) }}
272
+ {{- /* Destination is a page resource. */}}
273
+ {{- $r = . }}
274
+ {{- else }}
275
+ {{- with (and (ne .page.BundleType "leaf") (.page.CurrentSection.Resources.Get (strings.TrimPrefix "./" $u.Path)) ) }}
276
+ {{- /* Destination is a section resource, and current page is not a leaf bundle. */}}
277
+ {{- $r = . }}
278
+ {{- else }}
279
+ {{- with resources.Get $u.Path }}
280
+ {{- /* Destination is a global resource. */}}
281
+ {{- $r = . }}
282
+ {{- else }}
283
+ {{- errorf $msg }}
284
+ {{- end }}
285
+ {{- end }}
286
+ {{- end }}
287
+ {{- end }}
288
+ {{- return $r }}
289
+ {{- end -}}