From 025935f6bdd8bf930b8125df8fa8bb8b402c88f6 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Thu, 19 Jan 2023 21:46:07 -0800 Subject: [PATCH] Add number, numbered shortcode params --- README.md | 6 ++++++ i18n/en.yaml | 3 +++ layouts/partials/paige/figure.html | 23 ++++++++++++++++++++--- layouts/partials/paige/image-figure.html | 4 ++++ layouts/partials/paige/style.html | 13 +++++++++++++ layouts/shortcodes/paige/code.html | 4 ++++ layouts/shortcodes/paige/figure.html | 4 ++++ layouts/shortcodes/paige/gallery.html | 20 ++++++++++++++++++-- layouts/shortcodes/paige/image.html | 4 ++++ layouts/shortcodes/paige/quote.html | 4 ++++ 10 files changed, 80 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c703ec0d..0dfc4c1c 100644 --- a/README.md +++ b/README.md @@ -519,6 +519,8 @@ The `paige/figure` shortcode provides a figure with content. justify="center" maxheight="10rem" maxwidth="10rem" + number=0 + numbered=false width="10rem" >}} My content @@ -544,6 +546,10 @@ Parameters:
Optional. String. CSS value. Maximum total height.
maxwidth
Optional. String. CSS value. Maximum total width.
+
number
+
Optional. Integer or string. Figure number. Displayed with the caption.
+
numbered
+
Optional. Boolean. Number the figure automatically. Displayed with the caption.
width
Optional. String. CSS value. Total width.
diff --git a/i18n/en.yaml b/i18n/en.yaml index 9cae3f8e..18ad88d0 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -1,3 +1,6 @@ +paige_figure: + other: Figure + paige_noscript: other: JavaScript is required. diff --git a/layouts/partials/paige/figure.html b/layouts/partials/paige/figure.html index 73f3a22d..81776b29 100644 --- a/layouts/partials/paige/figure.html +++ b/layouts/partials/paige/figure.html @@ -8,6 +8,8 @@ {{ $justify := .justify | default "center" }} {{ $maxheight := .maxheight }} {{ $maxwidth := .maxwidth }} +{{ $number := .number }} +{{ $numbered := .numbered }} {{ $width := .width }} {{ $table := false }} @@ -70,7 +72,22 @@ {{ end }} {{ end }} -
+{{ $showcaption := $caption }} + +{{ if $caption }} + {{ if $number }} + {{ $caption = printf "%v %v: %v" (i18n "paige_figure") $number $caption }} + {{ end }} +{{ else }} + {{ if $number }} + {{ $caption = printf "%v %v" (i18n "paige_figure") $number }} + {{ $showcaption = true }} + {{ else if $numbered }} + {{ $showcaption = true }} + {{ end }} +{{ end }} + +
{{ if and (not $float) $style }}
{{ end }} @@ -78,8 +95,8 @@
{{ end }}
{{ $content }}
- {{ with $caption }} -
{{ . }}
+ {{ if $showcaption }} +
{{ $caption }}
{{ end }} {{ if $table }}
diff --git a/layouts/partials/paige/image-figure.html b/layouts/partials/paige/image-figure.html index 3dc765bf..b095c3ef 100644 --- a/layouts/partials/paige/image-figure.html +++ b/layouts/partials/paige/image-figure.html @@ -7,6 +7,8 @@ {{ $maxheight := .maxheight }} {{ $maxwidth := .maxwidth }} {{ $method := .method }} +{{ $number := .number }} +{{ $numbered := .numbered }} {{ $options := .options }} {{ $page := .page }} {{ $raw := .raw }} @@ -43,5 +45,7 @@ "height" $height "maxheight" $maxheight "maxwidth" $maxwidth + "number" $number + "numbered" $numbered "width" $width ) }} diff --git a/layouts/partials/paige/style.html b/layouts/partials/paige/style.html index 3eed9e65..06eb5ef7 100644 --- a/layouts/partials/paige/style.html +++ b/layouts/partials/paige/style.html @@ -4,9 +4,22 @@ body, html { } section[class="paige-content"] { + counter-reset: paige-figure; max-width: 100%; } +section[class="paige-content"] figure.paige-figure.paige-figure-numbered { + counter-increment: paige-figure; +} + +section[class="paige-content"] figure.paige-figure.paige-figure-numbered figcaption:empty::before { + content: "{{ i18n `paige_figure` }} " counter(paige-figure); +} + +section[class="paige-content"] figure.paige-figure.paige-figure-numbered figcaption::before { + content: "{{ i18n `paige_figure` }} " counter(paige-figure) ": "; +} + section[class="paige-content"] > blockquote { padding: 0.5rem 1rem; border-left: 0.25rem solid var(--bs-border-color); diff --git a/layouts/shortcodes/paige/code.html b/layouts/shortcodes/paige/code.html index 403a6a40..43801ad1 100644 --- a/layouts/shortcodes/paige/code.html +++ b/layouts/shortcodes/paige/code.html @@ -6,6 +6,8 @@ {{ $lang := .Get 0 | default (.Get "lang") | default "plaintext" }} {{ $maxheight := .Get "maxheight" }} {{ $maxwidth := .Get "maxwidth" }} +{{ $number := .Get "number" }} +{{ $numbered := .Get "numbered" }} {{ $options := .Get "options" }} {{ $width := .Get "width" }} @@ -21,5 +23,7 @@ "justify" $justify "maxheight" $maxheight "maxwidth" $maxwidth + "number" $number + "numbered" $numbered "width" $width ) }} diff --git a/layouts/shortcodes/paige/figure.html b/layouts/shortcodes/paige/figure.html index 1f6b8915..60e78712 100644 --- a/layouts/shortcodes/paige/figure.html +++ b/layouts/shortcodes/paige/figure.html @@ -6,6 +6,8 @@ {{ $justify := .Get "justify" }} {{ $maxheight := .Get "maxheight" }} {{ $maxwidth := .Get "maxwidth" }} +{{ $number := .Get "number" }} +{{ $numbered := .Get "numbered" }} {{ $width := .Get "width" }} {{ partial "paige/figure.html" (dict @@ -18,5 +20,7 @@ "justify" $justify "maxheight" $maxheight "maxwidth" $maxwidth + "number" $number + "numbered" $numbered "width" $width ) }} diff --git a/layouts/shortcodes/paige/gallery.html b/layouts/shortcodes/paige/gallery.html index a9006956..46b66ef8 100644 --- a/layouts/shortcodes/paige/gallery.html +++ b/layouts/shortcodes/paige/gallery.html @@ -7,6 +7,8 @@ {{ $maxheight := .Get "maxheight" }} {{ $maxwidth := .Get "maxwidth" }} {{ $method := .Get "method" | default "resize" }} +{{ $number := .Get "number" }} +{{ $numbered := .Get "numbered" }} {{ $options := .Get "options" | default "550x webp picture Lanczos" }} {{ $raw := .Get "raw" }} {{ $type := .Get "type" | default "rows" }} @@ -61,6 +63,7 @@ {{ else }} {{ $inner := chomp .Inner }} {{ $resources := slice }} + {{ $showcaption := $caption }} {{ with $images }} {{ with $.Page.Resources.Match . }} @@ -76,6 +79,19 @@ {{ end }} {{ end }} + {{ if $caption }} + {{ if $number }} + {{ $caption = printf "%v %v: %v" (i18n "paige_figure") $number $caption }} + {{ end }} + {{ else }} + {{ if $number }} + {{ $caption = printf "%v %v" (i18n "paige_figure") $number }} + {{ $showcaption = true }} + {{ else if $numbered }} + {{ $showcaption = true }} + {{ end }} + {{ end }} +
{{ if eq $type "grid" }}
@@ -128,8 +144,8 @@ {{ else }} {{ errorf "invalid type: %q" $type }} {{ end }} - {{ with $caption }} -
{{ . }}
+ {{ if $showcaption }} +
{{ $caption }}
{{ end }}
{{ end }} diff --git a/layouts/shortcodes/paige/image.html b/layouts/shortcodes/paige/image.html index eab215be..6ec01b54 100644 --- a/layouts/shortcodes/paige/image.html +++ b/layouts/shortcodes/paige/image.html @@ -8,6 +8,8 @@ {{ $maxheight := .Get "maxheight" }} {{ $maxwidth := .Get "maxwidth" }} {{ $method := .Get "method" }} +{{ $number := .Get "number" }} +{{ $numbered := .Get "numbered" }} {{ $options := .Get "options" }} {{ $raw := .Get "raw" }} {{ $src := .Get 0 | default (.Get "src") }} @@ -26,6 +28,8 @@ "maxheight" $maxheight "maxwidth" $maxwidth "method" $method + "number" $number + "numbered" $numbered "options" $options "raw" $raw "src" $src diff --git a/layouts/shortcodes/paige/quote.html b/layouts/shortcodes/paige/quote.html index 30aed100..d1b892a3 100644 --- a/layouts/shortcodes/paige/quote.html +++ b/layouts/shortcodes/paige/quote.html @@ -6,6 +6,8 @@ {{ $justify := .Get "justify" }} {{ $maxheight := .Get "maxheight" }} {{ $maxwidth := .Get "maxwidth" }} +{{ $number := .Get "number" }} +{{ $numbered := .Get "numbered" }} {{ $width := .Get "width" }} {{ $content = printf `
%v
` $content }} @@ -19,5 +21,7 @@ "justify" $justify "maxheight" $maxheight "maxwidth" $maxwidth + "number" $number + "numbered" $numbered "width" $width ) }}