Add maxheight, maxwidth params

master
Will Faught 3 years ago
parent 02a80777e9
commit c3051e027f

@ -586,6 +586,8 @@ The `paige/image` shortcode provides a figure with a centered image.
caption="My caption" caption="My caption"
height="10rem" height="10rem"
link="https://github.com/willfaught/paige" link="https://github.com/willfaught/paige"
maxheight="10rem"
maxwidth="10rem"
method="resize" method="resize"
options="550x webp picture Lanczos" options="550x webp picture Lanczos"
src="me.jpg" src="me.jpg"
@ -604,6 +606,10 @@ Parameters:
<dd>Optional. Image height in pixels.</dd> <dd>Optional. Image height in pixels.</dd>
<dt><code>link</code></dt> <dt><code>link</code></dt>
<dd>Optional. URL. Image link.</dd> <dd>Optional. URL. Image link.</dd>
<dt><code>maxheight</code></dt>
<dd>Optional. Maximum image height.</dd>
<dt><code>maxwidth</code></dt>
<dd>Optional. Maximum image width.</dd>
<dt><code>method</code></dt> <dt><code>method</code></dt>
<dd>Optional. Hugo image processing method. Must be <code>crop</code>, <code>fill</code>, <code>fit</code>, or <code>resize</code>. Must be specified with <code>options</code>. See <a href="https://gohugo.io/content-management/image-processing/#image-processing-methods">Image Processing Methods</a>.</dd> <dd>Optional. Hugo image processing method. Must be <code>crop</code>, <code>fill</code>, <code>fit</code>, or <code>resize</code>. Must be specified with <code>options</code>. See <a href="https://gohugo.io/content-management/image-processing/#image-processing-methods">Image Processing Methods</a>.</dd>
<dt><code>options</code></dt> <dt><code>options</code></dt>
@ -631,6 +637,8 @@ The `paige/gallery` shortcode provides a figure with a centered list of images.
height="10rem" height="10rem"
images="*.jpg" images="*.jpg"
justify="center" justify="center"
maxheight="10rem"
maxwidth="10rem"
method="resize" method="resize"
options="550x webp picture Lanczos" options="550x webp picture Lanczos"
type="list" type="list"
@ -655,13 +663,17 @@ Parameters:
<dt><code>caption</code></dt> <dt><code>caption</code></dt>
<dd>Optional. Markdown. Descriptive text that appears centered below the images.</dd> <dd>Optional. Markdown. Descriptive text that appears centered below the images.</dd>
<dt><code>height</code></dt> <dt><code>height</code></dt>
<dd>Optional. Height of the image or images.</dd> <dd>Optional. Height of the image or images in pixels.</dd>
<dt><code>image</code></dt> <dt><code>image</code></dt>
<dd>Optional. Page, site, or remote image glob. Only used in the inner content of this shortcode.</dd> <dd>Optional. Page, site, or remote image glob. Only used in the inner content of this shortcode.</dd>
<dt><code>images</code></dt> <dt><code>images</code></dt>
<dd>Optional. Unnamed argument. Page, site, or remote images glob. Defaults to all image page resources.</dd> <dd>Optional. Unnamed argument. Page, site, or remote images glob. Defaults to all image page resources.</dd>
<dt><code>justify</code></dt> <dt><code>justify</code></dt>
<dd>Optional. Flexbox main axis space distribution. Must be <code>start</code>, <code>center</code>, <code>end</code>, etc. See <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content"><code>justify-content</code></a>.</dd> <dd>Optional. Flexbox main axis space distribution. Must be <code>start</code>, <code>center</code>, <code>end</code>, etc. See <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content"><code>justify-content</code></a>.</dd>
<dt><code>maxheight</code></dt>
<dd>Optional. Maximum height of the image or images.</dd>
<dt><code>maxwidth</code></dt>
<dd>Optional. Maximum width of the image or images.</dd>
<dt><code>method</code></dt> <dt><code>method</code></dt>
<dd>Optional. Hugo image processing method. Must be <code>crop</code>, <code>fill</code>, <code>fit</code>, or <code>resize</code>. Default is <code>resize</code>. Must be specified with <code>options</code>. See <a href="https://gohugo.io/content-management/image-processing/#image-processing-methods">Image Processing Methods</a>.</dd> <dd>Optional. Hugo image processing method. Must be <code>crop</code>, <code>fill</code>, <code>fit</code>, or <code>resize</code>. Default is <code>resize</code>. Must be specified with <code>options</code>. See <a href="https://gohugo.io/content-management/image-processing/#image-processing-methods">Image Processing Methods</a>.</dd>
<dt><code>options</code></dt> <dt><code>options</code></dt>
@ -669,7 +681,7 @@ Parameters:
<dt><code>type</code></dt> <dt><code>type</code></dt>
<dd>Optional. Type of layout. Must be <code>grid</code> or <code>list</code>. Default is <code>list</code>.</dd> <dd>Optional. Type of layout. Must be <code>grid</code> or <code>list</code>. Default is <code>list</code>.</dd>
<dt><code>width</code></dt> <dt><code>width</code></dt>
<dd>Optional. Width of the image or images.</dd> <dd>Optional. Width of the image or images in pixels.</dd>
</dl> </dl>
## Customization ## Customization

@ -2,6 +2,8 @@
{{ $caption := .caption }} {{ $caption := .caption }}
{{ $height := .height }} {{ $height := .height }}
{{ $link := .link }} {{ $link := .link }}
{{ $maxheight := .maxheight }}
{{ $maxwidth := .maxwidth }}
{{ $method := .method }} {{ $method := .method }}
{{ $options := .options }} {{ $options := .options }}
{{ $page := .page }} {{ $page := .page }}
@ -20,6 +22,8 @@
"alt" $alt "alt" $alt
"class" $class "class" $class
"height" $height "height" $height
"maxheight" $maxheight
"maxwidth" $maxwidth
"method" $method "method" $method
"options" $options "options" $options
"page" $page "page" $page

@ -51,4 +51,52 @@
{{ $src = $resource.RelPermalink }} {{ $src = $resource.RelPermalink }}
{{ end }} {{ end }}
{{ if and (or $height $maxheight) (not (or $maxwidth $width)) }}
{{ $width = "auto" }}
{{ end }}
{{ if and (or $maxwidth $width) (not (or $height $maxheight)) }}
{{ $height = "auto" }}
{{ end }}
{{ if $height }}
{{ with printf "height: %v" $height }}
{{ if $style }}
{{ $style = printf "%v; %v" $style . }}
{{ else }}
{{ $style = . }}
{{ end }}
{{ end }}
{{ end }}
{{ if $maxheight }}
{{ with printf "max-height: %v" $maxheight }}
{{ if $style }}
{{ $style = printf "%v; %v" $style . }}
{{ else }}
{{ $style = . }}
{{ end }}
{{ end }}
{{ end }}
{{ if $maxwidth }}
{{ with printf "max-width: %v" $maxwidth }}
{{ if $style }}
{{ $style = printf "%v; %v" $style . }}
{{ else }}
{{ $style = . }}
{{ end }}
{{ end }}
{{ end }}
{{ if $width }}
{{ with printf "width: %v" $width }}
{{ if $style }}
{{ $style = printf "%v; %v" $style . }}
{{ else }}
{{ $style = . }}
{{ end }}
{{ end }}
{{ end }}
<img {{ with $alt }} alt="{{ . }}" {{ end }} {{ with $class }} class="{{ . }}" {{ end }} crossorigin="{{ $crossorigin }}" {{ with $fetchpriority }} fetchpriority="{{ . }}" {{ end }} {{ with $intrinsicheight }} height="{{ . }}" {{ end }} loading="{{ $loading }}" referrerpolicy="{{ $referrerpolicy }}" src="{{ $src }}" {{ with $style }} style="{{ . | safeCSS }}" {{ end }} {{ with $title }} title="{{ . }}" {{ end }} {{ with $intrinsicwidth }} width="{{ . }}" {{ end }}> <img {{ with $alt }} alt="{{ . }}" {{ end }} {{ with $class }} class="{{ . }}" {{ end }} crossorigin="{{ $crossorigin }}" {{ with $fetchpriority }} fetchpriority="{{ . }}" {{ end }} {{ with $intrinsicheight }} height="{{ . }}" {{ end }} loading="{{ $loading }}" referrerpolicy="{{ $referrerpolicy }}" src="{{ $src }}" {{ with $style }} style="{{ . | safeCSS }}" {{ end }} {{ with $title }} title="{{ . }}" {{ end }} {{ with $intrinsicwidth }} width="{{ . }}" {{ end }}>

@ -4,6 +4,8 @@
{{ $image := .Get "image" }} {{ $image := .Get "image" }}
{{ $images := .Get 0 | default (.Get "images") }} {{ $images := .Get 0 | default (.Get "images") }}
{{ $justify := .Get "justify" | default "center" }} {{ $justify := .Get "justify" | default "center" }}
{{ $maxheight := .Get "maxheight" }}
{{ $maxwidth := .Get "maxwidth" }}
{{ $method := .Get "method" | default "resize" }} {{ $method := .Get "method" | default "resize" }}
{{ $options := .Get "options" | default "550x webp picture Lanczos" }} {{ $options := .Get "options" | default "550x webp picture Lanczos" }}
{{ $type := .Get "type" | default "rows" }} {{ $type := .Get "type" | default "rows" }}
@ -17,13 +19,17 @@
{{ partial "paige/image-figure.html" (dict {{ partial "paige/image-figure.html" (dict
"caption" $caption "caption" $caption
"height" $height
"link" $resource.RelPermalink "link" $resource.RelPermalink
"maxheight" $maxheight
"maxwidth" $maxwidth
"method" $method "method" $method
"options" $options "options" $options
"page" .Page "page" .Page
"resource" $resource "resource" $resource
"src" $image "src" $image
"table" true "table" true
"width" $width
) }} ) }}
{{ else }} {{ else }}
{{ $inner := chomp .Inner }} {{ $inner := chomp .Inner }}
@ -52,29 +58,39 @@
{{ else }} {{ else }}
{{ range $resources }} {{ range $resources }}
{{ partial "paige/image-figure.html" (dict {{ partial "paige/image-figure.html" (dict
"height" $height
"link" .RelPermalink "link" .RelPermalink
"maxheight" $maxheight
"maxwidth" $maxwidth
"method" $method "method" $method
"options" $options "options" $options
"resource" . "resource" .
"table" true "table" true
"width" $width
) }} ) }}
{{ end }} {{ end }}
{{ end }} {{ end }}
</div> </div>
</div> </div>
{{ else if eq $type "rows" }} {{ else if eq $type "rows" }}
{{ if not (or $height $maxheight) }}
{{ $maxheight = $maxheight | default "10rem" }}
{{ end }}
<div class="align-items-{{ $align }} column-gap-3 d-flex{{ with $caption }} figure-img{{ end }} flex-wrap justify-content-{{ $justify }} row-gap-3"> <div class="align-items-{{ $align }} column-gap-3 d-flex{{ with $caption }} figure-img{{ end }} flex-wrap justify-content-{{ $justify }} row-gap-3">
{{ with $inner }} {{ with $inner }}
{{ . }} {{ . }}
{{ else }} {{ else }}
{{ range $resources }} {{ range $resources }}
{{ partial "paige/image-figure.html" (dict {{ partial "paige/image-figure.html" (dict
"height" "10rem" "height" $height
"link" .RelPermalink "link" .RelPermalink
"maxheight" $maxheight
"maxwidth" $maxwidth
"method" $method "method" $method
"options" $options "options" $options
"resource" . "resource" .
"table" true "table" true
"width" $width
) }} ) }}
{{ end }} {{ end }}
{{ end }} {{ end }}

@ -2,6 +2,8 @@
{{ $caption := .Get "caption" }} {{ $caption := .Get "caption" }}
{{ $height := .Get "height" }} {{ $height := .Get "height" }}
{{ $link := .Get "link" }} {{ $link := .Get "link" }}
{{ $maxheight := .Get "maxheight" }}
{{ $maxwidth := .Get "maxwidth" }}
{{ $method := .Get "method" }} {{ $method := .Get "method" }}
{{ $options := .Get "options" }} {{ $options := .Get "options" }}
{{ $src := .Get 0 | default (.Get "src") }} {{ $src := .Get 0 | default (.Get "src") }}
@ -13,6 +15,8 @@
"caption" $caption "caption" $caption
"height" $height "height" $height
"link" $link "link" $link
"maxheight" $maxheight
"maxwidth" $maxwidth
"method" $method "method" $method
"options" $options "options" $options
"src" $src "src" $src

Loading…
Cancel
Save