-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to show link in meta data for editing posts #278
Conversation
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 adityatelange#238. [stapelberg theme]: https://github.com/stapelberg/hugo/blob/d0b2a3edb61a855d87debc3d974ed250853aa931/themes/stapelberg/layouts/_default/single.html#L46
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- How about adding this to
post_meta
partial so that it would not display extra·
when other meta params are empty - It would be appropriate to keep
editPost
params with each other
like shown below in site configparams: editPost: URL: https://github.com/adityatelange/hugo-PaperMod/tree/exampleSite Text: "Edit"
- 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
I moved the link to
I have no idea why
Makes sense. Changed. |
@Syphdias I see edit button in |
|
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.
@Syphdias I implemented one of my suggestions from my last comment. I decided to go with I also picked up @kdkasad's suggestion to make the URL more flexible. Would be great if you could give it another look. |
Hey @adityatelange, I was wondering if you could give it another look 🙂 |
Yes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good to me :) , just can we move Edit
link to end of post-meta
? Also how about opening links in new tab (don't forget to add rel="noopener noreferrer"
)?
Also maybe we should add a param named NoGit
so that @kdkasad's previous comment could be taken into consideration so that a mailto
link could be added for non-git edit requests
As if NonGit = true
we could only link URL
and not the path with it
Also I have doubt with usage of .Param
with string values, empty strings can make issues somehow..
refer: https://gohugo.io/functions/param/ and gohugoio/hugo#3366
in that case {{ .Params.editPost.URL | default .Site.Params.editPost.URL }}
should be use imo.
- swap translation_list and edit_post - avoid `.Param` - add `rel="noopener noreferrer"` - add `target="_blank"`
This is three things:
How wrong did I interpret this?
<a href="mailto://[email protected]?subject=Suggesting%20changes%20for%20/posts/my-first-post.md" rel="noopener noreferrer" target="_blank">Edit</a> So I would suggest adding another option, if you do not want the page. Something like
=> done, I hope I got everything. Question though: There is |
End of post-meta means at the last position in the class
Opening in new tab
No you didn't.
Okay
If it works no need to (info here https://gohugo.io/templates/introduction/#2-use--to-access-the-global-context) |
Wiki of this repo. I clone the same to |
But wouldn't you want to append the file path if you used a git provider link?
Ah, thank you!
Ah, so the wiki is the complete one and |
set `editPost.appendFilePath` to `false` to not append file paths
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
I implemented |
@Syphdias Nice Work ! 👍 Sorry for keeping this PR for too long. |
I couldn't edit the wiki directly, so I cloned the Feel free to change what I have written. Maybe it saves you some time. |
appendFilePath appends the file name with backword slash. |
Oh, sorry about that.
VSCode has nothing to do with it. Apparently Quick and dirty fix below. Warning: Breaks other stuff like diff --git a/layouts/partials/edit_post.html b/layouts/partials/edit_post.html
index 21a33eb5..925b2f8c 100644
--- a/layouts/partials/edit_post.html
+++ b/layouts/partials/edit_post.html
@@ -1,6 +1,7 @@
+{{- $fileUrlPath := path.Join (split .File.Path "\\") }}
{{- if or .Params.editPost.URL .Site.Params.editPost.URL -}}
{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) .IsTranslated }}| {{- end -}}
-<a href="{{ .Params.editPost.URL | default .Site.Params.editPost.URL }}{{ if .Params.editPost.appendFilePath | default ( .Site.Params.editPost.appendFilePath | default false ) }}/{{ .File.Path }}{{ end }}" rel="noopener noreferrer" target="_blank">
+<a href="{{ .Params.editPost.URL | default .Site.Params.editPost.URL }}{{ if .Params.editPost.appendFilePath | default ( .Site.Params.editPost.appendFilePath | default false ) }}/{{ $fileUrlPath }}{{ end }}" rel="noopener noreferrer" target="_blank">
{{- .Params.editPost.Text | default (.Site.Params.editPost.Text | default (i18n "edit_post" | default "Edit") ) -}}
</a>
{{- end }} I guess the right way would be to use
Does that mean a this would convert a path? |
yes.. i checked this.. @Syphdias .. this fix is working in windows.. |
@openact The patch or the |
I tried patch.. I did not get what to do in |
Let's say you have these file:
The patch does something simple: Take the
If it does not work, the proper way to do this would be to use Edit: probably |
Nope, I was right the first time... I might be wrong, but I think this OS-independent behavior is intentional because it look like hugo uses this function internally to build URLs. So this should not break in future releases. *knock on wood* PS: Fun fact: I can't normally git checkout my current test repo HEAD since it includes a file with |
`.File.Path` is OS dependant and uses `\` as directory separator. This leads to cases where posts get the wrong URL, if in a sub folder, e.g. `content/posts/folder\post.md`. One idea was to replace `\` with `/` this however breaks valid files (on Unix systems) which include `\` in the file name. According to the docs [`path.Join`](layouts/partials/edit_post.html) is OS unaware and converts to a Unix-like path. > Note: All path elements on Windows are converted to slash ('/') separators. PS: It looks like hugo also uses this internally to build URLs. PPS: Solution was discussed in adityatelange#278.
@openact, checkout #333 if it fixes your problem. |
`.File.Path` is OS dependant and uses `\` as directory separator. This leads to cases where posts get the wrong URL, if in a sub folder, e.g. `content/posts/folder\post.md`. One idea was to replace `\` with `/` this however breaks valid files (on Unix systems) which include `\` in the file name. According to the docs [`path.Join`](layouts/partials/edit_post.html) is OS unaware and converts to a Unix-like path. > Note: All path elements on Windows are converted to slash ('/') separators. PS: It looks like hugo also uses this internally to build URLs. PPS: Solution was discussed in #278.
…#278) Usage - in site config => Params: editPost: URL: "https://github.com/<path_to_repo>/content" Text: "Suggest Changes" # edit text appendFilePath: true # to append file path to Edit link - in front-matter vars => --- editPost: URL: "https://github.com/<path_to_repo>/content" Text: "Suggest Changes" # edit text appendFilePath: true # to append file path to Edit link --- - Front-matter vars overrides global ones
`.File.Path` is OS dependant and uses `\` as directory separator. This leads to cases where posts get the wrong URL, if in a sub folder, e.g. `content/posts/folder\post.md`. One idea was to replace `\` with `/` this however breaks valid files (on Unix systems) which include `\` in the file name. According to the docs [`path.Join`](layouts/partials/edit_post.html) is OS unaware and converts to a Unix-like path. > Note: All path elements on Windows are converted to slash ('/') separators. PS: It looks like hugo also uses this internally to build URLs. PPS: Solution was discussed in adityatelange#278.
The idea was inspired by the stapelberg theme.
If
editPostUrl
is set, its value will be used to create a link for every postis 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.:
For the post saved in
content/posts/markdown-syntax.md
, this will lead to anhref 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.
PS: There is one issue that is not being addressed by this PR and that is docs – and I don't think I can directly solve this in this PR.
Where is documentations supposed to go?
README.md
on branchmaster
?content/posts/papermod/papermod-variables.md
on branchexampleSite
Also: