Skip to content

Commit 769e51d

Browse files
authored
Add showCanonicalLink to markdown metadata (adityatelange#428)
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
1 parent 93fd278 commit 769e51d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

layouts/_default/single.html

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ <h1 class="post-title">
1717
{{- partial "post_meta.html" . -}}
1818
{{- partial "translation_list.html" . -}}
1919
{{- partial "edit_post.html" . -}}
20+
{{- partial "post_canonical.html" . -}}
2021
</div>
2122
{{- end }}
2223
</header>

layouts/partials/post_canonical.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{ if and (.Params.canonicalURL) (.Params.ShowCanonicalLink ) -}}
2+
{{ $url := urls.Parse .Params.canonicalURL }}
3+
4+
{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) .IsTranslated (or .Params.editPost.URL .Site.Params.editPost.URL) }}&nbsp;|&nbsp;{{- end -}}
5+
<span>
6+
{{- (.Site.Params.CanonicalLinkText | default .Params.CanonicalLinkText) | default "Originally published at" -}}
7+
&nbsp;<a href="{{ trim .Params.canonicalURL " " }}" title="{{ trim .Params.canonicalURL " " }}" target="_blank" rel="noopener noreferrer">{{ $url.Host }}</a>
8+
</span>
9+
{{- end }}

0 commit comments

Comments
 (0)