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 */}}