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 { serverClient } from "@/lib/trpc/server"
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -6,9 +7,11 @@ import type {
|
|||||||
PageArgs,
|
PageArgs,
|
||||||
UIDParams,
|
UIDParams,
|
||||||
} from "@/types/params"
|
} from "@/types/params"
|
||||||
|
import type { Lang } from "@/constants/languages"
|
||||||
|
|
||||||
export async function generateMetadata({
|
export async function generateMetadata({
|
||||||
searchParams,
|
searchParams,
|
||||||
|
params,
|
||||||
}: PageArgs<
|
}: PageArgs<
|
||||||
LangParams & ContentTypeParams & UIDParams,
|
LangParams & ContentTypeParams & UIDParams,
|
||||||
{ subpage?: string; filterFromUrl?: string }
|
{ subpage?: string; filterFromUrl?: string }
|
||||||
@@ -22,5 +25,34 @@ export async function generateMetadata({
|
|||||||
filterFromUrl,
|
filterFromUrl,
|
||||||
noIndex: noIndexOnSearchParams,
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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