feat(SW-2957): Added suffix to meta title on specific page types
Approved-by: Matilda Landström
This commit is contained in:
@@ -2,11 +2,26 @@ import { getIntl } from "@/i18n"
|
|||||||
|
|
||||||
import type { RawMetadataSchema } from "@scandic-hotels/trpc/routers/contentstack/metadata/output"
|
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) {
|
export async function getTitle(data: RawMetadataSchema) {
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
|
const suffix = getTitleSuffix(data.system.content_type_uid)
|
||||||
const metadata = data.web?.seo_metadata
|
const metadata = data.web?.seo_metadata
|
||||||
|
|
||||||
if (metadata?.title) {
|
if (metadata?.title) {
|
||||||
return metadata.title
|
return `${metadata.title}${suffix}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.system.content_type_uid === "hotel_page" && data.hotelData) {
|
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}",
|
defaultMessage: "Hotels in {location}",
|
||||||
},
|
},
|
||||||
{ location }
|
{ location }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return `${destinationTitle}${suffix}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.web?.breadcrumbs?.title) {
|
if (data.web?.breadcrumbs?.title) {
|
||||||
return data.web.breadcrumbs.title
|
return `${data.web.breadcrumbs.title}${suffix}`
|
||||||
}
|
}
|
||||||
if (data.heading) {
|
if (data.heading) {
|
||||||
return data.heading
|
return `${data.heading}${suffix}`
|
||||||
}
|
}
|
||||||
if (data.header?.heading) {
|
if (data.header?.heading) {
|
||||||
return data.header.heading
|
return `${data.header.heading}${suffix}`
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user