import { env } from "@/env/server" import { serverClient } from "@/lib/trpc/server" import type { ContentTypeParams, LangParams, PageArgs, UIDParams, } from "@/types/params" import type { Lang } from "@/constants/languages" export async function generateMetadata({ searchParams, params, }: PageArgs< LangParams & ContentTypeParams & UIDParams, { subpage?: string; filterFromUrl?: string } >) { const { subpage, filterFromUrl, ...otherSearchParams } = searchParams // If there are other (real) search params, we don't want to index the page as this will // cause duplicate content issues. const noIndexOnSearchParams = !!Object.keys(otherSearchParams).length const metadata = await serverClient().contentstack.metadata.get({ subpage, filterFromUrl, noIndex: noIndexOnSearchParams, }) if (!metadata) { return { robots: { index: env.isLangLive(params.lang), follow: env.isLangLive(params.lang), }, } } if (typeof metadata?.robots === "string") { return metadata } return { ...metadata, robots: { ...(metadata.robots ?? {}), index: isIndexable(metadata.robots?.index, params.lang), follow: isIndexable(metadata.robots?.follow, params.lang), }, } } function isIndexable( pageIndexableFromSettings: boolean | null | undefined, lang: Lang ) { // If we are live we want to index the page, but if the page has been marked as noindex in contentstack we don't return (pageIndexableFromSettings ?? true) && env.isLangLive(lang) }