From 46739dfefb54f2980002dadb7ce85810b9fe6d23 Mon Sep 17 00:00:00 2001 From: Angad Behl <77907286+slashtechno@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:39:34 +0000 Subject: [PATCH] feat: Customize partial to allow for global `ShowCanonicalLinks` --- content/blog/hello-world.md | 9 +++++++++ hugo.yaml | 6 ++++-- layouts/partials/post_canonical.html | 12 ++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 content/blog/hello-world.md create mode 100644 layouts/partials/post_canonical.html diff --git a/content/blog/hello-world.md b/content/blog/hello-world.md new file mode 100644 index 0000000..11e4bed --- /dev/null +++ b/content/blog/hello-world.md @@ -0,0 +1,9 @@ +--- +canonicalURL: http://itsfrommars.blogspot.com/2024/06/hello-world_11.html +date: 2024-06-19T09:37:00-07:00 +description: This is a simple blog post created using the Google API, just to say hello to the world. +lastmod: 2024-06-21T13:59:09-07:00 +title: Hello, world! +--- + +I created this post from the Google API. Hello, world! \ No newline at end of file diff --git a/hugo.yaml b/hugo.yaml index 94fed4e..3a57800 100644 --- a/hugo.yaml +++ b/hugo.yaml @@ -5,10 +5,12 @@ title: Cross Blogger Showcase theme: PaperMod params: - title: Hi, this is a test! - description: "This is a showcase of Cross Blogger, a headless CMS for Hugo." + description: 'Example Hugo site using Cross Blogger to use Blogger as a headless CMS' env: production # Enables enhanced SEO + CanonicalLinkText: "Canonical URLs can optionally be enabled. This post was fetched from" + ShowCanonicalLinks: true profileMode: + subtitle: 'The blog posts below are fetched from Blogger using Cross Blogger' enabled: true buttons: - name: Blog diff --git a/layouts/partials/post_canonical.html b/layouts/partials/post_canonical.html new file mode 100644 index 0000000..a79c0dd --- /dev/null +++ b/layouts/partials/post_canonical.html @@ -0,0 +1,12 @@ +{{ if and .Params.canonicalURL (or .Params.ShowCanonicalLink site.Params.ShowCanonicalLinks) -}} + +{{ $url := urls.Parse .Params.canonicalURL }} + +{{ $urlWithoutScheme := replaceRE "^https?://" "" $url.String }} + +{{- 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" -}} +  {{ $urlWithoutScheme}} + +{{- end }}