From ff8f2537cac27ab93964e634596acd9a1baf6be8 Mon Sep 17 00:00:00 2001 From: Xin Date: Sun, 21 Jan 2024 10:33:49 +0000 Subject: [PATCH] fix: accurate `editURL` resolution in translated sites (#264) --- layouts/partials/toc.html | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html index 21d77a7..b941732 100644 --- a/layouts/partials/toc.html +++ b/layouts/partials/toc.html @@ -26,8 +26,18 @@
{{- if site.Params.editURL.enable -}} {{- $editURL := site.Params.editURL.base | default "" -}} - {{- with .File -}}{{ $editURL = urls.JoinPath $editURL (replace .Path "\\" "/") }}{{- end -}} - {{- with .Params.editURL -}}{{ $editURL = . }}{{- end -}} + {{- with .Params.editURL -}} + {{/* if `editURL` is set in the front matter */}} + {{- $editURL = . -}} + {{- else -}} + {{- with .File -}} + {{/* `.FileInfo.Meta.SourceRoot` is a Hugo internal field, e.g. `/path/to/repo/content/en/` */}} + {{- $sourceDir := replace (strings.TrimPrefix .FileInfo.Meta.BaseDir .FileInfo.Meta.SourceRoot) "\\" "/" -}} + {{- $sourceDir = strings.TrimPrefix "/content" $sourceDir -}} + {{- $path := replace .Path "\\" "/" -}} + {{- $editURL = urls.JoinPath $editURL $sourceDir $path -}} + {{- end -}} + {{- end -}} {{ $editThisPage }} {{- end -}} {{/* Scroll To Top */}}