From 809ddf9efbdc34061cd27307b471b338269f726f Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Thu, 16 Jan 2025 07:42:04 -0800 Subject: [PATCH] Update theme --- .../components/author-github-data-card.html | 8 +- .../components/author-github-data.html | 8 +- .../partials/utilities/get-remote-data.html | 8 +- .../gohugoioTheme/layouts/shortcodes/hl.html | 11 + .../gohugoioTheme/layouts/shortcodes/img.html | 26 +- _vendor/modules.txt | 2 +- go.mod | 2 +- go.sum | 4 +- .../components/author-github-data-card.html | 43 -- .../components/author-github-data.html | 36 -- .../partials/utilities/get-remote-data.html | 23 -- layouts/shortcodes/hl.html | 4 - layouts/shortcodes/img.html | 391 ------------------ 13 files changed, 45 insertions(+), 521 deletions(-) create mode 100644 _vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/hl.html delete mode 100644 layouts/partials/components/author-github-data-card.html delete mode 100644 layouts/partials/components/author-github-data.html delete mode 100644 layouts/partials/utilities/get-remote-data.html delete mode 100644 layouts/shortcodes/hl.html delete mode 100644 layouts/shortcodes/img.html diff --git a/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/components/author-github-data-card.html b/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/components/author-github-data-card.html index 4caa21f3e..d3edadaac 100644 --- a/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/components/author-github-data-card.html +++ b/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/components/author-github-data-card.html @@ -4,14 +4,14 @@ {{ $data := "" }} {{ $url := urls.JoinPath "https://api.github.com/users" $author }} - {{ with resources.GetRemote $url }} + {{ with try (resources.GetRemote $url) }} {{ with .Err }} {{ errorf "%s" . }} - {{ else }} + {{ else with .Value }} {{ $data = . | transform.Unmarshal }} + {{ else }} + {{ errorf "Unable to get remote resource %q" $url }} {{ end }} - {{ else }} - {{ errorf "Unable to get remote resource %q" $url }} {{ end }}
diff --git a/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/components/author-github-data.html b/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/components/author-github-data.html index fbad3a0a7..c281e411f 100644 --- a/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/components/author-github-data.html +++ b/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/components/author-github-data.html @@ -4,14 +4,14 @@ {{ $data := "" }} {{ $url := urls.JoinPath "https://api.github.com/users" $author }} - {{ with resources.GetRemote $url }} + {{ with try (resources.GetRemote $url) }} {{ with .Err }} {{ errorf "%s" . }} - {{ else }} + {{ else with .Value }} {{ $data = . | transform.Unmarshal }} + {{ else }} + {{ errorf "Unable to get remote resource %q" $url }} {{ end }} - {{ else }} - {{ errorf "Unable to get remote resource %q" $url }} {{ end }} {{ with $data }} diff --git a/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/utilities/get-remote-data.html b/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/utilities/get-remote-data.html index 69ac41da4..78b2ba06e 100644 --- a/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/utilities/get-remote-data.html +++ b/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/utilities/get-remote-data.html @@ -11,13 +11,13 @@ Supports CSV, JSON, TOML, YAML, and XML. {{ $url := . }} {{ $data := dict }} -{{ with resources.GetRemote $url }} +{{ with try (resources.GetRemote $url) }} {{ with .Err }} {{ errorf "%s" . }} - {{ else }} + {{ else with .Value }} {{ $data = .Content | transform.Unmarshal }} + {{ else }} + {{ errorf "Unable to get remote resource %q" $url }} {{ end }} -{{ else }} - {{ errorf "Unable to get remote resource %q" $url }} {{ end }} {{ return $data }} diff --git a/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/hl.html b/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/hl.html new file mode 100644 index 000000000..1a5b4e1ec --- /dev/null +++ b/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/hl.html @@ -0,0 +1,11 @@ +{{- /* +Returns syntax-highlighted code from the given text. + +This is useful as a terse way to highlight inline code snippets. Calling the +highlight shortcode for inline snippets is verbose. +*/}} + +{{- $code := .Inner | strings.TrimSpace }} +{{- $lang := or (.Get 0) "go" }} +{{- $opts := dict "hl_inline" true "noClasses" true }} +{{- transform.Highlight $code $lang $opts }} diff --git a/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/img.html b/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/img.html index dd8c60e18..7c2d805d2 100644 --- a/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/img.html +++ b/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/img.html @@ -120,8 +120,8 @@ Renders the given image using the given filter, if any. {{- $validFilters := slice "autoorient" "brightness" "colorbalance" "colorize" "contrast" "dither" - "gamma" "gaussianblur" "grayscale" "hue" "invert" "none" "opacity" "overlay" - "padding" "pixelate" "process" "saturation" "sepia" "sigmoid" "text" + "gamma" "gaussianblur" "grayscale" "hue" "invert" "mask" "none" "opacity" + "overlay" "padding" "pixelate" "process" "saturation" "sepia" "sigmoid" "text" "unsharpmask" }} @@ -229,6 +229,12 @@ Renders the given image using the given filter, if any. {{- $ctx = merge $ctx (dict "argsRequired" 0) }} {{- template "validate-arg-count" $ctx }} {{- $f = images.Invert }} +{{- else if eq $filter "mask" }} + {{- $ctx = merge $ctx (dict "argsRequired" 1) }} + {{- template "validate-arg-count" $ctx }} + {{- $ctx := dict "src" (index $filterArgs 0) "name" .Name "position" .Position }} + {{- $maskImage := partial "inline/get-resource.html" $ctx }} + {{- $f = images.Mask $maskImage }} {{- else if eq $filter "opacity" }} {{- $ctx = merge $ctx (dict "argsRequired" 1) }} {{- template "validate-arg-count" $ctx }} @@ -322,11 +328,15 @@ Renders the given image using the given filter, if any. {{- end }} {{- /* Render. */}} +{{- $class := "di va b--black-20" }} +{{- if eq $filter "mask" }} + {{- $class = "di va" }} +{{- end }} {{- if $example }}

Original

- {{ $alt }} + {{ $alt }}

Processed

- {{ $alt }} + {{ $alt }} {{- else -}} {{ $alt }} {{- end }} @@ -354,15 +364,15 @@ Renders the given image using the given filter, if any. {{- $u := urls.Parse .src }} {{- $msg := "The %q shortcode was unable to resolve %s. See %s" }} {{- if $u.IsAbs }} - {{- with resources.GetRemote $u.String }} + {{- with try (resources.GetRemote $u.String) }} {{- with .Err }} {{- errorf "%s" . }} - {{- else }} + {{- else with .Value }} {{- /* This is a remote resource. */}} {{- $r = . }} + {{- else }} + {{- errorf $msg $.name $u.String $.position }} {{- end }} - {{- else }} - {{- errorf $msg $.name $u.String $.position }} {{- end }} {{- else }} {{- with .page.Resources.Get (strings.TrimPrefix "./" $u.Path) }} diff --git a/_vendor/modules.txt b/_vendor/modules.txt index 191983b98..50178323d 100644 --- a/_vendor/modules.txt +++ b/_vendor/modules.txt @@ -1 +1 @@ -# github.com/gohugoio/gohugoioTheme v0.0.0-20250116044755-d81e594dfa4b +# github.com/gohugoio/gohugoioTheme v0.0.0-20250116152525-2d382cae7743 diff --git a/go.mod b/go.mod index 958a0fa33..56a48deac 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/gohugoio/hugoDocs go 1.22.0 -require github.com/gohugoio/gohugoioTheme v0.0.0-20250116044755-d81e594dfa4b // indirect +require github.com/gohugoio/gohugoioTheme v0.0.0-20250116152525-2d382cae7743 // indirect diff --git a/go.sum b/go.sum index db5c5b89a..af9b5febf 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -github.com/gohugoio/gohugoioTheme v0.0.0-20250116044755-d81e594dfa4b h1:7CzDZzxF5rzaOp5MnK/GGUTgh/73uKYyksbUGtiFv7Q= -github.com/gohugoio/gohugoioTheme v0.0.0-20250116044755-d81e594dfa4b/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM= +github.com/gohugoio/gohugoioTheme v0.0.0-20250116152525-2d382cae7743 h1:gjoqq8+RnGwpuU/LQVYGGR/LsDplrfUjOabWwoROYsM= +github.com/gohugoio/gohugoioTheme v0.0.0-20250116152525-2d382cae7743/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM= diff --git a/layouts/partials/components/author-github-data-card.html b/layouts/partials/components/author-github-data-card.html deleted file mode 100644 index d3edadaac..000000000 --- a/layouts/partials/components/author-github-data-card.html +++ /dev/null @@ -1,43 +0,0 @@ -{{ $author := .context.Params.author }} -{{ if $author }} - -{{ end }} diff --git a/layouts/partials/components/author-github-data.html b/layouts/partials/components/author-github-data.html deleted file mode 100644 index c281e411f..000000000 --- a/layouts/partials/components/author-github-data.html +++ /dev/null @@ -1,36 +0,0 @@ -{{ $author := .context.Params.author }} -{{ if $author }} - -{{ end }} diff --git a/layouts/partials/utilities/get-remote-data.html b/layouts/partials/utilities/get-remote-data.html deleted file mode 100644 index 78b2ba06e..000000000 --- a/layouts/partials/utilities/get-remote-data.html +++ /dev/null @@ -1,23 +0,0 @@ -{{/* -Parses the serialized data from the given URL and returns a map or an array. - -Supports CSV, JSON, TOML, YAML, and XML. - -@param {string} . The URL from which to retrieve the serialized data. -@returns {any} - -@example {{ partial "get-remote-data.html" "https://example.org/foo.json" }} -*/}} - -{{ $url := . }} -{{ $data := dict }} -{{ with try (resources.GetRemote $url) }} - {{ with .Err }} - {{ errorf "%s" . }} - {{ else with .Value }} - {{ $data = .Content | transform.Unmarshal }} - {{ else }} - {{ errorf "Unable to get remote resource %q" $url }} - {{ end }} -{{ end }} -{{ return $data }} diff --git a/layouts/shortcodes/hl.html b/layouts/shortcodes/hl.html deleted file mode 100644 index 55dd5c5fc..000000000 --- a/layouts/shortcodes/hl.html +++ /dev/null @@ -1,4 +0,0 @@ -{{ $code := .Inner | strings.TrimSpace }} -{{ $lang := or (.Get 0) "go" }} -{{ $opts := dict "hl_inline" true "noClasses" true }} -{{ transform.Highlight $code $lang $opts }} diff --git a/layouts/shortcodes/img.html b/layouts/shortcodes/img.html deleted file mode 100644 index 7c2d805d2..000000000 --- a/layouts/shortcodes/img.html +++ /dev/null @@ -1,391 +0,0 @@ -{{- /* -Renders the given image using the given filter, if any. - -@param {string} src The path to the image which must be a remote, page, or global resource. -@param {string} [filter] The filter to apply to the image (case-insensitive). -@param {string} [filterArgs] A comma-delimited list of arguments to pass to the filter. -@param {bool} [example=false] If true, renders a before/after example. -@param {int} [exampleWidth=384] Image width, in pixels, when rendering a before/after example. - -@returns {template.HTML} - -@examples - - {{< img src="zion-national-park.jpg" >}} - - {{< img src="zion-national-park.jpg" alt="Zion National Park" >}} - - {{< img - src="zion-national-park.jpg" - alt="Zion National Park" - filter="grayscale" - >}} - - {{< img - src="zion-national-park.jpg" - alt="Zion National Park" - filter="process" - filterArgs="resize 400x webp" - >}} - - {{< img - src="zion-national-park.jpg" - alt="Zion National Park" - filter="colorize" - filterArgs="180,50,20" - >}} - - {{< img - src="zion-national-park.jpg" - alt="Zion National Park" - filter="grayscale" - example=true - >}} - - {{< img - src="zion-national-park.jpg" - alt="Zion National Park" - filter="grayscale" - example=true - exampleWidth=400 - >}} - - When using the text filter, provide the arguments in this order: - - 0. The text - 1. The horizontal offset, in pixels, relative to the left of the image (default 20) - 2. The vertical offset, in pixels, relative to the top of the image (default 20) - 3. The font size in pixels (default 64) - 4. The line height (default 1.2) - 5. The font color (default #ffffff) - - {{< img - src="images/examples/zion-national-park.jpg" - alt="Zion National Park" - filter="Text" - filterArgs="Zion National Park,25,250,56" - example=true - >}} - - When using the padding filter, provide all arguments in this order: - - 0. Padding top - 1. Padding right - 2. Padding bottom - 3. Padding right - 4. Canvas color - - {{< img - src="images/examples/zion-national-park.jpg" - alt="Zion National Park" - filter="Padding" - filterArgs="20,50,20,50,#0705" - example=true - >}} - -*/}} - -{{- /* Initialize. */}} -{{- $alt := "" }} -{{- $src := "" }} -{{- $filter := "" }} -{{- $filterArgs := slice }} -{{- $example := false }} -{{- $exampleWidth := 384 }} - -{{- /* Default values to use with the text filter. */}} -{{ $textFilterOpts := dict - "xOffset" 20 - "yOffset" 20 - "fontSize" 64 - "lineHeight" 1.2 - "fontColor" "#ffffff" - "fontPath" "https://github.com/google/fonts/raw/main/ofl/lato/Lato-Regular.ttf" -}} - -{{- /* Get and validate parameters. */}} -{{- with .Get "alt" }} - {{- $alt = .}} -{{- end }} - -{{- with .Get "src" }} - {{- $src = . }} -{{- else }} - {{- errorf "The %q shortcode requires a file parameter. See %s" .Name .Position }} -{{- end }} - -{{- with .Get "filter" }} - {{- $filter = . | lower }} -{{- end }} - -{{- $validFilters := slice - "autoorient" "brightness" "colorbalance" "colorize" "contrast" "dither" - "gamma" "gaussianblur" "grayscale" "hue" "invert" "mask" "none" "opacity" - "overlay" "padding" "pixelate" "process" "saturation" "sepia" "sigmoid" "text" - "unsharpmask" -}} - -{{- with $filter }} - {{- if not (in $validFilters .) }} - {{- errorf "The filter passed to the %q shortcode is invalid. The filter must be one of %s. See %s" $.Name (delimit $validFilters ", " ", or ") $.Position }} - {{- end }} -{{- end }} - -{{- with .Get "filterArgs" }} - {{- $filterArgs = split . "," }} - {{- $filterArgs = apply $filterArgs "trim" "." " " }} -{{- end }} - -{{- if in (slice "false" false 0) (.Get "example") }} - {{- $example = false }} -{{- else if in (slice "true" true 1) (.Get "example")}} - {{- $example = true }} -{{- end }} - -{{- with .Get "exampleWidth" }} - {{- $exampleWidth = . | int }} -{{- end }} - -{{- /* Get image. */}} -{{- $ctx := dict "page" .Page "src" $src "name" .Name "position" .Position }} -{{- $i := partial "inline/get-resource.html" $ctx }} - -{{- /* Resize if rendering before/after examples. */}} -{{- if $example }} - {{- $i = $i.Resize (printf "%dx" $exampleWidth) }} -{{- end }} - -{{- /* Create filter. */}} -{{- $f := "" }} -{{- $ctx := dict "filter" $filter "args" $filterArgs "name" .Name "position" .Position }} -{{- if eq $filter "autoorient" }} - {{- $ctx = merge $ctx (dict "argsRequired" 0) }} - {{- template "validate-arg-count" $ctx }} - {{- $f = images.AutoOrient }} -{{- else if eq $filter "brightness" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "percentage" "argValue" (index $filterArgs 0) "min" -100 "max" 100) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.Brightness (index $filterArgs 0) }} -{{- else if eq $filter "colorbalance" }} - {{- $ctx = merge $ctx (dict "argsRequired" 3) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "percentage red" "argValue" (index $filterArgs 0) "min" -100 "max" 500) }} - {{- template "validate-arg-value" $ctx }} - {{- $ctx = merge $ctx (dict "argName" "percentage green" "argValue" (index $filterArgs 1) "min" -100 "max" 500) }} - {{- template "validate-arg-value" $ctx }} - {{- $ctx = merge $ctx (dict "argName" "percentage blue" "argValue" (index $filterArgs 2) "min" -100 "max" 500) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.ColorBalance (index $filterArgs 0) (index $filterArgs 1) (index $filterArgs 2) }} -{{- else if eq $filter "colorize" }} - {{- $ctx = merge $ctx (dict "argsRequired" 3) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "hue" "argValue" (index $filterArgs 0) "min" 0 "max" 360) }} - {{- template "validate-arg-value" $ctx }} - {{- $ctx = merge $ctx (dict "argName" "saturation" "argValue" (index $filterArgs 1) "min" 0 "max" 100) }} - {{- template "validate-arg-value" $ctx }} - {{- $ctx = merge $ctx (dict "argName" "percentage" "argValue" (index $filterArgs 2) "min" 0 "max" 100) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.Colorize (index $filterArgs 0) (index $filterArgs 1) (index $filterArgs 2) }} -{{- else if eq $filter "contrast" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "percentage" "argValue" (index $filterArgs 0) "min" -100 "max" 100) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.Contrast (index $filterArgs 0) }} -{{- else if eq $filter "dither" }} - {{- $f = images.Dither }} -{{- else if eq $filter "gamma" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "gamma" "argValue" (index $filterArgs 0) "min" 0 "max" 100) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.Gamma (index $filterArgs 0) }} -{{- else if eq $filter "gaussianblur" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "sigma" "argValue" (index $filterArgs 0) "min" 0 "max" 1000) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.GaussianBlur (index $filterArgs 0) }} -{{- else if eq $filter "grayscale" }} - {{- $ctx = merge $ctx (dict "argsRequired" 0) }} - {{- template "validate-arg-count" $ctx }} - {{- $f = images.Grayscale }} -{{- else if eq $filter "hue" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "shift" "argValue" (index $filterArgs 0) "min" -180 "max" 180) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.Hue (index $filterArgs 0) }} -{{- else if eq $filter "invert" }} - {{- $ctx = merge $ctx (dict "argsRequired" 0) }} - {{- template "validate-arg-count" $ctx }} - {{- $f = images.Invert }} -{{- else if eq $filter "mask" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $ctx := dict "src" (index $filterArgs 0) "name" .Name "position" .Position }} - {{- $maskImage := partial "inline/get-resource.html" $ctx }} - {{- $f = images.Mask $maskImage }} -{{- else if eq $filter "opacity" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "opacity" "argValue" (index $filterArgs 0) "min" 0 "max" 1) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.Opacity (index $filterArgs 0) }} -{{- else if eq $filter "overlay" }} - {{- $ctx = merge $ctx (dict "argsRequired" 3) }} - {{- template "validate-arg-count" $ctx }} - {{- $ctx := dict "src" (index $filterArgs 0) "name" .Name "position" .Position }} - {{- $overlayImg := partial "inline/get-resource.html" $ctx }} - {{- $f = images.Overlay $overlayImg (index $filterArgs 1 | float ) (index $filterArgs 2 | float) }} -{{- else if eq $filter "padding" }} - {{- $ctx = merge $ctx (dict "argsRequired" 5) }} - {{- template "validate-arg-count" $ctx }} - {{- $f = images.Padding - (index $filterArgs 0 | int) - (index $filterArgs 1 | int) - (index $filterArgs 2 | int) - (index $filterArgs 3 | int) - (index $filterArgs 4) - }} -{{- else if eq $filter "pixelate" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "size" "argValue" (index $filterArgs 0) "min" 0 "max" 1000) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.Pixelate (index $filterArgs 0) }} -{{- else if eq $filter "process" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $f = images.Process (index $filterArgs 0) }} -{{- else if eq $filter "saturation" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "percentage" "argValue" (index $filterArgs 0) "min" -100 "max" 500) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.Saturation (index $filterArgs 0) }} -{{- else if eq $filter "sepia" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "percentage" "argValue" (index $filterArgs 0) "min" 0 "max" 100) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.Sepia (index $filterArgs 0) }} -{{- else if eq $filter "sigmoid" }} - {{- $ctx = merge $ctx (dict "argsRequired" 2) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "midpoint" "argValue" (index $filterArgs 0) "min" 0 "max" 1) }} - {{- template "validate-arg-value" $ctx }} - {{- $ctx = merge $ctx (dict "argName" "factor" "argValue" (index $filterArgs 1) "min" -10 "max" 10) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.Sigmoid (index $filterArgs 0) (index $filterArgs 1) }} -{{- else if eq $filter "text" }} - {{- $ctx = merge $ctx (dict "argsRequired" 1) }} - {{- template "validate-arg-count" $ctx }} - {{- $ctx := dict "src" $textFilterOpts.fontPath "name" .Name "position" .Position }} - {{- $font := or (partial "inline/get-resource.html" $ctx) }} - {{- $fontSize := or (index $filterArgs 3 | int) $textFilterOpts.fontSize }} - {{- $lineHeight := math.Max (or (index $filterArgs 4 | float) $textFilterOpts.lineHeight) 1 }} - {{- $opts := dict - "x" (or (index $filterArgs 1 | int) $textFilterOpts.xOffset) - "y" (or (index $filterArgs 2 | int) $textFilterOpts.yOffset) - "size" $fontSize - "linespacing" (mul (sub $lineHeight 1) $fontSize) - "color" (or (index $filterArgs 5) $textFilterOpts.fontColor) - "font" $font - }} - {{- $f = images.Text (index $filterArgs 0) $opts }} -{{- else if eq $filter "unsharpmask" }} - {{- $ctx = merge $ctx (dict "argsRequired" 3) }} - {{- template "validate-arg-count" $ctx }} - {{- $filterArgs = apply $filterArgs "float" "." }} - {{- $ctx = merge $ctx (dict "argName" "sigma" "argValue" (index $filterArgs 0) "min" 0 "max" 500) }} - {{- template "validate-arg-value" $ctx }} - {{- $ctx = merge $ctx (dict "argName" "amount" "argValue" (index $filterArgs 1) "min" 0 "max" 100) }} - {{- template "validate-arg-value" $ctx }} - {{- $ctx = merge $ctx (dict "argName" "threshold" "argValue" (index $filterArgs 2) "min" 0 "max" 1) }} - {{- template "validate-arg-value" $ctx }} - {{- $f = images.UnsharpMask (index $filterArgs 0) (index $filterArgs 1) (index $filterArgs 2) }} -{{- end }} - -{{- /* Apply filter. */}} -{{- $fi := $i }} -{{- with $f }} - {{- $fi = $i.Filter . }} -{{- end }} - -{{- /* Render. */}} -{{- $class := "di va b--black-20" }} -{{- if eq $filter "mask" }} - {{- $class = "di va" }} -{{- end }} -{{- if $example }} -

Original

- {{ $alt }} -

Processed

- {{ $alt }} -{{- else -}} - {{ $alt }} -{{- end }} - -{{- define "validate-arg-count" }} - {{- $msg := "When using the %q filter, the %q shortcode requires an args parameter with %d %s. See %s" }} - {{- if lt (len .args) .argsRequired }} - {{- $text := "values" }} - {{- if eq 1 .argsRequired }} - {{- $text = "value" }} - {{- end }} - {{- errorf $msg .filter .name .argsRequired $text .position }} - {{- end }} -{{- end }} - -{{- define "validate-arg-value" }} - {{- $msg := "The %q argument passed to the %q shortcode is invalid. Expected a value in the range [%v,%v], but received %v. See %s" }} - {{- if or (lt .argValue .min) (gt .argValue .max) }} - {{- errorf $msg .argName .name .min .max .argValue .position }} - {{- end }} -{{- end }} - -{{- define "partials/inline/get-resource.html" }} - {{- $r := "" }} - {{- $u := urls.Parse .src }} - {{- $msg := "The %q shortcode was unable to resolve %s. See %s" }} - {{- if $u.IsAbs }} - {{- with try (resources.GetRemote $u.String) }} - {{- with .Err }} - {{- errorf "%s" . }} - {{- else with .Value }} - {{- /* This is a remote resource. */}} - {{- $r = . }} - {{- else }} - {{- errorf $msg $.name $u.String $.position }} - {{- end }} - {{- end }} - {{- else }} - {{- with .page.Resources.Get (strings.TrimPrefix "./" $u.Path) }} - {{- /* This is a page resource. */}} - {{- $r = . }} - {{- else }} - {{- with resources.Get $u.Path }} - {{- /* This is a global resource. */}} - {{- $r = . }} - {{- else }} - {{- errorf $msg $.name $u.Path $.position }} - {{- end }} - {{- end }} - {{- end }} - {{- return $r}} -{{- end -}}