summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/(main)/(home)/posts/page.tsx12
-rw-r--r--src/app/(main)/(home)/tags/[...slug]/page.tsx12
2 files changed, 14 insertions, 10 deletions
diff --git a/src/app/(main)/(home)/posts/page.tsx b/src/app/(main)/(home)/posts/page.tsx
index 376f5c1..45016a4 100644
--- a/src/app/(main)/(home)/posts/page.tsx
+++ b/src/app/(main)/(home)/posts/page.tsx
@@ -128,7 +128,7 @@ export async function generateMetadata(
): Promise<Metadata> {
const searchParams = await props.searchParams;
- const pageIndex = searchParams.page
+ const rawPage = searchParams.page
? Number.parseInt(
Array.isArray(searchParams.page)
? (searchParams.page[0] ?? '')
@@ -137,13 +137,15 @@ export async function generateMetadata(
)
: 1;
- const isFirstPage = pageIndex === 1 || !searchParams.page;
- const pageTitle = isFirstPage ? 'Posts' : `Posts - Page ${pageIndex}`;
- const canonicalUrl = isFirstPage ? '/posts' : `/posts?page=${pageIndex}`;
+ if (Number.isNaN(rawPage) || rawPage < 1) notFound();
+
+ const isFirstPage = rawPage === 1 || !searchParams.page;
+ const pageTitle = isFirstPage ? 'Posts' : `Posts - Page ${rawPage}`;
+ const canonicalUrl = isFirstPage ? '/posts' : `/posts?page=${rawPage}`;
return createMetadata({
title: pageTitle,
- description: `Posts${!isFirstPage ? ` - Page ${pageIndex}` : ''}`,
+ description: `Posts${!isFirstPage ? ` - Page ${rawPage}` : ''}`,
openGraph: {
url: canonicalUrl,
},
diff --git a/src/app/(main)/(home)/tags/[...slug]/page.tsx b/src/app/(main)/(home)/tags/[...slug]/page.tsx
index 30c6464..b6bdafa 100644
--- a/src/app/(main)/(home)/tags/[...slug]/page.tsx
+++ b/src/app/(main)/(home)/tags/[...slug]/page.tsx
@@ -165,7 +165,7 @@ export async function generateMetadata(
const searchParams = await props.searchParams;
const tag = params.slug[0];
- const pageIndex = searchParams.page
+ const rawPage = searchParams.page
? Number.parseInt(
Array.isArray(searchParams.page)
? (searchParams.page[0] ?? '')
@@ -174,18 +174,20 @@ export async function generateMetadata(
)
: 1;
- const isFirstPage = pageIndex === 1 || !searchParams.page;
+ if (Number.isNaN(rawPage) || rawPage < 1) notFound();
+
+ const isFirstPage = rawPage === 1 || !searchParams.page;
const pageTitle = isFirstPage
? `${tag} Posts`
- : `${tag} Posts - Page ${pageIndex}`;
+ : `${tag} Posts - Page ${rawPage}`;
const canonicalUrl = isFirstPage
? `/tags/${tag}`
- : `/tags/${tag}?page=${pageIndex}`;
+ : `/tags/${tag}?page=${rawPage}`;
return createMetadata({
title: pageTitle,
description: `Posts tagged with ${tag}${
- !isFirstPage ? ` - Page ${pageIndex}` : ''
+ !isFirstPage ? ` - Page ${rawPage}` : ''
}`,
openGraph: {
url: canonicalUrl,