Skip to content
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 showCanonicalLink to markdown metadata #428

Merged
merged 8 commits into from
Oct 22, 2021

Conversation

nikaera
Copy link
Contributor

@nikaera nikaera commented May 30, 2021

Thank you for making a great Hugo theme! I'm using your theme on my blog. 📝

I would like to display the URL of the original article, like DEV articles do, if canonicalUrl is set in the article metadata. Therefore, I added a new field showCanonicalLink to the metadata so that if an article has a canonicalUrl set, Originally published at <hostname> will be displayed at the top of the article by setting showCanonicalLink to true. 🌐

The actual contents of the display are as follows. ⬇️

---
#...
canonicalUrl: "https://zenn.dev/nikaera/articles/unity-gameci-github-actions"
showCanonicalLink: true
#...
---
#...

Articles with canonicalUrl set and showCanonicalLink field set to true

I submitted a pull request because I am using a custom template to achieve this functionality and figured I would use it often. I would appreciate it if you could take it in if you like. 🙏

@nikaera
Copy link
Contributor Author

nikaera commented May 30, 2021

1 Security Hotspot

I have fixed the above. ⚒️

@adityatelange
Copy link
Owner

@nikaera Doesn't really fit well on smaller screens.

image


I would suggest this to be implemented, similar to how EditPost is implemented

{{- if or .Params.editPost.URL .Site.Params.editPost.URL -}}
{{- $fileUrlPath := path.Join .File.Path }}
{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) .IsTranslated }}&nbsp;|&nbsp;{{- end -}}
<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 }}

That way, we can have the same feature but it will fit well on smaller screens as well as we won't need to add extra styling for it.

@nikaera
Copy link
Contributor Author

nikaera commented Jun 17, 2021

@adityatelange Thank you for your comment! I used edit_post.html as a reference and modified it.

There was a change in the appearance as follows. ⬇️
[PC Browser]
スクリーンショット 2021-06-18 0 50 43

[Mobile Browser]
スクリーンショット 2021-06-18 0 51 19

I would appreciate your review. 🙏

@sonarcloud
Copy link

sonarcloud bot commented Jun 20, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@adityatelange
Copy link
Owner

adityatelange commented Jun 20, 2021

@nikaera I have made some changes to the code. Can you please check if everything is good? 😄
p.s. Do check commit log to see what's changed
image

image

@nikaera
Copy link
Contributor Author

nikaera commented Jun 20, 2021

@adityatelange Wow, thank you so much! 👀😆 I have checked all the modifications and LGTM! 🙌

@adityatelange adityatelange merged commit 38891b9 into adityatelange:master Oct 22, 2021
@adityatelange adityatelange added the enhancement New feature or improvement label Oct 30, 2021
kylethedeveloper pushed a commit to kylethedeveloper/hugo-PaperMod that referenced this pull request Feb 21, 2023
If an article has a `canonicalUrl` set, Originally published at `<hostname>` will be displayed at the top of the article by setting `showCanonicalLink` to true. 

Usage =>
  In front-matter:
    canonicalUrl: "<URL>"
    showCanonicalLink: true
@nikaera nikaera deleted the feat/show-canonical-link branch February 1, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants