mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -1,37 +1,39 @@
|
||||
{{/* prettier-ignore-start */ -}}
|
||||
{{- /*
|
||||
Renders the given image using the given process specification.
|
||||
|
||||
@param {string} (positional parameter 0) The path to the image, relative to the current page. The image must be a page resource.
|
||||
@param {string}} (positional parameter 1) The image processing 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.
|
||||
|
||||
@returns template.HTML
|
||||
|
||||
@example {{< imgproc "sunset.jpg" "resize 300x" />}}
|
||||
*/}}
|
||||
|
||||
{{- with $.Get 0 }}
|
||||
{{- with $i := $.Page.Resources.Get . }}
|
||||
{{- with $spec := $.Get 1 }}
|
||||
@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 style="padding: 0.25rem; margin: 2rem 0; background-color: #cccc">
|
||||
<img style="max-width: 100%; width: auto; height: auto;" src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
|
||||
<figcaption>
|
||||
<small>
|
||||
{{- with $.Inner }}
|
||||
{{ . }}
|
||||
{{- else }}
|
||||
{{ $spec }}
|
||||
{{- end }}
|
||||
</small>
|
||||
<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 positional parameter (1) containing the image processing specification. See %s" $.Name $.Position }}
|
||||
{{- 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 positional parameter (0) indicating the image path, relative to the current page. See %s" $.Name $.Position }}
|
||||
{{- 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 }}
|
||||
|
Reference in New Issue
Block a user