From 5f86db2efd6199bb357906c86cc4a16cf958ab26 Mon Sep 17 00:00:00 2001 From: Syphdias Date: Mon, 1 Mar 2021 01:29:49 +0100 Subject: [PATCH 1/8] Add option to show link in meta data for editing posts The idea was inspired by the [stapelberg theme]. If `editPostUrl` is set, its value will be used to create a link for every post is displayed in the meta data of the post (if meta not hidden). This is useful for providing the reader with an easy way to find the proper place to suggest changes. An example would be an edit prefix for the proper git repo, e.g.: ``` Params: editPostUrl: "https://github.com/adityatelange/hugo-PaperMod/edit/exampleSite" ``` For the post saved in `content/posts/markdown-syntax.md`, this will lead to an href of "https://github.com/adityatelange/hugo-PaperMod/edit/exampleSite/content/posts/markdown-syntax.md" The text for the edit button defaults to "Edit" or a translation if available but can be changed individually by setting the parameter `editPostText`. This closes #238. [stapelberg theme]: https://github.com/stapelberg/hugo/blob/d0b2a3edb61a855d87debc3d974ed250853aa931/themes/stapelberg/layouts/_default/single.html#L46 --- i18n/de.yaml | 3 +++ layouts/_default/single.html | 1 + layouts/partials/edit_post.html | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 layouts/partials/edit_post.html diff --git a/i18n/de.yaml b/i18n/de.yaml index 66412775c1..fcb53301b1 100644 --- a/i18n/de.yaml +++ b/i18n/de.yaml @@ -14,3 +14,6 @@ - id: translations translation: "Übersetzungen" + +- id: edit_post + translation: "Bearbeiten" diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 3673ea634e..3543dbbb09 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -16,6 +16,7 @@

{{- end}} diff --git a/layouts/partials/edit_post.html b/layouts/partials/edit_post.html new file mode 100644 index 0000000000..d11a3eb47c --- /dev/null +++ b/layouts/partials/edit_post.html @@ -0,0 +1,3 @@ +{{- if (.Param "editPostUrl") }} + · {{ .Param "editPostText" | i18n "edit_post" | default "Edit" }} +{{- end }} From d0da8b26041490faf7810ce5caf3d93085744def Mon Sep 17 00:00:00 2001 From: Syphdias Date: Mon, 1 Mar 2021 15:41:07 +0100 Subject: [PATCH 2/8] Change editPost parameter and move logic to post_meta partial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Instead of two separate parameters `editPostUrl` and `editPostText` there is now the `editPost` hash with `URL` and `Text` ``` Params: editPost: URL: "https://github.com/adityatelange/hugo-PaperMod/edit/exampleSite" Text: "Suggest Changes" ``` - Moved insertion of link to post_meta to prevent extra `·` from showing up --- layouts/_default/single.html | 1 - layouts/partials/edit_post.html | 3 --- layouts/partials/post_meta.html | 4 ++++ 3 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 layouts/partials/edit_post.html diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 3543dbbb09..3673ea634e 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -16,7 +16,6 @@

{{- end}} diff --git a/layouts/partials/edit_post.html b/layouts/partials/edit_post.html deleted file mode 100644 index d11a3eb47c..0000000000 --- a/layouts/partials/edit_post.html +++ /dev/null @@ -1,3 +0,0 @@ -{{- if (.Param "editPostUrl") }} - · {{ .Param "editPostText" | i18n "edit_post" | default "Edit" }} -{{- end }} diff --git a/layouts/partials/post_meta.html b/layouts/partials/post_meta.html index d0cf176181..18251104ef 100644 --- a/layouts/partials/post_meta.html +++ b/layouts/partials/post_meta.html @@ -12,6 +12,10 @@ {{ $scratch.Add "meta" (slice .)}} {{end}} +{{- if (.Param "editPost") }} +{{ $scratch.Add "meta" (printf "%s" (.Param "editPost.URL") .File.Path (.Param "editPost.Text" | i18n "edit_post" | default "Edit") ) }} +{{- end -}} + {{- with ($scratch.Get "meta")}} {{- delimit . " · "}} {{- end }} From 9626101a67d4e70b5377bf9f93aab7602adf0b83 Mon Sep 17 00:00:00 2001 From: Syphdias Date: Mon, 1 Mar 2021 16:09:59 +0100 Subject: [PATCH 3/8] Check editPost.URL instead of editPost to prevent empty links --- layouts/partials/post_meta.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layouts/partials/post_meta.html b/layouts/partials/post_meta.html index 18251104ef..3cdcdda657 100644 --- a/layouts/partials/post_meta.html +++ b/layouts/partials/post_meta.html @@ -12,7 +12,7 @@ {{ $scratch.Add "meta" (slice .)}} {{end}} -{{- if (.Param "editPost") }} +{{- if (.Param "editPost.URL") }} {{ $scratch.Add "meta" (printf "%s" (.Param "editPost.URL") .File.Path (.Param "editPost.Text" | i18n "edit_post" | default "Edit") ) }} {{- end -}} From da4061c9d996ccda0445744c077e91fcdd2984ed Mon Sep 17 00:00:00 2001 From: Syphdias Date: Mon, 1 Mar 2021 16:13:33 +0100 Subject: [PATCH 4/8] Fix ability to change editPost.Text --- layouts/partials/post_meta.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layouts/partials/post_meta.html b/layouts/partials/post_meta.html index 3cdcdda657..947b095bb2 100644 --- a/layouts/partials/post_meta.html +++ b/layouts/partials/post_meta.html @@ -13,7 +13,7 @@ {{end}} {{- if (.Param "editPost.URL") }} -{{ $scratch.Add "meta" (printf "%s" (.Param "editPost.URL") .File.Path (.Param "editPost.Text" | i18n "edit_post" | default "Edit") ) }} +{{ $scratch.Add "meta" (printf "%s" (.Param "editPost.URL") .File.Path (.Param "editPost.Text" | default (i18n "edit_post" | default "Edit")) ) }} {{- end -}} {{- with ($scratch.Get "meta")}} From 6c33cd7ebae5abdb80de0c9963c2fb854af1513e Mon Sep 17 00:00:00 2001 From: Syphdias Date: Sat, 6 Mar 2021 16:39:13 +0100 Subject: [PATCH 5/8] Move edit Link to separate partial to only include it in single The edit link is not wanted in search archives and list view. This is why the partial edit_post was created like previously. Some adjustments to the translation_list partial were necessary to show separator if not meta is available but edit link is shown. --- layouts/_default/single.html | 1 + layouts/partials/edit_post.html | 4 ++++ layouts/partials/post_meta.html | 4 ---- layouts/partials/translation_list.html | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 layouts/partials/edit_post.html diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 3673ea634e..84699425ab 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -15,6 +15,7 @@

{{- if not (.Param "hideMeta") }} {{- end}} diff --git a/layouts/partials/edit_post.html b/layouts/partials/edit_post.html new file mode 100644 index 0000000000..4b31dd680a --- /dev/null +++ b/layouts/partials/edit_post.html @@ -0,0 +1,4 @@ +{{- if (.Param "editPost.URL") -}} +{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) }}| {{- end -}} +{{ .Param "editPost.Text" | default (i18n "edit_post" | default "Edit") }} +{{- end }} diff --git a/layouts/partials/post_meta.html b/layouts/partials/post_meta.html index 947b095bb2..d0cf176181 100644 --- a/layouts/partials/post_meta.html +++ b/layouts/partials/post_meta.html @@ -12,10 +12,6 @@ {{ $scratch.Add "meta" (slice .)}} {{end}} -{{- if (.Param "editPost.URL") }} -{{ $scratch.Add "meta" (printf "%s" (.Param "editPost.URL") .File.Path (.Param "editPost.Text" | default (i18n "edit_post" | default "Edit")) ) }} -{{- end -}} - {{- with ($scratch.Get "meta")}} {{- delimit . " · "}} {{- end }} diff --git a/layouts/partials/translation_list.html b/layouts/partials/translation_list.html index a2c2d86cef..f22617971c 100644 --- a/layouts/partials/translation_list.html +++ b/layouts/partials/translation_list.html @@ -1,6 +1,6 @@ {{- if .IsTranslated -}} {{- if (ne .Layout "search")}} -{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) }} | {{- end -}} +{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) (.Param "editPost.URL") }} | {{- end -}} {{- end }}
    {{- i18n "translations" | default "Translations"}}: From bf6dafd23d4107018da01bfc8dd28f5262ec6219 Mon Sep 17 00:00:00 2001 From: Syphdias Date: Mon, 22 Mar 2021 22:22:01 +0100 Subject: [PATCH 6/8] Add wishes from last review - swap translation_list and edit_post - avoid `.Param` - add `rel="noopener noreferrer"` - add `target="_blank"` --- layouts/_default/single.html | 2 +- layouts/partials/edit_post.html | 6 +++--- layouts/partials/translation_list.html | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 84699425ab..3543dbbb09 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -15,8 +15,8 @@

    {{- if not (.Param "hideMeta") }} {{- end}} diff --git a/layouts/partials/edit_post.html b/layouts/partials/edit_post.html index 4b31dd680a..e6a195e9e8 100644 --- a/layouts/partials/edit_post.html +++ b/layouts/partials/edit_post.html @@ -1,4 +1,4 @@ -{{- if (.Param "editPost.URL") -}} -{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) }}| {{- end -}} -{{ .Param "editPost.Text" | default (i18n "edit_post" | default "Edit") }} +{{- if or .Params.editPost.URL .Site.Params.editPost.URL -}} +{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) .IsTranslated }}| {{- end -}} +{{ .Params.editPost.Text | default (.Site.Params.editPost.Text | default (i18n "edit_post" | default "Edit") ) }} {{- end }} diff --git a/layouts/partials/translation_list.html b/layouts/partials/translation_list.html index f22617971c..a2c2d86cef 100644 --- a/layouts/partials/translation_list.html +++ b/layouts/partials/translation_list.html @@ -1,6 +1,6 @@ {{- if .IsTranslated -}} {{- if (ne .Layout "search")}} -{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) (.Param "editPost.URL") }} | {{- end -}} +{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) }} | {{- end -}} {{- end }}
      {{- i18n "translations" | default "Translations"}}: From 8759ee3549775544d2066c6a3418ee33ba915640 Mon Sep 17 00:00:00 2001 From: Syphdias Date: Tue, 23 Mar 2021 09:26:12 +0100 Subject: [PATCH 7/8] Add ability to not append file path in editPost.URL set `editPost.appendFilePath` to `false` to not append file paths --- layouts/partials/edit_post.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/layouts/partials/edit_post.html b/layouts/partials/edit_post.html index e6a195e9e8..54819dae37 100644 --- a/layouts/partials/edit_post.html +++ b/layouts/partials/edit_post.html @@ -1,4 +1,6 @@ {{- if or .Params.editPost.URL .Site.Params.editPost.URL -}} {{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) .IsTranslated }}| {{- end -}} -{{ .Params.editPost.Text | default (.Site.Params.editPost.Text | default (i18n "edit_post" | default "Edit") ) }} + + {{- .Params.editPost.Text | default (.Site.Params.editPost.Text | default (i18n "edit_post" | default "Edit") ) -}} + {{- end }} From 3dfa403b49c54cd1dfe0ecba685bc67456f41f81 Mon Sep 17 00:00:00 2001 From: Syphdias Date: Tue, 23 Mar 2021 09:33:42 +0100 Subject: [PATCH 8/8] Correct default for editPost.appendFilePath --- layouts/partials/edit_post.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layouts/partials/edit_post.html b/layouts/partials/edit_post.html index 54819dae37..21a33eb5fb 100644 --- a/layouts/partials/edit_post.html +++ b/layouts/partials/edit_post.html @@ -1,6 +1,6 @@ {{- if or .Params.editPost.URL .Site.Params.editPost.URL -}} {{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) .IsTranslated }}| {{- end -}} - + {{- .Params.editPost.Text | default (.Site.Params.editPost.Text | default (i18n "edit_post" | default "Edit") ) -}} {{- end }}