seo: enforce trailing slash on all URLs
- 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:
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user