From 00f6db19d9e1b160007a04c046dfcbefad6595e0 Mon Sep 17 00:00:00 2001 From: David Legrand <1110600+davlgd@users.noreply.github.com> Date: Wed, 14 Feb 2024 01:31:36 +0100 Subject: [PATCH] Fixes after review - `where` > `location` - Edit link > in a partial --- exampleSite/hugo.yaml | 2 +- layouts/partials/components/edit-url.html | 19 +++++++++++++++++++ layouts/partials/components/last-updated.html | 18 +----------------- layouts/partials/toc.html | 18 +----------------- 4 files changed, 22 insertions(+), 35 deletions(-) create mode 100644 layouts/partials/components/edit-url.html diff --git a/exampleSite/hugo.yaml b/exampleSite/hugo.yaml index 943cb8bd..a444415e 100644 --- a/exampleSite/hugo.yaml +++ b/exampleSite/hugo.yaml @@ -133,7 +133,7 @@ params: editURL: enable: true - where: "toc" # single | toc + 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 00000000..5506e022 --- /dev/null +++ b/layouts/partials/components/edit-url.html @@ -0,0 +1,19 @@ +{{- $editThisPage := (T "editThisPage") | default "Edit this page"}} + +
+ {{- if and (site.Params.editURL.enable) (eq site.Params.editURL.location .source) -}} + {{- $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 -}} \ No newline at end of file diff --git a/layouts/partials/components/last-updated.html b/layouts/partials/components/last-updated.html index 37c68c7c..23b75f63 100644 --- a/layouts/partials/components/last-updated.html +++ b/layouts/partials/components/last-updated.html @@ -2,23 +2,7 @@ {{- $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 -}} +{{ partial "components/edit-url.html" (dict "source" "single") }} {{- with .Lastmod -}} {{ $datetime := (time.Format "2006-01-02T15:04:05.000Z" .) }} {{ $lastUpdated }}
diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html index 1c65e97e..23f674f2 100644 --- a/layouts/partials/toc.html +++ b/layouts/partials/toc.html @@ -23,23 +23,7 @@ {{- end -}} {{/* TOC bottom part */}} -
- {{- 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 */}} - {{- $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") }} {{/* Scroll To Top */}}