From e4b76d6fce660d52468992f788d896b46c12a574 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sat, 3 May 2025 02:59:33 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20defaultSocialImag?= =?UTF-8?q?e=20(#1491)=20(#2100)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `defaultSocialImage` as the default image for social media sharing. This feature would be useful for users who don’t want to specify an image for every article. This PR also resolves the issue where the homepage missing an image when shared. --- config/_default/params.toml | 1 + exampleSite/content/docs/configuration/index.it.md | 1 + exampleSite/content/docs/configuration/index.ja.md | 1 + exampleSite/content/docs/configuration/index.md | 1 + exampleSite/content/docs/configuration/index.zh-cn.md | 1 + layouts/partials/head.html | 8 ++++++++ 6 files changed, 13 insertions(+) diff --git a/config/_default/params.toml b/config/_default/params.toml index 0803aea5..d8e097ea 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -23,6 +23,7 @@ disableTextInHeader = false # defaultBackgroundImage = "IMAGE.jpg" # used as default for background images # defaultFeaturedImage = "IMAGE.jpg" # used as default for featured images in all articles +# defaultSocialImage = "/android-chrome-512x512.png" # used as default for social media sharing (Open Graph and Twitter) # highlightCurrentMenuArea = true # smartTOC = true diff --git a/exampleSite/content/docs/configuration/index.it.md b/exampleSite/content/docs/configuration/index.it.md index 4da3babd..f88e3683 100644 --- a/exampleSite/content/docs/configuration/index.it.md +++ b/exampleSite/content/docs/configuration/index.it.md @@ -181,6 +181,7 @@ Many of the article defaults here can be overridden on a per article basis by sp | `disableTextInHeader` | `false` | Disables text in header, useful for logo based headers. | | `defaultBackgroundImage` | _Not set_ | Default background image for both `background` homepage layout and `background` hero style | | `defaultFeaturedImage` | _Not set_ | Default background image for all `featured` images across articles, will be overridden by a local `featured` image. | +| `defaultSocialImage` | _Not set_ | Default image for social media sharing (Open Graph and Twitter). Will be overridden by a local `feature` image if available. | | `highlightCurrentMenuArea` | _Not set_ | Marks menu entries in the main menu when selected | | `smartTOC` | _Not set_ | Activate smart Table of Contents, items in view will be highlighted. | | `smartTOCHideUnfocusedChildren` | _Not set_ | When smart Table of Contents is turned on, this will hide deeper levels of the table when they are not in focus. | diff --git a/exampleSite/content/docs/configuration/index.ja.md b/exampleSite/content/docs/configuration/index.ja.md index 0630f6f4..24f36382 100644 --- a/exampleSite/content/docs/configuration/index.ja.md +++ b/exampleSite/content/docs/configuration/index.ja.md @@ -181,6 +181,7 @@ Blowfish は、テーマの機能を制御する多数の設定パラメータ | `disableTextInHeader` | `false` | ヘッダーのテキストを無効にします。ロゴベースのヘッダーに役立ちます。 | | `defaultBackgroundImage` | _未設定_ | `background` ホームページレイアウトと `background` ヒーロースタイルの両方のデフォルトの背景画像です。 | | `defaultFeaturedImage` | _未設定_ | 記事全体のすべての `featured` 画像のデフォルトの背景画像です。ローカルの `featured` 画像によってオーバーライドされます。 | +| `defaultSocialImage` | _未設定_ | ソーシャルメディア共有(Open Graph と Twitter)用のデフォルト画像。ローカルの `featured` 画像によってオーバーライドされます。 | | `highlightCurrentMenuArea` | _未設定_ | メインメニューのメニュー項目が選択されているときにマークを付けます。 | | `smartTOC` | _未設定_ | スマート目次をアクティブにします。表示されている項目が強調表示されます。 | | `smartTOCHideUnfocusedChildren` | _未設定_ | スマート目次がオンになっている場合、フォーカスされていないときに、テーブルのより深いレベルが非表示になります。 | diff --git a/exampleSite/content/docs/configuration/index.md b/exampleSite/content/docs/configuration/index.md index 6cc76234..bf132935 100644 --- a/exampleSite/content/docs/configuration/index.md +++ b/exampleSite/content/docs/configuration/index.md @@ -187,6 +187,7 @@ Many of the article defaults here can be overridden on a per article basis by sp | `disableTextInHeader` | `false` | Disables text in header, useful for logo based headers. | | `defaultBackgroundImage` | _Not set_ | Default background image for both `background` homepage layout and `background` hero style | | `defaultFeaturedImage` | _Not set_ | Default background image for all `featured` images across articles, will be overridden by a local `featured` image. | +| `defaultSocialImage` | _Not set_ | Default image for social media sharing (Open Graph and Twitter). Will be overridden by a local `feature` image. | | `highlightCurrentMenuArea` | _Not set_ | Marks menu entries in the main menu when selected | | `smartTOC` | _Not set_ | Activate smart Table of Contents, items in view will be highlighted. | | `smartTOCHideUnfocusedChildren` | _Not set_ | When smart Table of Contents is turned on, this will hide deeper levels of the table when they are not in focus. | diff --git a/exampleSite/content/docs/configuration/index.zh-cn.md b/exampleSite/content/docs/configuration/index.zh-cn.md index 12510ba5..e36f7de5 100644 --- a/exampleSite/content/docs/configuration/index.zh-cn.md +++ b/exampleSite/content/docs/configuration/index.zh-cn.md @@ -185,6 +185,7 @@ Blowfish 提供了大量控制主题功能的配置参数,下面的表格中 | `disableTextInHeader` | `false` | 禁用文本类型的标题,对基于 logo 的标题很有用。 | | `defaultBackgroundImage` | 无 | 设置默认背景图,用于 `background` 和 `hero` 布局下的主页。 | | `defaultFeaturedImage` | 无 | 设置默认背景图片,用于所有文章的`featured`图片,可以通过文章目录中的 `featured` 图片替换。 | +| `defaultSocialImage` | 无 | 社交媒体分享(Open Graph 和 Twitter)使用的默认图片,可以通过文章目录中的 `featured` 图片替换。 | | `highlightCurrentMenuArea` | 无 | 当菜单被选择时,标记主菜单中的菜单项。 | | `smartTOC` | 无 | 开启智能目录,视图中的项目将会被高亮显示。 | | `smartTOCHideUnfocusedChildren` | 无 | 当开启智能目录,如果目录级别不再被聚焦时,将会隐藏更深层次的目录。 | diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 46f47769..fc2d7638 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -107,6 +107,14 @@ {{/* Social */}} {{ template "_internal/opengraph.html" . }} {{ template "_internal/twitter_cards.html" . }} + {{- /* Image for both main page and backoff if not `*feature*` image found */ -}} + {{- /* See https://gohugo.io/templates/embedded/#open-graph */ -}} + {{ if not ($.Resources.GetMatch "*feature*") }} + {{ with .Site.Params.defaultSocialImage }} + + + {{ end }} + {{ end }} {{/* Schema */}} {{ partial "schema.html" . }} {{/* Me */}} From 3afe8b5e0052f2bf2fa4c58eb5fb1ad871add379 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sat, 3 May 2025 03:12:42 +0800 Subject: [PATCH 2/3] chore: correct typo (#1491) (#2100) --- layouts/partials/head.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index fc2d7638..71d8960a 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -107,7 +107,7 @@ {{/* Social */}} {{ template "_internal/opengraph.html" . }} {{ template "_internal/twitter_cards.html" . }} - {{- /* Image for both main page and backoff if not `*feature*` image found */ -}} + {{- /* Main page always uses this; fallback elsewhere if no feature image */ -}} {{- /* See https://gohugo.io/templates/embedded/#open-graph */ -}} {{ if not ($.Resources.GetMatch "*feature*") }} {{ with .Site.Params.defaultSocialImage }} From 806a8612b81fb61482cd15a5bf35b88563bbb41c Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sat, 3 May 2025 19:53:39 +0800 Subject: [PATCH 3/3] chore: add usage example in document site --- exampleSite/config/_default/params.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 8069e6b7..00a1793c 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -23,6 +23,7 @@ disableTextInHeader = false defaultBackgroundImage = "/img/background.svg" defaultFeaturedImage = "/img/featured.svg" +defaultSocialImage = "/img/blowfish.jpg" highlightCurrentMenuArea = true smartTOC = true