Merged in fix/remove-scandic-friends-robots-override (pull request #3322)
fix: remove /scandic-friends indexable override * fix: remove /scandic-friends indexable override Approved-by: Bianca Widstam Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -9,7 +9,6 @@ import { getImage } from "./image"
|
||||
import { getTitle } from "./title"
|
||||
|
||||
import type { Metadata } from "next"
|
||||
import type { AlternateURLs } from "next/dist/lib/metadata/types/alternative-urls-types"
|
||||
|
||||
export async function generateMetadata({
|
||||
searchParams,
|
||||
@@ -48,51 +47,12 @@ export async function generateMetadata({
|
||||
...metadata,
|
||||
robots: {
|
||||
...metadata.robots,
|
||||
index: isIndexable(metadata.robots?.index, alternates),
|
||||
follow: isIndexable(metadata.robots?.follow, alternates),
|
||||
index: metadata.robots?.index ?? true,
|
||||
follow: metadata.robots?.follow ?? true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function isIndexable(
|
||||
pageIndexableFromSettings: boolean | null | undefined,
|
||||
alternates: AlternateURLs | null
|
||||
) {
|
||||
// This is a special case for whitelisting the scandic friends pages, this can be removed when all pages are live
|
||||
const url = getUrl(alternates)
|
||||
const firstNonLangSegment = (url ?? "").substring(3)
|
||||
if (firstNonLangSegment.startsWith("/scandic-friends")) {
|
||||
return true
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
function getUrl(alternates: AlternateURLs | null): string | null {
|
||||
try {
|
||||
if (!alternates?.canonical) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (typeof alternates.canonical === "string") {
|
||||
return alternates.canonical
|
||||
}
|
||||
|
||||
if ("href" in alternates.canonical) {
|
||||
return alternates.canonical.href
|
||||
}
|
||||
|
||||
if (typeof alternates.canonical.url === "string") {
|
||||
return alternates.canonical.url
|
||||
}
|
||||
|
||||
return alternates.canonical.url.href
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function isNoIndexFromMetadata(data: RawMetadataSchema) {
|
||||
const isDestinationPage = [
|
||||
PageContentTypeEnum.destinationCityPage,
|
||||
|
||||
Reference in New Issue
Block a user