From 12c58504464b046922458a3bce065d1b70322798 Mon Sep 17 00:00:00 2001 From: xiaoqing Date: Thu, 21 Dec 2023 19:24:53 +0800 Subject: [PATCH] 1. Removed microdata and unified use of JSON-LD. 2. Add alternateName field to webSite schema. That is an alternate site name used in Google search results. 3. Fix missing field in google rich result test. 4. Prioritize using the featured image in front matter as the article image in JSON-LD. --- exampleSite/config/_default/params.toml | 4 + .../theme-documentation-basics/index.en.md | 3 + .../theme-documentation-basics/index.zh-cn.md | 3 + layouts/_default/summary.html | 4 +- layouts/index.html | 11 +- layouts/partials/footer.html | 8 +- layouts/partials/head/seo.html | 179 ++++++++++++------ 7 files changed, 141 insertions(+), 71 deletions(-) diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index a23406290..c0cbe4eb6 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -545,6 +545,10 @@ cacheRemoteImages = false # thumbnail URL # 缩略图 URL thumbnailUrl = "/images/screenshot.png" + # Google 搜索结果中网站备用名字 + # alternate site name in Google search result + # https://developers.google.com/search/docs/appearance/site-names#alternative + # alternateName = ["Hugo DoIt"] # Analytics config # 网站分析配置 diff --git a/exampleSite/content/posts/theme-documentation-basics/index.en.md b/exampleSite/content/posts/theme-documentation-basics/index.en.md index 754f784ab..78cf64568 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.en.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.en.md @@ -772,6 +772,9 @@ Please open the code block below to view the complete sample configuration :(far image = "" # thumbnail URL thumbnailUrl = "" + # {{< version 0.4.1 >}} + # alternate site name in Google search result + alternateName = ["Hugo DoIt"] # {{< version 0.2.0 >}} Analytics config [params.analytics] diff --git a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md index 17845b493..52d0835ea 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md @@ -776,6 +776,9 @@ hugo image = "" # 缩略图 URL thumbnailUrl = "" + # {{< version 0.4.1 >}} + # Google 搜索结果中网站备用名字 + alternateName = ["Hugo DoIt"] # {{< version 0.2.0 >}} 网站分析配置 [params.analytics] diff --git a/layouts/_default/summary.html b/layouts/_default/summary.html index 1f38c69d2..5f675fe05 100644 --- a/layouts/_default/summary.html +++ b/layouts/_default/summary.html @@ -1,6 +1,6 @@ {{- $params := .Params | merge .Site.Params.page -}} -
+
{{- /* Featured image */ -}} {{- $image := $params.featuredImagePreview | default $params.featuredImage -}} {{- $height := "auto" -}} @@ -29,7 +29,7 @@ {{- end -}} {{- /* Title */ -}} -

+

{{ .Title }}

diff --git a/layouts/index.html b/layouts/index.html index 352ab18dc..d871d53a6 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -1,10 +1,9 @@ {{- define "title" }} - {{- with .Scratch.Get "paginatorPager" -}} - {{- if gt .PageNumber 1 -}} - {{- T "prefixPageNumber" }} {{ .PageNumber }} {{ T "suffixPageNumber" }} - {{ $.Site.Title -}} - {{ else }} - {{- $.Site.Title -}} - {{- end -}} + {{- $paginatorPager := .Scratch.Get "paginatorPager" -}} + {{- if and $paginatorPager (gt $paginatorPager.PageNumber 1) -}} + {{- T "prefixPageNumber" }} {{ $paginatorPager.PageNumber }} {{ T "suffixPageNumber" }} - {{ $.Site.Title -}} + {{ else }} + {{- $.Site.Title -}} {{- end -}} {{- end -}} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 27f47d12b..ca2fa1438 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -34,17 +34,15 @@ {{- if ne .Site.Params.footer.copyright false -}} {{- with .Site.Params.footer.since -}} - - {{- if lt . now.Year }}{{ . }} - {{ end }}{{ now.Year -}} - + {{- if lt . now.Year }}{{ . }} - {{ end }}{{ now.Year -}} {{- else -}} - {{ now.Year }} + {{ now.Year }} {{- end -}} {{- end -}} {{- /* Author */ -}} {{- if ne .Site.Params.footer.author false -}} -  {{ .Site.Author.name }} +  {{ .Site.Author.name }} {{- end -}} {{- /* License */ -}} diff --git a/layouts/partials/head/seo.html b/layouts/partials/head/seo.html index 9d406c17d..b00f5de99 100644 --- a/layouts/partials/head/seo.html +++ b/layouts/partials/head/seo.html @@ -1,5 +1,3 @@ -{{- $params := .Scratch.Get "params" -}} - {{- with .Site.Params.verification.google -}} {{- end -}} @@ -22,57 +20,13 @@ {{- end -}} -{{- /* Home SEO */ -}} -{{- if .IsHome -}} - - -{{- /* Page SEO */ -}} -{{- else if .IsPage -}} - + {{- end -}} + +{{- /* Page SEO */ -}} +{{- else if .IsPage -}} + {{- end -}}