diff --git a/layouts/partials/functions/get_logo.html b/layouts/partials/functions/get_logo.html index 4bf6b8e6..b4e11c1d 100644 --- a/layouts/partials/functions/get_logo.html +++ b/layouts/partials/functions/get_logo.html @@ -2,15 +2,20 @@ {{/* Inputs: constraint: max_height/fit (str); size (int) */}} {{/* Output: resource (obj) */}} -{{ $logo := resources.Get "images/logo.png" }} +{{/* Workaround fact Hugo does not support GetMatch in assets dir */}} +{{/* Hugo doesn't support image ops on SVG: https://discourse.gohugo.io/t/ho-do-i-convert-a-generic-resource-to-image-resource/22570/4 */}} +{{ $logo := resources.Get "images/logo.png" | default (resources.Get "images/logo.svg") }} {{ $logo_proc := $logo }} -{{ if eq .constraint "max_height" }} - {{/* Resize logo to fit specified max height. */}} - {{ $logo_proc = ($logo.Resize (printf "x%s" (string .size))) }} -{{ else }} - {{/* Constrain logo to fit within specified dimensions. */}} - {{ $logo_proc = ($logo.Fit (printf "%sx%s" (string .size) (string .size))) }} +{{/* If the type of image can be resized by Hugo, resize it given a `.size` argument to the function. */}} +{{ if resources.Get "images/logo.png" }} + {{ if eq .constraint "max_height" }} + {{/* Resize logo to fit specified max height. */}} + {{ $logo_proc = ($logo.Resize (printf "x%s" (string .size))) }} + {{ else }} + {{/* Constrain logo to fit within specified dimensions. */}} + {{ $logo_proc = ($logo.Fit (printf "%sx%s" (string .size) (string .size))) }} + {{ end }} {{ end }} {{ return $logo_proc }} diff --git a/layouts/partials/functions/get_logo_url.html b/layouts/partials/functions/get_logo_url.html new file mode 100644 index 00000000..0f2c23d5 --- /dev/null +++ b/layouts/partials/functions/get_logo_url.html @@ -0,0 +1,12 @@ +{{/* Function to get logo URL for JSONLD. */}} +{{/* Inputs: page context */}} +{{/* Output: logo URL (URL) */}} + +{{ $logo_url := "" }} +{{ if resources.Get "images/logo.png" | or (resources.Get "images/logo.svg") }} + {{ $logo_url = (partial "functions/get_logo" (dict "constraint" "fit" "size" 192)).Permalink }} +{{ else }} + {{ $logo_url = (partial "functions/get_icon" 192).Permalink }} +{{ end }} + +{{ return $logo_url }} diff --git a/layouts/partials/jsonld/article.html b/layouts/partials/jsonld/article.html index b8e30710..33550bf0 100644 --- a/layouts/partials/jsonld/article.html +++ b/layouts/partials/jsonld/article.html @@ -1,4 +1,4 @@ -{{ $page := .page }} +{{- $page := .page }} {{ $summary := .summary }} {{ $featured_image := ($page.Resources.ByType "image").GetMatch "*featured*" }} @@ -10,7 +10,7 @@ {{ $author := partial "functions/get_author_name" $page }} {{ $publisher := site.Params.org_name | default site.Title }} -{{ $logo_url := (printf "img/%s" (site.Params.logo | absURL)) | default (partial "functions/get_icon" 512).Permalink }} +{{ $logo_url := partial "functions/get_logo_url" $page -}}