From 447acb7df37d9a9b7faa1f2cbd5d29f997c0d838 Mon Sep 17 00:00:00 2001 From: Xin <5097752+imfing@users.noreply.github.com> Date: Sat, 17 Jan 2026 12:14:15 +0000 Subject: [PATCH] fix(og-image): handle leading slashes in image paths for subpath deployments (#901) * fix(og-image): handle leading slashes in image paths for subpath deployments Fix Open Graph image paths not working correctly when deploying to subpaths (e.g., https://example.com/docs/). The issue occurred when image paths with leading slashes were specified in configuration, causing the subpath to be ignored. The fix follows the established pattern used throughout the theme by stripping leading slashes before applying relURL, ensuring paths respect the baseURL subpath configuration. - Update opengraph.html to process image paths consistently - Update configuration examples to remove leading slashes - Add investigation document explaining the issue and fix * chore: remove issue summary --- docs/content/docs/guide/configuration.ja.md | 2 +- docs/content/docs/guide/configuration.md | 4 ++-- docs/content/docs/guide/configuration.zh-cn.md | 2 +- layouts/_partials/opengraph.html | 12 ++++++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/content/docs/guide/configuration.ja.md b/docs/content/docs/guide/configuration.ja.md index c2136c4..6a067ed 100644 --- a/docs/content/docs/guide/configuration.ja.md +++ b/docs/content/docs/guide/configuration.ja.md @@ -420,6 +420,6 @@ llms.txt ファイルはコンテンツ構造から自動生成され、AI ツ title: "設定" params: images: - - "/img/config-image.jpg" + - "img/config-image.jpg" audio: "config-talk.mp3" ``` diff --git a/docs/content/docs/guide/configuration.md b/docs/content/docs/guide/configuration.md index 776fdc1..8d843ec 100644 --- a/docs/content/docs/guide/configuration.md +++ b/docs/content/docs/guide/configuration.md @@ -520,7 +520,7 @@ Other Open Graph properties can have only one value. title: "My Page" params: images: - - "/images/image01.jpg" + - "images/image01.jpg" audio: "podcast02.mp3" videos: - "video01.mp4" @@ -533,7 +533,7 @@ Page content. ```yaml {filename="hugo.yaml"} params: images: - - "/images/image01.jpg" + - "images/image01.jpg" audio: "podcast02.mp3" videos: - "video01.mp4" diff --git a/docs/content/docs/guide/configuration.zh-cn.md b/docs/content/docs/guide/configuration.zh-cn.md index 3efdd26..d901f04 100644 --- a/docs/content/docs/guide/configuration.zh-cn.md +++ b/docs/content/docs/guide/configuration.zh-cn.md @@ -420,6 +420,6 @@ llms.txt 文件根据内容结构自动生成,使 AI 工具和语言模型更 title: "配置" params: images: - - "/img/config-image.jpg" + - "img/config-image.jpg" audio: "config-talk.mp3" ``` diff --git a/layouts/_partials/opengraph.html b/layouts/_partials/opengraph.html index 140f248..91b9d3f 100644 --- a/layouts/_partials/opengraph.html +++ b/layouts/_partials/opengraph.html @@ -28,12 +28,20 @@ {{- else }} - + {{- $image := . -}} + {{- if hasPrefix $image "/" -}} + {{- $image = relURL (strings.TrimPrefix "/" $image) -}} + {{- end -}} + {{- end }} {{- end }} {{- else -}} {{- with $.Site.Params.images }} - + {{- $image := index . 0 -}} + {{- if hasPrefix $image "/" -}} + {{- $image = relURL (strings.TrimPrefix "/" $image) -}} + {{- end -}} + {{- end }} {{- end -}}