feat: Customize partial to allow for global `ShowCanonicalLinks`

This commit is contained in:
Angad Behl 2024-06-25 15:39:34 +00:00 committed by GitHub
parent 01eb2b2b5c
commit 46739dfefb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 2 deletions

View File

@ -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!

View File

@ -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

View File

@ -0,0 +1,12 @@
{{ if and .Params.canonicalURL (or .Params.ShowCanonicalLink site.Params.ShowCanonicalLinks) -}}
<!-- https://gohugo.io/functions/urls/parse/ -->
{{ $url := urls.Parse .Params.canonicalURL }}
<!-- https://gohugo.io/functions/strings/replacere/ -->
{{ $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) }}&nbsp;|&nbsp;{{- end -}}
<span>
{{- (site.Params.CanonicalLinkText | default .Params.CanonicalLinkText) | default "Originally published at" -}}
&nbsp;<a href="{{ trim .Params.canonicalURL " " }}" title="{{ trim .Params.canonicalURL " " }}" target="_blank" rel="noopener noreferrer">{{ $urlWithoutScheme}}</a>
</span>
{{- end }}