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
This commit is contained in:
Xin
2026-01-17 12:14:15 +00:00
committed by GitHub
parent c4a39472eb
commit 447acb7df3
4 changed files with 14 additions and 6 deletions

View File

@@ -420,6 +420,6 @@ llms.txt ファイルはコンテンツ構造から自動生成され、AI ツ
title: "設定" title: "設定"
params: params:
images: images:
- "/img/config-image.jpg" - "img/config-image.jpg"
audio: "config-talk.mp3" audio: "config-talk.mp3"
``` ```

View File

@@ -520,7 +520,7 @@ Other Open Graph properties can have only one value.
title: "My Page" title: "My Page"
params: params:
images: images:
- "/images/image01.jpg" - "images/image01.jpg"
audio: "podcast02.mp3" audio: "podcast02.mp3"
videos: videos:
- "video01.mp4" - "video01.mp4"
@@ -533,7 +533,7 @@ Page content.
```yaml {filename="hugo.yaml"} ```yaml {filename="hugo.yaml"}
params: params:
images: images:
- "/images/image01.jpg" - "images/image01.jpg"
audio: "podcast02.mp3" audio: "podcast02.mp3"
videos: videos:
- "video01.mp4" - "video01.mp4"

View File

@@ -420,6 +420,6 @@ llms.txt 文件根据内容结构自动生成,使 AI 工具和语言模型更
title: "配置" title: "配置"
params: params:
images: images:
- "/img/config-image.jpg" - "img/config-image.jpg"
audio: "config-talk.mp3" audio: "config-talk.mp3"
``` ```

View File

@@ -28,12 +28,20 @@
<meta property="og:image" content="{{ .Permalink }}"> <meta property="og:image" content="{{ .Permalink }}">
{{- else }} {{- else }}
<!-- Otherwise treat it as a site/global path --> <!-- Otherwise treat it as a site/global path -->
<meta property="og:image" content="{{ . | absURL }}"> {{- $image := . -}}
{{- if hasPrefix $image "/" -}}
{{- $image = relURL (strings.TrimPrefix "/" $image) -}}
{{- end -}}
<meta property="og:image" content="{{ $image | absURL }}">
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- else -}} {{- else -}}
{{- with $.Site.Params.images }} {{- with $.Site.Params.images }}
<meta property="og:image" content="{{ index . 0 | absURL }}"> {{- $image := index . 0 -}}
{{- if hasPrefix $image "/" -}}
{{- $image = relURL (strings.TrimPrefix "/" $image) -}}
{{- end -}}
<meta property="og:image" content="{{ $image | absURL }}">
{{- end }} {{- end }}
{{- end -}} {{- end -}}