Merged in fix/seo-whitelist-scandic-friends (pull request #2071)
fix: SEO whitelist /scandic-friends * fix: SEO whitelist /scandic-friends * fix: SEO whitelist /scandic-friends Approved-by: Linus Flood
This commit is contained in:
committed by
Linus Flood
parent
13261d425c
commit
aceb88cb1a
@@ -242,6 +242,6 @@ export const metadataQueryRouter = router({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadata
|
return { metadata, alternates }
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
import { serverClient } from "@/lib/trpc/server"
|
import { serverClient } from "@/lib/trpc/server"
|
||||||
|
|
||||||
|
import type { AlternateURLs } from "next/dist/lib/metadata/types/alternative-urls-types"
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ContentTypeParams,
|
ContentTypeParams,
|
||||||
LangParams,
|
LangParams,
|
||||||
@@ -20,11 +22,12 @@ export async function generateMetadata({
|
|||||||
// If there are other (real) search params, we don't want to index the page as this will
|
// If there are other (real) search params, we don't want to index the page as this will
|
||||||
// cause duplicate content issues.
|
// cause duplicate content issues.
|
||||||
const noIndexOnSearchParams = !!Object.keys(otherSearchParams).length
|
const noIndexOnSearchParams = !!Object.keys(otherSearchParams).length
|
||||||
const metadata = await serverClient().contentstack.metadata.get({
|
const { metadata, alternates } =
|
||||||
subpage,
|
await serverClient().contentstack.metadata.get({
|
||||||
filterFromUrl,
|
subpage,
|
||||||
noIndex: noIndexOnSearchParams,
|
filterFromUrl,
|
||||||
})
|
noIndex: noIndexOnSearchParams,
|
||||||
|
})
|
||||||
|
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
return {
|
return {
|
||||||
@@ -43,16 +46,48 @@ export async function generateMetadata({
|
|||||||
...metadata,
|
...metadata,
|
||||||
robots: {
|
robots: {
|
||||||
...(metadata.robots ?? {}),
|
...(metadata.robots ?? {}),
|
||||||
index: isIndexable(metadata.robots?.index, params.lang),
|
index: isIndexable(metadata.robots?.index, params.lang, alternates),
|
||||||
follow: isIndexable(metadata.robots?.follow, params.lang),
|
follow: isIndexable(metadata.robots?.follow, params.lang, alternates),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isIndexable(
|
function isIndexable(
|
||||||
pageIndexableFromSettings: boolean | null | undefined,
|
pageIndexableFromSettings: boolean | null | undefined,
|
||||||
lang: Lang
|
lang: Lang,
|
||||||
|
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
|
// 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)
|
return (pageIndexableFromSettings ?? true) && env.isLangLive(lang)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user