From 111456910fcb16b263fd2f9284d4ff923122ffac Mon Sep 17 00:00:00 2001 From: spivakov83 Date: Tue, 27 Jan 2026 11:46:25 +0200 Subject: [PATCH] feat: Enhance canonical URL consistency by removing 'www' from the default site URL, adding a root canonical link, and improving absolute URL generation. --- app/layout.tsx | 3 +++ lib/site-metadata.ts | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/layout.tsx b/app/layout.tsx index 8d2ef7b..705b549 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -60,6 +60,9 @@ export const metadata: Metadata = { default: siteTitle, template: `%s | DevContext`, }, + alternates: { + canonical: "/", + }, applicationName: "DevContext", description: siteDescription, keywords: [ diff --git a/lib/site-metadata.ts b/lib/site-metadata.ts index 06447ba..777c979 100644 --- a/lib/site-metadata.ts +++ b/lib/site-metadata.ts @@ -1,4 +1,4 @@ -const DEFAULT_SITE_URL = "https://www.devcontext.xyz"; +const DEFAULT_SITE_URL = "https://devcontext.xyz"; const normalizeSiteUrl = (input: string): string => { const trimmed = input.trim(); @@ -23,9 +23,13 @@ export const SITE_URL = normalizeSiteUrl( export const CANONICAL_HOST = new URL(SITE_URL).hostname; export const absoluteUrl = (path = ""): string => { - if (!path || path === "/") { - return SITE_URL; + const base = SITE_URL.endsWith("/") ? SITE_URL.slice(0, -1) : SITE_URL; + const normalizedPath = path.startsWith("/") ? path : `/${path}`; + + // Ensure the root path always has a trailing slash for SEO consistency + if (normalizedPath === "/") { + return `${base}/`; } - return `${SITE_URL}${path.startsWith("/") ? path : `/${path}`}`; + return `${base}${normalizedPath}`; };