feat(SW-2957): Added suffix to meta title on specific page types

Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-06-30 06:08:17 +00:00
parent 2b5573059c
commit 36d010a0a4

View File

@@ -2,11 +2,26 @@ import { getIntl } from "@/i18n"
import type { RawMetadataSchema } from "@scandic-hotels/trpc/routers/contentstack/metadata/output"
function getTitleSuffix(contentType: string) {
switch (contentType) {
case "content_page":
case "collection_page":
case "destination_overview_page":
case "destination_city_page":
case "destination_country_page":
return " | Scandic Hotels"
default:
return ""
}
}
export async function getTitle(data: RawMetadataSchema) {
const intl = await getIntl()
const suffix = getTitleSuffix(data.system.content_type_uid)
const metadata = data.web?.seo_metadata
if (metadata?.title) {
return metadata.title
return `${metadata.title}${suffix}`
}
if (data.system.content_type_uid === "hotel_page" && data.hotelData) {
@@ -173,23 +188,25 @@ export async function getTitle(data: RawMetadataSchema) {
)
}
}
return intl.formatMessage(
const destinationTitle = intl.formatMessage(
{
defaultMessage: "Hotels in {location}",
},
{ location }
)
return `${destinationTitle}${suffix}`
}
}
}
if (data.web?.breadcrumbs?.title) {
return data.web.breadcrumbs.title
return `${data.web.breadcrumbs.title}${suffix}`
}
if (data.heading) {
return data.heading
return `${data.heading}${suffix}`
}
if (data.header?.heading) {
return data.header.heading
return `${data.header.heading}${suffix}`
}
return ""
}