seo: enforce trailing slash on all URLs
Deploy / verify (push) Successful in 37s
Deploy / deploy (push) Successful in 55s

- Set trailingSlash='always' globally via root layout.
- Update postHref, pageHref, Pagination, tag/breadcrumb hrefs, blog→posts
  redirects to emit trailing slash.
- Match old Astro canonical so indexed URLs hit 200 directly instead of
  308-redirect.
This commit is contained in:
Peter Meier
2026-04-17 22:23:16 +02:00
parent d28a55a70a
commit f328989aa8
12 changed files with 24 additions and 19 deletions
+6 -2
View File
@@ -1,4 +1,7 @@
import type { LayoutServerLoad } from './$types';
export const trailingSlash = 'always';
import {
getNavigationByKey,
NavigationKeys,
@@ -71,7 +74,7 @@ export const load: LayoutServerLoad = async ({ locals }) => {
for (const p of posts) {
const label = p.linkName ?? p.headline ?? p.slug ?? p._slug ?? '';
const urlSlug = normalizeSlug(p.slug ?? p._slug);
const canonical = urlSlug ? `/post/${encodeURIComponent(urlSlug)}` : '';
const canonical = urlSlug ? `/post/${encodeURIComponent(urlSlug)}/` : '';
const keySlug = normalizeSlug(p.slug);
const keyUnderscore = normalizeSlug(p._slug);
if (keySlug) {
@@ -111,7 +114,8 @@ export const load: LayoutServerLoad = async ({ locals }) => {
.split('/')
.filter(Boolean)
.map((seg) => encodeURIComponent(seg))
.join('/');
.join('/') +
'/';
const href = postHref ?? pageHref;
headerLinks.push({ href, label });
}