From d2b1384c2b963c17eb27dc8db3fa0d58bdb7f9cb Mon Sep 17 00:00:00 2001 From: RizqiSyahrendra Date: Tue, 11 Mar 2025 17:30:17 +0700 Subject: [PATCH] feat: tag pages integration --- src/app/(main)/page.tsx | 2 +- src/app/(main)/tag/[...path]/page.tsx | 157 ++++++++++++++++++++++++++ src/components/Blogs/Blogs.tsx | 7 ++ src/services/payload/blog.ts | 24 +++- 4 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 src/app/(main)/tag/[...path]/page.tsx diff --git a/src/app/(main)/page.tsx b/src/app/(main)/page.tsx index 1d0d6a8..b90bbb0 100644 --- a/src/app/(main)/page.tsx +++ b/src/app/(main)/page.tsx @@ -111,7 +111,7 @@ export default async function Home() { { "@type": "Organization", "@id": `${fullUrl}#organization`, - name: "Cochise Oncology", + name: siteName, url: fullUrl, logo: { "@type": "ImageObject", diff --git a/src/app/(main)/tag/[...path]/page.tsx b/src/app/(main)/tag/[...path]/page.tsx new file mode 100644 index 0000000..89b0db3 --- /dev/null +++ b/src/app/(main)/tag/[...path]/page.tsx @@ -0,0 +1,157 @@ +import { BeforeFooterBlock } from "@/components/Blocks/BeforeFooter"; +import { BlogCardItemSkeleton } from "@/components/Blogs/BlogCardItem"; +import Blogs from "@/components/Blogs/Blogs"; +import HeroOther from "@/components/HeroOther"; +import { fetchBlogTagBySlug } from "@/services/payload/blog"; +import { getDefaultMetadata } from "@/utils/metadata"; +import { sanitizePageNumber } from "@/utils/sanitize"; +import { Metadata } from "next"; +import { headers } from "next/headers"; +import { notFound } from "next/navigation"; +import { Suspense } from "react"; + +export async function generateMetadata({ params }: { params: Promise<{ path: string[0] }> }): Promise { + const path = (await params)?.path; + const paramsTag = path?.[0] ?? ""; + const metadata = await getDefaultMetadata(); + + const tag = await fetchBlogTagBySlug(paramsTag); + if (!!tag?.data) { + metadata.title = `${tag.data.name} Archives - ${metadata.openGraph?.siteName}`; + } + + return metadata; +} + +export default async function TagPage({ + params, + searchParams, +}: { + params?: Promise<{ path: string[] }>; + searchParams?: Promise<{ page?: string; s?: string }>; +}) { + const path = (await params)?.path; + const paramsTag = path?.[0] ?? ""; + const paramsPage = path?.[2] ?? ""; + const paramsSearch = (await searchParams)?.s; + const page = sanitizePageNumber(paramsPage); + const headersList = await headers(); + const mainUrl = headersList.get("x-main-url"); + const fullUrl = headersList.get("x-full-url"); + const siteName = headersList.get("x-site-name"); + + const tag = await fetchBlogTagBySlug(paramsTag); + if (!tag) { + notFound(); + } + + const jsonLd = { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "CollectionPage", + "@id": fullUrl, + url: fullUrl, + name: `${tag.data.name} - ${siteName}`, + isPartOf: { + "@id": `${mainUrl}/#website`, + }, + primaryImageOfPage: { + "@id": `${fullUrl}#primaryimage`, + }, + image: { + "@id": `${fullUrl}#primaryimage`, + }, + inLanguage: "en-US", + }, + { + "@type": "WebSite", + "@id": `${mainUrl}/#website`, + url: `${mainUrl}/`, + name: siteName, + description: "", + publisher: { + "@id": `${mainUrl}/#organization`, + }, + potentialAction: [ + { + "@type": "SearchAction", + target: { + "@type": "EntryPoint", + urlTemplate: `${mainUrl}/?s={search_term_string}`, + }, + "query-input": { + "@type": "PropertyValueSpecification", + valueRequired: true, + valueName: "search_term_string", + }, + }, + ], + inLanguage: "en-US", + }, + { + "@type": "Organization", + "@id": `${mainUrl}/#organization`, + name: siteName, + url: `${mainUrl}/`, + logo: { + "@type": "ImageObject", + inLanguage: "en-US", + "@id": `${mainUrl}/#/schema/logo/image/`, + url: `${mainUrl}/assets/images/logo-dark.webp`, + contentUrl: `${mainUrl}/assets/images/logo-dark.webp`, + caption: siteName, + }, + image: { + "@id": `${mainUrl}/#/schema/logo/image/`, + }, + }, + ], + }; + + return ( + <> +