diff --git a/README.md b/README.md index 897b79f5..9262371e 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,10 @@ paige: utterances: # utteranc.es github_repo: "example/foo" date_format: "2006 January 2" # Hugo date format for page dates + gallery: # Inherited by the paige/gallery and paige/gallery/item shortcodes + display: "list" # Display images in a grid or list; values are "grid", "list"; default is "grid" + method: "resize" # Hugo image processing method; values are "crop", "fill", "fit", "resize"; default is "resize" + options: "550x webp picture Lanczos" # Hugo image processing options; default is "550x webp picture Lanczos" hide_theme_comment: true # Don't put a link to this project in a code comment hide_theme_link: true # Don't put a link to this project in the footer math: @@ -275,6 +279,10 @@ authors: [ ] link: "https://youtu.be/dQw4w9WgXcQ" # The reference for an anchor around the title paige: + gallery: # Inherited by the paige/gallery and paige/gallery/item shortcodes + display: "list" # Display images in a grid or list; values are "grid", "list"; default is "grid" + method: "resize" # Hugo image processing method; values are "crop", "fill", "fit", "resize"; default is "resize" + options: "550x webp picture Lanczos" # Hugo image processing options; default is "550x webp picture Lanczos" math: true # Enable math typesetting with KaTeX toc: true # Show a table of contents if there are any headers ``` @@ -511,6 +519,62 @@ These are the the named parameters with positions: {{< /paige/code >}} ``` +### Gallery + +The `paige/gallery` shortcode provides a figure with a set of images and an optional, centered caption. + +``` +{{< paige/gallery + + // Page resource image file name or pattern; optional; defaults to all images + images="birthday*.jpg" + + // Optional + caption="My caption" + + // Hugo image processing method; optional; values are "crop", "fill", "fit", "resize"; default is "resize" + method="resize" + + // Hugo image processing options; optional; default is "550x webp picture Lanczos" + options="550x webp picture Lanczos" + + // Display images in a grid or list; optional; values are "grid", "list"; default is "grid" + display="grid" + +/>}} +``` + +The `paige/gallery/item` shortcode is nested within the `paige/gallery` shortcode to provide a caption and customization per image. +The display type is automatically list, and cannot be overridden. + +``` +{{< paige/gallery caption="My caption" method="resize" options="550x webp picture Lanczos" >}} + + {{< paige/gallery/item + + // Page resource image file name or pattern + image="birthday1.jpg" + + // Optional + caption="My caption" + + // Optional + method="resize" + + // Optional + options="550x webp picture Lanczos" + + >}} + +{{< /paige/gallery >}} +``` + +The `paige/gallery` shortcode must be self-closing if the `paige/gallery/item` shortcode is not used. + +``` +{{< paige/gallery />}} +``` + ## Customization If `partials/paige/head-last.html` exists in the site, it is included at the end of the head tag. diff --git a/layouts/partials/paige/gallery-item.html b/layouts/partials/paige/gallery-item.html new file mode 100644 index 00000000..4c117910 --- /dev/null +++ b/layouts/partials/paige/gallery-item.html @@ -0,0 +1,26 @@ +{{ $image := .image }} +{{ $caption := .caption }} +{{ $method := .method }} +{{ $options := .options }} + +{{ $thumbnail := $image }} +{{ with $image }} + {{ if eq $method "crop" }} + {{ $thumbnail = .Crop $options }} + {{ else if eq $method "fill" }} + {{ $thumbnail = .Fill $options }} + {{ else if eq $method "fit" }} + {{ $thumbnail = .Fit $options }} + {{ else if eq $method "resize" }} + {{ $thumbnail = .Resize $options }} + {{ end }} +{{ end }} + + + + + + {{ with $caption }} + {{ . }} + {{ end }} + diff --git a/layouts/shortcodes/paige/gallery.html b/layouts/shortcodes/paige/gallery.html new file mode 100644 index 00000000..653495e8 --- /dev/null +++ b/layouts/shortcodes/paige/gallery.html @@ -0,0 +1,58 @@ +{{ $images := .Get "images" }} +{{ $caption := .Get "caption" }} +{{ $method := .Get "method" | default .Page.Params.paige.gallery.method | default .Page.Site.Params.paige.gallery.method | default "resize" }} +{{ $options := .Get "options" | default .Page.Params.paige.gallery.options | default .Page.Site.Params.paige.gallery.options | default "550x webp picture Lanczos" }} +{{ $display := .Get "display" | default .Page.Params.paige.gallery.display | default .Page.Site.Params.paige.gallery.display | default "grid" }} + +{{ $inner := chomp .Inner }} + +{{ if $inner }} + {{ $display = "list" }} +{{ end }} + +{{ $resources := slice }} +{{ with $images }} + {{ $resources = $.Page.Resources.Match . }} +{{ else }} + {{ $resources = .Page.Resources.ByType "image" }} +{{ end }} + +{{ $cols := "col-12 col-md-6 col-lg-4 col-xl-3 col-xxl-2" }} +{{ with len $resources }} + {{ if eq . 1 }} + {{ $cols = "col-12" }} + {{ else if eq . 2 }} + {{ $cols = "col-12 col-md-6" }} + {{ else if eq . 3 }} + {{ $cols = "col-12 col-md-6 col-lg-4" }} + {{ else if eq . 4 }} + {{ $cols = "col-12 col-md-6 col-lg-4 col-xl-3" }} + {{ end }} +{{ end }} + + + {{ if eq $display "grid" }} + + + {{ range $resources }} + + {{ partial "paige/gallery-item.html" (dict "image" . "method" $method "options" $options) }} + + {{ end }} + + + {{ else if eq $display "list" }} + + {{ with $inner }} + {{ . }} + {{ else }} + {{ range $resources }} + {{ partial "paige/gallery-item.html" (dict "image" . "method" $method "options" $options) }} + {{ end }} + {{ end }} + + {{ end }} + {{ with $caption }} + {{ . }} + {{ end }} + diff --git a/layouts/shortcodes/paige/gallery/item.html b/layouts/shortcodes/paige/gallery/item.html new file mode 100644 index 00000000..b255ea1c --- /dev/null +++ b/layouts/shortcodes/paige/gallery/item.html @@ -0,0 +1,5 @@ +{{ $image := .Page.Resources.GetMatch (.Get 0 | default (.Get "image")) }} +{{ $caption := .Get "caption" }} +{{ $method := .Get "method" | default .Page.Params.paige.gallery.method | default .Page.Site.Params.paige.gallery.method | default "resize" }} +{{ $options := .Get "options" | default .Page.Params.paige.gallery.options | default .Page.Site.Params.paige.gallery.options | default "550x webp picture Lanczos" }} +{{ partial "paige/gallery-item.html" (dict "image" $image "caption" $caption "method" $method "options" $options) }} diff --git a/theme.toml b/theme.toml index 725ef8fc..aa71f9ba 100644 --- a/theme.toml +++ b/theme.toml @@ -31,12 +31,14 @@ tags = [ "bootstrap", "contact", "dark", + "gallery", "hero", "landing", "light", "minimal", "multilingual", "personal", + "portfolio", "responsive" ]