diff --git a/exampleSite/hugo.yaml b/exampleSite/hugo.yaml index 0da0ad99..5235f23f 100644 --- a/exampleSite/hugo.yaml +++ b/exampleSite/hugo.yaml @@ -142,6 +142,7 @@ params: editURL: enable: true + where: "single" # single | toc base: "https://github.com/imfing/hextra/edit/main/exampleSite/content" blog: diff --git a/layouts/partials/components/last-updated.html b/layouts/partials/components/last-updated.html index 7918fb12..22905e65 100644 --- a/layouts/partials/components/last-updated.html +++ b/layouts/partials/components/last-updated.html @@ -1,9 +1,28 @@ {{- $lastUpdated := (T "lastUpdated") | default "Last updated on" -}} +{{- $editThisPage := (T "editThisPage") | default "Edit this page"}} {{- if site.Params.displayUpdatedDate -}} +
+ {{- if and (site.Params.editURL.enable) (eq site.Params.editURL.where "single") -}} + {{- $editURL := site.Params.editURL.base | default "" -}} + {{- 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 -}} {{- with .Lastmod -}} {{ $datetime := (time.Format "2006-01-02T15:04:05.000Z" .) }} -
{{ $lastUpdated }}
+
{{ $lastUpdated }}
+
{{- else -}}
{{- end -}} diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html index 02cf98da..4c25671f 100644 --- a/layouts/partials/toc.html +++ b/layouts/partials/toc.html @@ -24,7 +24,7 @@ {{/* TOC bottom part */}}
- {{- if site.Params.editURL.enable -}} + {{- if and (site.Params.editURL.enable) (eq site.Params.editURL.where "toc") -}} {{- $editURL := site.Params.editURL.base | default "" -}} {{- with .Params.editURL -}} {{/* if `editURL` is set in the front matter */}}