Skip to content

Commit 55ceb91

Browse files
committed
Merge branch 'develop'
2 parents 4f9a619 + 220a64d commit 55ceb91

File tree

5 files changed

+88
-9
lines changed

5 files changed

+88
-9
lines changed

layouts/_default/baseof.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<link rel="preload" fetchpriority="low" as="image" href="/img/logo.svg" type="image/svg+xml">
1111
<link rel="preload" fetchpriority="low" href="/webfonts/fa-brands-400.woff2" as="font" type="font/woff2" crossorigin="anonymous">
1212
<link rel="preload" fetchpriority="low" href="/webfonts/fa-solid-900.woff2" as="font" type="font/woff2" crossorigin="anonymous">
13-
<meta property="og:url" content="{{ .Permalink }}">
13+
<meta property="og:url" content="{{ partial "canonical-url.html" . }}">
1414
<meta property="og:site_name" content="{{ .Site.Title }}">
1515
{{ if and (eq .Section "blog") .IsPage }}
1616
<meta name="description" content="{{ .Summary }}">
@@ -58,12 +58,7 @@
5858
<link rel="stylesheet" href="{{ $css.RelPermalink }}" integrity="{{ $css.Data.Integrity }}" media="screen" />
5959
{{ end }}
6060
<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="{{ .Site.LanguagePrefix }}/feed.xml" />
61-
{{ range .AllTranslations }}
62-
<link rel="alternate" hreflang="{{ .Language.LanguageCode }}" href="{{ .Permalink }}" />
63-
{{ if eq .Language.Lang "en" }}
64-
<link rel="alternate" hreflang="x-default" href="{{ .Permalink }}" />
65-
{{ end }}
66-
{{ end }}
61+
{{ partial "hreflang.html" . }}
6762
</head>
6863
<body x-data="{ isNavOpen: false, globalData: { githubStargazers: null, mastodonFollowers: null } }" x-init="determineGlobalData('{{ .Site.Language.Lang }}', globalData)" :class="isNavOpen && 'overflow-hidden'" class="bg-dark font-body text-gray-900">
6964
{{ partial "nav.html" . }}

layouts/partials/canonical-url.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{{/*
2+
Get canonical URL with pagination support
3+
Usage: {{ partial "canonical-url.html" . }}
4+
Returns: The canonical URL for the current page, including pagination path if applicable
5+
*/}}
6+
7+
{{/* Get current page number if paginated */}}
8+
{{ $pageNumber := 1 }}
9+
{{ $isPaginated := false }}
10+
{{ if and .IsNode .Paginator }}
11+
{{ $pageNumber = .Paginator.PageNumber }}
12+
{{ $isPaginated = true }}
13+
{{ end }}
14+
15+
{{/* Build canonical URL */}}
16+
{{ $canonicalURL := .Permalink }}
17+
{{ if and $isPaginated (gt $pageNumber 1) }}
18+
{{ $baseURL := .Permalink }}
19+
{{ if not (strings.HasSuffix $baseURL "/") }}
20+
{{ $baseURL = printf "%s/" $baseURL }}
21+
{{ end }}
22+
{{ $canonicalURL = printf "%spage/%d/" $baseURL $pageNumber }}
23+
{{ end }}
24+
25+
{{ return $canonicalURL }}

layouts/partials/hreflang.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{{/*
2+
Hreflang partial for handling pagination-aware alternate language links
3+
Usage: {{ partial "hreflang.html" . }}
4+
*/}}
5+
6+
{{/* Get current page number if paginated */}}
7+
{{ $pageNumber := 1 }}
8+
{{ $isPaginated := false }}
9+
{{ if and .IsNode .Paginator }}
10+
{{ $pageNumber = .Paginator.PageNumber }}
11+
{{ $isPaginated = true }}
12+
{{ end }}
13+
14+
{{/* Use canonical URL partial */}}
15+
<link rel="canonical" href="{{ partial "canonical-url.html" . }}" />
16+
17+
{{/* Include hreflang for all pages */}}
18+
{{ range .AllTranslations }}
19+
{{ $altURL := .Permalink }}
20+
{{ if and $isPaginated (gt $pageNumber 1) }}
21+
{{ $baseURL := .Permalink }}
22+
{{ if not (strings.HasSuffix $baseURL "/") }}
23+
{{ $baseURL = printf "%s/" $baseURL }}
24+
{{ end }}
25+
{{ $altURL = printf "%spage/%d/" $baseURL $pageNumber }}
26+
{{ end }}
27+
<link rel="alternate" hreflang="{{ .Language.LanguageCode }}" href="{{ $altURL }}" />
28+
{{ if eq .Language.Lang "en" }}
29+
<link rel="alternate" hreflang="x-default" href="{{ $altURL }}" />
30+
{{ end }}
31+
{{ end }}

layouts/partials/nav.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@
103103
<div class="relative">
104104
<ul x-show="isDropdownOpen" x-cloak class="absolute right-0 mt-6 py-2 w-48 bg-white rounded-sm shadow-md z-50">
105105
{{- range .Translations }}
106+
{{ $translationURL := partial "translation-url.html" (dict "context" $ "translation" .) }}
106107
<li>
107-
<a :href="'{{ .RelPermalink }}' + (window.location.search ?? '')" lang="{{ .Lang }}" class="block px-4 py-2 text-gray-800 hover:bg-secondary hover:text-white hover:no-underline" data-umami-event="nav-lang-{{ .Lang }}">{{ .Language.LanguageName }}</a>
108+
<a :href="'{{ $translationURL }}' + (window.location.search ?? '')" lang="{{ .Lang }}" class="block px-4 py-2 text-gray-800 hover:bg-secondary hover:text-white hover:no-underline" data-umami-event="nav-lang-{{ .Lang }}">{{ .Language.LanguageName }}</a>
108109
</li>
109110
{{- end }}
110111
</ul>
@@ -159,7 +160,8 @@
159160
</div>
160161
<div class="mt-1">
161162
{{ range .Translations }}
162-
<a :href="'{{ .RelPermalink }}' + (window.location.search ?? '')" lang="{{ .Lang }}" class="block px-2 py-1 hover:text-secondary hover:no-underline" data-umami-event="nav-lang-{{ .Lang }}">{{ .Language.LanguageName }}</a>
163+
{{ $translationURL := partial "translation-url.html" (dict "context" $ "translation" .) }}
164+
<a :href="'{{ $translationURL }}' + (window.location.search ?? '')" lang="{{ .Lang }}" class="block px-2 py-1 hover:text-secondary hover:no-underline" data-umami-event="nav-lang-{{ .Lang }}">{{ .Language.LanguageName }}</a>
163165
{{ end }}
164166
</div>
165167

layouts/partials/translation-url.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{/*
2+
Get translation URL with pagination support
3+
Usage: {{ partial "translation-url.html" (dict "context" $ "translation" .) }}
4+
Returns: The URL for the translation, including pagination path if applicable
5+
*/}}
6+
7+
{{ $ctx := .context }}
8+
{{ $translation := .translation }}
9+
10+
{{/* Get current page number */}}
11+
{{ $pageNumber := 1 }}
12+
{{ if and $ctx.IsNode $ctx.Paginator }}
13+
{{ $pageNumber = $ctx.Paginator.PageNumber }}
14+
{{ end }}
15+
16+
{{/* Build translation URL */}}
17+
{{ $url := $translation.RelPermalink }}
18+
{{ if gt $pageNumber 1 }}
19+
{{ $baseURL := $translation.RelPermalink }}
20+
{{ if not (strings.HasSuffix $baseURL "/") }}
21+
{{ $baseURL = printf "%s/" $baseURL }}
22+
{{ end }}
23+
{{ $url = printf "%spage/%d/" $baseURL $pageNumber }}
24+
{{ end }}
25+
26+
{{ return $url }}

0 commit comments

Comments
 (0)