mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-14 20:16:48 +00:00
feat: add support for SVG logo format + fix logo URL in JSONLD
Can now upload an SVG logo to `assets/images/logo.svg`. If your site is for an organization, Google currently requires that the logo is PNG rather than SVG otherwise the site may not receive rich search results based on the JSONLD (see https://developers.google.com/search/docs/data-types/logo). Also, this commit fixes the logo URL in the site's JSONLD metadata - irrespective of the above feature, the logo URL metadata broke when adding the new automated logo detection system in #1439. Close #1512 Fix #1516 Fix #1439
This commit is contained in:
1 parent
5e62b09331
commit
c5b26892a9
6 files changed
+29
-12
No files matched your search
@@ -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 }}
|
||||
@@ -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 }}
|
||||
@@ -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 -}}
|
||||
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"@type": {{site.Params.local_business_type | default site.Params.site_type}},
|
||||
"@id": {{site.BaseURL}},
|
||||
"name": {{site.Params.org_name | default site.Title}},
|
||||
{{with site.Params.logo}}"logo": {{printf "img/%s" . | absURL}},{{end}}
|
||||
"logo": {{ partial "functions/get_logo_url" . }},
|
||||
{{with site.Params.sharing_image}}"image": {{printf "img/%s" . | absURL}},{{end}}
|
||||
{{ if (eq site.Params.site_type "LocalBusiness") | and site.Params.coordinates }}
|
||||
"geo": {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
{{/* Get site logo. */}}
|
||||
{{ $show_logo := site.Params.main_menu.show_logo | default true }}
|
||||
{{ $has_logo := fileExists "assets/images/logo.png" }}
|
||||
{{ $has_logo := fileExists "assets/images/logo.png" | or (fileExists "assets/images/logo.svg") }}
|
||||
{{ $logo := "" }}
|
||||
{{ if $has_logo }}
|
||||
{{ $logo = (partial "functions/get_logo" (dict "constraint" "max_height" "size" 70)) }}
|
||||
|
||||
@@ -148,7 +148,7 @@
|
||||
<link rel="canonical" href="{{ .Permalink }}">
|
||||
|
||||
{{ $featured_image := (.Resources.ByType "image").GetMatch "*featured*" }}
|
||||
{{ $has_logo := fileExists "assets/images/logo.png" }}
|
||||
{{ $has_logo := fileExists "assets/images/logo.png" | or (fileExists "assets/images/logo.svg") }}
|
||||
{{ $og_image := "" }}
|
||||
{{ $twitter_card := "summary_large_image" }}
|
||||
{{ if $featured_image }}
|
||||
|
||||
Reference in new issue
Block a user