From 406e6830915c593d8dacc056f70effa9581cbc5d Mon Sep 17 00:00:00 2001 From: Giancarlo Buomprisco Date: Mon, 9 Jun 2025 20:55:43 +0700 Subject: [PATCH] Add prev/next metadata on blog pages (#273) * feat(web): add prev/next seo tags to blog --- apps/web/app/(marketing)/blog/page.tsx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/web/app/(marketing)/blog/page.tsx b/apps/web/app/(marketing)/blog/page.tsx index e7febf287..b531348de 100644 --- a/apps/web/app/(marketing)/blog/page.tsx +++ b/apps/web/app/(marketing)/blog/page.tsx @@ -1,5 +1,7 @@ import { cache } from 'react'; +import type { Metadata } from 'next'; + import { createCmsClient } from '@kit/cms'; import { getLogger } from '@kit/shared/logger'; import { If } from '@kit/ui/if'; @@ -17,12 +19,27 @@ interface BlogPageProps { searchParams: Promise<{ page?: string }>; } -export const generateMetadata = async () => { - const { t } = await createI18nServerInstance(); +const BLOG_POSTS_PER_PAGE = 10; + +export const generateMetadata = async ( + props: BlogPageProps, +): Promise => { + const { t, resolvedLanguage } = await createI18nServerInstance(); + const searchParams = await props.searchParams; + const limit = BLOG_POSTS_PER_PAGE; + + const page = searchParams.page ? parseInt(searchParams.page) : 0; + const offset = page * limit; + + const { total } = await getContentItems(resolvedLanguage, limit, offset); return { title: t('marketing:blog'), description: t('marketing:blogSubtitle'), + pagination: { + previous: page > 0 ? `/blog?page=${page - 1}` : undefined, + next: offset + limit < total ? `/blog?page=${page + 1}` : undefined, + }, }; }; @@ -53,8 +70,8 @@ async function BlogPage(props: BlogPageProps) { const { t, resolvedLanguage: language } = await createI18nServerInstance(); const searchParams = await props.searchParams; + const limit = BLOG_POSTS_PER_PAGE; const page = searchParams.page ? parseInt(searchParams.page) : 0; - const limit = 10; const offset = page * limit; const { total, items: posts } = await getContentItems(