Skip to content

Commit 65dcca3

Browse files
committed
feat: update canonical URLs in metadata generation for various pages
1 parent 9f63ae6 commit 65dcca3

File tree

8 files changed

+13
-7
lines changed

8 files changed

+13
-7
lines changed

app/[locale]/about/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export async function generateMetadata({
5252
description: t("description"),
5353
locale: locale as Locale,
5454
path: `/about`,
55+
canonicalUrl: `/about`,
5556
});
5657
}
5758

app/[locale]/blogs/[slug]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export async function generateMetadata({
3131
noIndex: true,
3232
locale: locale as Locale,
3333
path: `/blogs/${slug}`,
34+
canonicalUrl: `/blogs/${slug}`,
3435
});
3536
}
3637

@@ -41,7 +42,7 @@ export async function generateMetadata({
4142
images: post.image ? [post.image] : [],
4243
locale: locale as Locale,
4344
path: `/blogs/${slug}`,
44-
// canonicalUrl: `/blogs/${slug}`,
45+
canonicalUrl: `/blogs/${slug}`,
4546
});
4647
}
4748

app/[locale]/blogs/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export async function generateMetadata({
2323
description: t("description"),
2424
locale: locale as Locale,
2525
path: `/blogs`,
26+
canonicalUrl: `/blogs`,
2627
});
2728
}
2829

app/[locale]/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function generateMetadata({
3535
description: t("description"),
3636
locale: locale as Locale,
3737
path: `/`,
38-
// canonicalUrl: `/blogs/${slug}`,
38+
canonicalUrl: `/`,
3939
});
4040
}
4141

app/[locale]/privacy-policy/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export async function generateMetadata({
5252
description: t("description"),
5353
locale: locale as Locale,
5454
path: `/privacy-policy`,
55+
canonicalUrl: `/privacy-policy`,
5556
});
5657
}
5758

app/[locale]/terms-of-service/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export async function generateMetadata({
5252
description: t("description"),
5353
locale: locale as Locale,
5454
path: `/terms-of-service`,
55+
canonicalUrl: `/terms-of-service`,
5556
});
5657
}
5758

app/[locale]/unsubscribe/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { unsubscribeFromNewsletter } from "@/app/actions/newsletter";
1+
import { unsubscribeFromNewsletter } from "@/actions/newsletter";
22

33
type SearchParams = Promise<{ [key: string]: string | string[] | undefined }>;
44

lib/metadata.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ export async function constructMetadata({
5353
// build alternate language links
5454
const alternateLanguages = Object.keys(LOCALE_NAMES).reduce((acc, lang) => {
5555
const path = canonicalUrl
56-
? `/${lang === DEFAULT_LOCALE ? '' : lang}${canonicalUrl}`
57-
: `/${lang === DEFAULT_LOCALE ? '' : lang}`
58-
acc[lang] = `${siteConfig.url}/${path}`
56+
? `${lang === DEFAULT_LOCALE ? '' : `/${lang}`}${canonicalUrl}`
57+
: `${lang === DEFAULT_LOCALE ? '' : `/${lang}`}`
58+
acc[lang] = `${siteConfig.url}${path}`
59+
5960
return acc
6061
}, {} as Record<string, string>)
6162

@@ -67,7 +68,7 @@ export async function constructMetadata({
6768
creator: siteConfig.creator,
6869
metadataBase: new URL(siteConfig.url),
6970
alternates: {
70-
canonical: canonicalUrl ? `${siteConfig.url}/${canonicalUrl}` : undefined,
71+
canonical: canonicalUrl ? `${siteConfig.url}${locale === DEFAULT_LOCALE ? '' : `/${locale}`}${canonicalUrl}` : undefined,
7172
languages: alternateLanguages,
7273
},
7374
openGraph: {

0 commit comments

Comments
 (0)