Skip to content

Commit 5b2a964

Browse files
committed
feat: Enhance canonical URL consistency by removing 'www' from the default site URL, adding a root canonical link, and improving absolute URL generation.
1 parent 7bb41da commit 5b2a964

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

app/layout.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export const metadata: Metadata = {
6060
default: siteTitle,
6161
template: `%s | DevContext`,
6262
},
63+
alternates: {
64+
canonical: "/",
65+
},
6366
applicationName: "DevContext",
6467
description: siteDescription,
6568
keywords: [

lib/site-metadata.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const DEFAULT_SITE_URL = "https://www.devcontext.xyz";
1+
const DEFAULT_SITE_URL = "https://devcontext.xyz";
22

33
const normalizeSiteUrl = (input: string): string => {
44
const trimmed = input.trim();
@@ -23,9 +23,13 @@ export const SITE_URL = normalizeSiteUrl(
2323
export const CANONICAL_HOST = new URL(SITE_URL).hostname;
2424

2525
export const absoluteUrl = (path = ""): string => {
26-
if (!path || path === "/") {
27-
return SITE_URL;
26+
const base = SITE_URL.endsWith("/") ? SITE_URL.slice(0, -1) : SITE_URL;
27+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
28+
29+
// Ensure the root path always has a trailing slash for SEO consistency
30+
if (normalizedPath === "/") {
31+
return `${base}/`;
2832
}
2933

30-
return `${SITE_URL}${path.startsWith("/") ? path : `/${path}`}`;
34+
return `${base}${normalizedPath}`;
3135
};

0 commit comments

Comments
 (0)