diff --git a/exampleSite/hugo.yaml b/exampleSite/hugo.yaml index 5b0776a..9848a27 100644 --- a/exampleSite/hugo.yaml +++ b/exampleSite/hugo.yaml @@ -142,6 +142,7 @@ params: editURL: enable: true + location: "toc" # single | toc base: "https://github.com/imfing/hextra/edit/main/exampleSite/content" blog: diff --git a/layouts/partials/components/edit-url.html b/layouts/partials/components/edit-url.html new file mode 100644 index 0000000..71f71eb --- /dev/null +++ b/layouts/partials/components/edit-url.html @@ -0,0 +1,28 @@ +{{- $editThisPage := (T "editThisPage") | default "Edit this page"}} + +{{- $context := .context -}} + +{{- $linkClass := "hx-mb-4 hx-block hx-text-xs hx-text-gray-500 ltr:hx-text-right rtl:hx-text-left dark:hx-text-gray-400" -}} + +{{- if and (site.Params.editURL.enable) (eq site.Params.editURL.location .source) -}} + {{- $editURL := site.Params.editURL.base | default "" -}} + + {{- with $context.Params.editURL -}} + {{/* if `editURL` is set in the front matter */}} + {{- $editURL = . -}} + {{- else -}} + {{- with $context.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 -}} + + {{- if eq site.Params.editURL.location "toc" -}} + {{- $linkClass = "hx-text-xs hx-font-medium hx-text-gray-500 hover:hx-text-gray-900 dark:hx-text-gray-400 dark:hover:hx-text-gray-100 contrast-more:hx-text-gray-800 contrast-more:dark:hx-text-gray-50" -}} + {{- end -}} + + {{ $editThisPage }} +{{- end -}} diff --git a/layouts/partials/components/last-updated.html b/layouts/partials/components/last-updated.html index 7918fb1..fd39154 100644 --- a/layouts/partials/components/last-updated.html +++ b/layouts/partials/components/last-updated.html @@ -1,9 +1,12 @@ {{- $lastUpdated := (T "lastUpdated") | default "Last updated on" -}} {{- if site.Params.displayUpdatedDate -}} +
+{{ partial "components/edit-url.html" (dict "source" "single" "context" .) }} {{- 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 02cf98d..d173343 100644 --- a/layouts/partials/toc.html +++ b/layouts/partials/toc.html @@ -24,22 +24,7 @@ {{/* TOC bottom part */}}
- {{- if site.Params.editURL.enable -}} - {{- $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 -}} + {{ partial "components/edit-url.html" (dict "source" "toc" "context" .) }} {{/* Scroll To Top */}}