From 38891b9062100a1f6f5d9e0474d4ca702c4a9db0 Mon Sep 17 00:00:00 2001 From: nikaera Date: Fri, 22 Oct 2021 23:22:45 +0900 Subject: [PATCH] Add `showCanonicalLink` to markdown metadata (#428) If an article has a `canonicalUrl` set, Originally published at `` will be displayed at the top of the article by setting `showCanonicalLink` to true. Usage => In front-matter: canonicalUrl: "" showCanonicalLink: true --- layouts/_default/single.html | 1 + layouts/partials/post_canonical.html | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 layouts/partials/post_canonical.html diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 355697e2..1d983fd0 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" . -}} {{- end }} diff --git a/layouts/partials/post_canonical.html b/layouts/partials/post_canonical.html new file mode 100644 index 00000000..9befad12 --- /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 -}} + + {{- (.Site.Params.CanonicalLinkText | default .Params.CanonicalLinkText) | default "Originally published at" -}} +  {{ $url.Host }} + +{{- end }}