Merged in fix/noindex-contentpages (pull request #2066)
fix: add noindex+nofollow to contentpages * fix: add noindex+nofollow to contentpages * fix: move no-index/no-follow to the shared generateMetadata function instead * remove comment Approved-by: Erik Tiekstra
This commit is contained in:
committed by
Linus Flood
parent
40570c356a
commit
45d474385c
@@ -1,3 +1,4 @@
|
||||
import { env } from "@/env/server"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import type {
|
||||
@@ -6,9 +7,11 @@ import type {
|
||||
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 }
|
||||
@@ -22,5 +25,34 @@ export async function generateMetadata({
|
||||
filterFromUrl,
|
||||
noIndex: noIndexOnSearchParams,
|
||||
})
|
||||
return metadata
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user