Skip to content

Commit ff8f253

Browse files
authored
fix: accurate editURL resolution in translated sites (#264)
1 parent 728fe21 commit ff8f253

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

layouts/partials/toc.html

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,18 @@
2626
<div class="{{ $borderClass }} sticky bottom-0 flex flex-col items-start gap-2 pb-8 dark:border-neutral-800 contrast-more:border-t contrast-more:border-neutral-400 contrast-more:shadow-none contrast-more:dark:border-neutral-400">
2727
{{- if site.Params.editURL.enable -}}
2828
{{- $editURL := site.Params.editURL.base | default "" -}}
29-
{{- with .File -}}{{ $editURL = urls.JoinPath $editURL (replace .Path "\\" "/") }}{{- end -}}
30-
{{- with .Params.editURL -}}{{ $editURL = . }}{{- end -}}
29+
{{- with .Params.editURL -}}
30+
{{/* if `editURL` is set in the front matter */}}
31+
{{- $editURL = . -}}
32+
{{- else -}}
33+
{{- with .File -}}
34+
{{/* `.FileInfo.Meta.SourceRoot` is a Hugo internal field, e.g. `/path/to/repo/content/en/` */}}
35+
{{- $sourceDir := replace (strings.TrimPrefix .FileInfo.Meta.BaseDir .FileInfo.Meta.SourceRoot) "\\" "/" -}}
36+
{{- $sourceDir = strings.TrimPrefix "/content" $sourceDir -}}
37+
{{- $path := replace .Path "\\" "/" -}}
38+
{{- $editURL = urls.JoinPath $editURL $sourceDir $path -}}
39+
{{- end -}}
40+
{{- end -}}
3141
<a class="text-xs font-medium text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100 contrast-more:text-gray-800 contrast-more:dark:text-gray-50" href="{{ $editURL }}" target="_blank" rel="noreferer">{{ $editThisPage }}</a>
3242
{{- end -}}
3343
{{/* Scroll To Top */}}

0 commit comments

Comments
 (0)