diff options
| author | nikaera <GimNikaErast@gmail.com> | 2021-10-22 23:22:45 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-22 19:52:45 +0530 |
| commit | 38891b9062100a1f6f5d9e0474d4ca702c4a9db0 (patch) | |
| tree | 5dabe939d10d7c1e19f0689ea4d59bbadddf7c7f /layouts | |
| parent | a57cb762c320c05b616f7911c8b5dc78e3080a72 (diff) | |
Add `showCanonicalLink` to markdown metadata (#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
Diffstat (limited to 'layouts')
| -rw-r--r-- | layouts/_default/single.html | 1 | ||||
| -rw-r--r-- | layouts/partials/post_canonical.html | 9 |
2 files changed, 10 insertions, 0 deletions
diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 355697e..1d983fd 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -17,6 +17,7 @@ {{- partial "post_meta.html" . -}} {{- partial "translation_list.html" . -}} {{- partial "edit_post.html" . -}} + {{- partial "post_canonical.html" . -}} </div> {{- end }} </header> diff --git a/layouts/partials/post_canonical.html b/layouts/partials/post_canonical.html new file mode 100644 index 0000000..9befad1 --- /dev/null +++ b/layouts/partials/post_canonical.html @@ -0,0 +1,9 @@ +{{ if and (.Params.canonicalURL) (.Params.ShowCanonicalLink ) -}} +{{ $url := urls.Parse .Params.canonicalURL }} + +{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) .IsTranslated (or .Params.editPost.URL .Site.Params.editPost.URL) }} | {{- end -}} +<span> + {{- (.Site.Params.CanonicalLinkText | default .Params.CanonicalLinkText) | default "Originally published at" -}} + <a href="{{ trim .Params.canonicalURL " " }}" title="{{ trim .Params.canonicalURL " " }}" target="_blank" rel="noopener noreferrer">{{ $url.Host }}</a> +</span> +{{- end }} |
