Skip to content

Commit

Permalink
feat: Improve canonicalURL for Netlify CMS (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris authored Jul 10, 2021
1 parent bac23f3 commit 0484dc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions layouts/partials/canonical-link.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{ with $.Page.Params.canonicalURL }}
{{ $url := urls.Parse $.Page.Params.canonicalURL }}
{{ if $url.Host }}
{{ i18n "canonical_link" . }}
<a href="{{ . | safeURL }}" rel="noopener noreferrer" target="_blank">{{ (. | safeURL | urls.Parse).Host }}</a>
<a href="{{ $.Page.Params.canonicalURL | safeURL }}" rel="noopener noreferrer" target="_blank">{{ $url.Host }}</a>
{{ end }}
5 changes: 3 additions & 2 deletions layouts/partials/head/general.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<!-- Open Graph Protocol (OGP) -->
{{ partial "head/ogp" . }}

{{ with .Page.Params.canonicalURL }}
<link rel="canonical" href="{{ . | safeURL }}">
{{ $canonicalURL := urls.Parse $.Page.Params.canonicalURL }}
{{ if $canonicalURL.Host }}
<link rel="canonical" href="{{ $.Page.Params.canonicalURL | safeURL }}">
{{ end }}

0 comments on commit 0484dc0

Please sign in to comment.