diff --git a/README.md b/README.md index 704ec466..3f48155b 100644 --- a/README.md +++ b/README.md @@ -586,6 +586,8 @@ The `paige/image` shortcode provides a figure with a centered image. caption="My caption" height="10rem" link="https://github.com/willfaught/paige" + maxheight="10rem" + maxwidth="10rem" method="resize" options="550x webp picture Lanczos" src="me.jpg" @@ -604,6 +606,10 @@ Parameters:
Optional. Image height in pixels.
link
Optional. URL. Image link.
+
maxheight
+
Optional. Maximum image height.
+
maxwidth
+
Optional. Maximum image width.
method
Optional. Hugo image processing method. Must be crop, fill, fit, or resize. Must be specified with options. See Image Processing Methods.
options
@@ -631,6 +637,8 @@ The `paige/gallery` shortcode provides a figure with a centered list of images. height="10rem" images="*.jpg" justify="center" + maxheight="10rem" + maxwidth="10rem" method="resize" options="550x webp picture Lanczos" type="list" @@ -655,13 +663,17 @@ Parameters:
caption
Optional. Markdown. Descriptive text that appears centered below the images.
height
-
Optional. Height of the image or images.
+
Optional. Height of the image or images in pixels.
image
Optional. Page, site, or remote image glob. Only used in the inner content of this shortcode.
images
Optional. Unnamed argument. Page, site, or remote images glob. Defaults to all image page resources.
justify
Optional. Flexbox main axis space distribution. Must be start, center, end, etc. See justify-content.
+
maxheight
+
Optional. Maximum height of the image or images.
+
maxwidth
+
Optional. Maximum width of the image or images.
method
Optional. Hugo image processing method. Must be crop, fill, fit, or resize. Default is resize. Must be specified with options. See Image Processing Methods.
options
@@ -669,7 +681,7 @@ Parameters:
type
Optional. Type of layout. Must be grid or list. Default is list.
width
-
Optional. Width of the image or images.
+
Optional. Width of the image or images in pixels.
## Customization diff --git a/layouts/partials/paige/image-figure.html b/layouts/partials/paige/image-figure.html index d458a7df..a674df19 100644 --- a/layouts/partials/paige/image-figure.html +++ b/layouts/partials/paige/image-figure.html @@ -2,6 +2,8 @@ {{ $caption := .caption }} {{ $height := .height }} {{ $link := .link }} +{{ $maxheight := .maxheight }} +{{ $maxwidth := .maxwidth }} {{ $method := .method }} {{ $options := .options }} {{ $page := .page }} @@ -20,6 +22,8 @@ "alt" $alt "class" $class "height" $height + "maxheight" $maxheight + "maxwidth" $maxwidth "method" $method "options" $options "page" $page diff --git a/layouts/partials/paige/img.html b/layouts/partials/paige/img.html index 0c5f5364..4d68975b 100644 --- a/layouts/partials/paige/img.html +++ b/layouts/partials/paige/img.html @@ -51,4 +51,52 @@ {{ $src = $resource.RelPermalink }} {{ 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 }} + {{ . }} diff --git a/layouts/shortcodes/paige/gallery.html b/layouts/shortcodes/paige/gallery.html index 0e2215d3..49e13d51 100644 --- a/layouts/shortcodes/paige/gallery.html +++ b/layouts/shortcodes/paige/gallery.html @@ -4,6 +4,8 @@ {{ $image := .Get "image" }} {{ $images := .Get 0 | default (.Get "images") }} {{ $justify := .Get "justify" | default "center" }} +{{ $maxheight := .Get "maxheight" }} +{{ $maxwidth := .Get "maxwidth" }} {{ $method := .Get "method" | default "resize" }} {{ $options := .Get "options" | default "550x webp picture Lanczos" }} {{ $type := .Get "type" | default "rows" }} @@ -17,13 +19,17 @@ {{ partial "paige/image-figure.html" (dict "caption" $caption + "height" $height "link" $resource.RelPermalink + "maxheight" $maxheight + "maxwidth" $maxwidth "method" $method "options" $options "page" .Page "resource" $resource "src" $image "table" true + "width" $width ) }} {{ else }} {{ $inner := chomp .Inner }} @@ -52,29 +58,39 @@ {{ else }} {{ range $resources }} {{ partial "paige/image-figure.html" (dict + "height" $height "link" .RelPermalink + "maxheight" $maxheight + "maxwidth" $maxwidth "method" $method "options" $options "resource" . "table" true + "width" $width ) }} {{ end }} {{ end }} {{ else if eq $type "rows" }} + {{ if not (or $height $maxheight) }} + {{ $maxheight = $maxheight | default "10rem" }} + {{ end }}
{{ with $inner }} {{ . }} {{ else }} {{ range $resources }} {{ partial "paige/image-figure.html" (dict - "height" "10rem" + "height" $height "link" .RelPermalink + "maxheight" $maxheight + "maxwidth" $maxwidth "method" $method "options" $options "resource" . "table" true + "width" $width ) }} {{ end }} {{ end }} diff --git a/layouts/shortcodes/paige/image.html b/layouts/shortcodes/paige/image.html index c71ff3d7..87cb5c4c 100644 --- a/layouts/shortcodes/paige/image.html +++ b/layouts/shortcodes/paige/image.html @@ -2,6 +2,8 @@ {{ $caption := .Get "caption" }} {{ $height := .Get "height" }} {{ $link := .Get "link" }} +{{ $maxheight := .Get "maxheight" }} +{{ $maxwidth := .Get "maxwidth" }} {{ $method := .Get "method" }} {{ $options := .Get "options" }} {{ $src := .Get 0 | default (.Get "src") }} @@ -13,6 +15,8 @@ "caption" $caption "height" $height "link" $link + "maxheight" $maxheight + "maxwidth" $maxwidth "method" $method "options" $options "src" $src