diff --git a/config/_default/params.toml b/config/_default/params.toml index 66f17729..de923249 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -12,6 +12,7 @@ autoSwitchAppearance = true enableA11y = false enableSearch = true enableCodeCopy = false +enableStructuredBreadcrumbs = false replyByEmail = false diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 3fa5bd2c..83bf0d9a 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -12,6 +12,7 @@ autoSwitchAppearance = true enableA11y = false enableSearch = true enableCodeCopy = true +enableStructuredBreadcrumbs = true replyByEmail = false diff --git a/exampleSite/content/docs/configuration/index.it.md b/exampleSite/content/docs/configuration/index.it.md index ac546f91..f86d7cc8 100644 --- a/exampleSite/content/docs/configuration/index.it.md +++ b/exampleSite/content/docs/configuration/index.it.md @@ -174,6 +174,7 @@ Many of the article defaults here can be overridden on a per article basis by sp | `enableA11y` | `false` | Whether to enable the accessibility toggle button. | | `enableSearch` | `false` | Whether site search is enabled. Set to `true` to enable search functionality. Note that the search feature depends on the `outputs.home` setting in the [site configuration](#configurazioni-del-sito) being set correctly. | | `enableCodeCopy` | `false` | Whether copy-to-clipboard buttons are enabled for `` blocks. The `highlight.noClasses` parameter must be set to `false` for code copy to function correctly. Read more about [other configuration files](#other-configuration-files) below. | +| `enableStructuredBreadcrumbs` | `false` | Whether to add [BreadcrumbList](https://developers.google.com/search/docs/appearance/structured-data/breadcrumb) for SEO. Do NOT enable this if your content path does not match the URL, i.e., complex [URL setting](https://gohugo.io/content-management/urls/). | | `mainSections` | _Not set_ | The sections that should be displayed in the recent articles list. If not provided the section with the greatest number of articles is used. | | `showViews` | _Not set_ | Whether or not articles and list views are displayed. This requires firebase integrations to be enabled, look below. | | `showLikes` | _Not set_ | Whether or not articles and list likes are displayed. This requires firebase integrations to be enabled, look below. | diff --git a/exampleSite/content/docs/configuration/index.ja.md b/exampleSite/content/docs/configuration/index.ja.md index 1220ab90..4298069c 100644 --- a/exampleSite/content/docs/configuration/index.ja.md +++ b/exampleSite/content/docs/configuration/index.ja.md @@ -174,6 +174,7 @@ Blowfish は、テーマの機能を制御する多数の設定パラメータ | `enableA11y` | `false` | アクセシビリティ切り替えボタンを有効にするかどうか。 | | `enableSearch` | `false` | サイト内検索が有効かどうかです。`true` に設定すると、検索機能が有効になります。検索機能は、[サイト設定](#サイト設定)の `outputs.home` 設定が正しく設定されているかどうかに依存することに注意してください。 | | `enableCodeCopy` | `false` | `` ブロックのクリップボードへのコピーボタンを有効にするかどうかです。コードコピーが正しく機能するには、`highlight.noClasses` パラメータを `false` に設定する必要があります。以下の[その他の設定ファイル](#その他の設定ファイル)について読んでください。 | +| `enableStructuredBreadcrumbs` | `false` | SEO のために [BreadcrumbList](https://developers.google.com/search/docs/appearance/structured-data/breadcrumb) を追加するかどうかを示す。コンテンツパスが URL と一致しない場合例えば複雑な [URL 設定](https://gohugo.io/content-management/urls/) では有効化しないことを示す。 | | `mainSections` | _未設定_ | 最近の記事リストに表示するセクションです。指定しない場合は、記事数が最も多いセクションが使用されます。 | | `showViews` | _未設定_ | 記事とリストの表示回数を表示するかどうかです。これには Firebase 統合を有効にする必要があります。以下をご覧ください。 | | `showLikes` | _未設定_ | 記事とリストのいいねを表示するかどうかです。これには Firebase 統合を有効にする必要があります。以下をご覧ください。 | diff --git a/exampleSite/content/docs/configuration/index.md b/exampleSite/content/docs/configuration/index.md index 735ab59d..0981a4f6 100644 --- a/exampleSite/content/docs/configuration/index.md +++ b/exampleSite/content/docs/configuration/index.md @@ -176,6 +176,7 @@ Many of the article defaults here can be overridden on a per article basis by sp | `enableA11y` | `false` | Whether to enable the accessibility toggle button. | | `enableSearch` | `false` | Whether site search is enabled. Set to `true` to enable search functionality. Note that the search feature depends on the `outputs.home` setting in the [site configuration](#site-configuration) being set correctly. | | `enableCodeCopy` | `false` | Whether copy-to-clipboard buttons are enabled for `` blocks. The `highlight.noClasses` parameter must be set to `false` for code copy to function correctly. Read more about [other configuration files](#other-configuration-files) below. | +| `enableStructuredBreadcrumbs` | `false` | Whether to add [BreadcrumbList](https://developers.google.com/search/docs/appearance/structured-data/breadcrumb) for SEO. Do NOT enable this if your content path does not match the URL, i.e., complex [URL setting](https://gohugo.io/content-management/urls/). | | `replyByEmail` | `false` | Whether the reply-by-email link is enabled after post. The `params.author.email` parameter in `config/_default/languages.en.toml` must be set. | | `forgejoDefaultServer` | _Not set_ | The default `server` parameter for the `forgejo` shortcode. | | `giteaDefaultServer` | _Not set_ | The default `server` parameter for the `gitea` shortcode. | diff --git a/exampleSite/content/docs/configuration/index.zh-cn.md b/exampleSite/content/docs/configuration/index.zh-cn.md index d32dceac..5c031b1c 100644 --- a/exampleSite/content/docs/configuration/index.zh-cn.md +++ b/exampleSite/content/docs/configuration/index.zh-cn.md @@ -174,6 +174,7 @@ Blowfish 提供了大量控制主题功能的配置参数,下面的表格中 | `enableA11y` | `false` | 是否启用无障碍切换按钮。 | | `enableSearch` | `false` | 是否开启网站的搜索功能,设为 `true` 即为启用。注意,搜索功能依赖于[站点设置](#网站配置)中的 `outputs.home` 设置,请确保此值配置正确。 | | `enableCodeCopy` | `false` | 是否可以将``代码块复制到剪贴板。想要使用代码复制功能,需要将 `highlight.noClasses` 参数设置为 `false`。 阅读 [其他配置文件](#其他配置文件) 以获取更多信息。 | +| `enableStructuredBreadcrumbs` | `false` | 是否为 SEO 添加 [BreadcrumbList](https://developers.google.com/search/docs/appearance/structured-data/breadcrumb)。如果内容路径与 URL 不一致例如复杂的 [URL 设置](https://gohugo.io/content-management/urls/) 则不要启用。 | | `replyByEmail` | `false` | 是否在发布后启用“通过邮件回复”的链接。如果使用,则必须设置 `config/_default/languages.en.toml` 中的 `params.author.email` 参数。 | | `forgejoDefaultServer` | _Not set_ | 短代码 `forgejo` 的默认 `server` 参数。 | | `giteaDefaultServer` | _Not set_ | 短代码 `gitea` 的默认 `server` 参数。 | diff --git a/layouts/partials/schema.html b/layouts/partials/schema.html index 04e4e7ac..ea599540 100644 --- a/layouts/partials/schema.html +++ b/layouts/partials/schema.html @@ -3,11 +3,11 @@ { "@context": "https://schema.org", "@type": "WebSite", - "@id": "{{ (site.GetPage "/").Permalink | safeURL }}", + "@id": {{ site.Home.Permalink | safeURL }}, "name": "{{ .Site.Title | safeJS }}", {{ with .Site.Params.description }}"description": "{{ . | safeJS }}",{{ end }} {{ with .Site.LanguageCode }}"inLanguage": "{{ . }}",{{ end }} - "url": "{{ (site.GetPage "/").Permalink | safeURL }}", + "url": {{ site.Home.Permalink | safeURL }}, {{ with .Site.Params.keywords }}"keywords": {{ . }},{{ end }} "publisher" : { "@type": "Person", @@ -27,7 +27,7 @@ {{ with .Description }}"description": "{{ . | safeJS }}",{{ end }} {{ with .Summary }}"abstract": "{{ . | safeJS }}",{{ end }} {{ with .Site.LanguageCode }}"inLanguage": "{{ . }}",{{ end }} - "url" : "{{ .Permalink }}", + "url" : {{ .Permalink }}, "author" : { "@type": "Person", "name": "{{ .Site.Params.Author.name | safeJS }}" @@ -44,6 +44,28 @@ {{ end }} "mainEntityOfPage": "true", "wordCount": "{{ .WordCount }}" - }] + }{{ if site.Params.enableStructuredBreadcrumbs | default false }}, + { + "@context": "https://schema.org", + "@type": "BreadcrumbList", + "itemListElement": [ + {{- $breadcrumbs := slice -}} + {{- range .Ancestors -}} + {{- if not .IsHome -}} + {{- $breadcrumbs = $breadcrumbs | append . -}} + {{- end -}} + {{- end -}} + {{- $breadcrumbs = $breadcrumbs | append . -}} + + {{- range $index, $element := $breadcrumbs -}} + { + "@type": "ListItem", + "position": {{ add $index 1 }}, + "name": "{{ .Title }}", + "item": {{ .Permalink }}, + }{{ if ne (add $index 1) (len $breadcrumbs) }},{{ end }} + {{- end -}} + ] + }{{ end }}] {{ end }}