SW-3490 set metadata for routes * feat(SW-3490): Set metadata title for hotelreservation paths Approved-by: Anton Gunnarsson
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import { PageContentTypeEnum } from "@scandic-hotels/trpc/enums/contentType"
|
|
|
|
import {
|
|
getDestinationFilterSeoMetaTitle,
|
|
getDestinationPageTitle,
|
|
} from "./destinationPage"
|
|
import { getTitlePrefix } from "./getTitlePrefix"
|
|
import { getHotelPageTitle } from "./hotelPage"
|
|
|
|
import type { RawMetadataSchema } from "@scandic-hotels/trpc/routers/contentstack/metadata/output"
|
|
|
|
function getTitleSuffix(contentType: string) {
|
|
switch (contentType) {
|
|
case PageContentTypeEnum.contentPage:
|
|
case PageContentTypeEnum.collectionPage:
|
|
case PageContentTypeEnum.campaignPage:
|
|
case PageContentTypeEnum.campaignOverviewPage:
|
|
case PageContentTypeEnum.destinationOverviewPage:
|
|
case PageContentTypeEnum.destinationCityPage:
|
|
case PageContentTypeEnum.destinationCountryPage:
|
|
return "Scandic Hotels"
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|
|
export async function getTitle(data: RawMetadataSchema) {
|
|
const prefix = getTitlePrefix()
|
|
const suffix = getTitleSuffix(data.system.content_type_uid)
|
|
const metadata = data.web?.seo_metadata
|
|
const isDestinationPage = [
|
|
PageContentTypeEnum.destinationCityPage,
|
|
PageContentTypeEnum.destinationCountryPage,
|
|
].includes(data.system.content_type_uid as PageContentTypeEnum)
|
|
|
|
if (isDestinationPage) {
|
|
const destinationFilterSeoMetaTitle = getDestinationFilterSeoMetaTitle(data)
|
|
if (destinationFilterSeoMetaTitle) {
|
|
return destinationFilterSeoMetaTitle
|
|
}
|
|
}
|
|
|
|
if (metadata?.title) {
|
|
return combineSegments([prefix, metadata.title, suffix])
|
|
}
|
|
|
|
let title: string | null | undefined = null
|
|
|
|
switch (data.system.content_type_uid) {
|
|
case PageContentTypeEnum.hotelPage:
|
|
title = await getHotelPageTitle(data)
|
|
break
|
|
case PageContentTypeEnum.destinationCityPage:
|
|
title = await getDestinationPageTitle(data, "city")
|
|
break
|
|
case PageContentTypeEnum.destinationCountryPage:
|
|
title = await getDestinationPageTitle(data, "country")
|
|
break
|
|
default:
|
|
break
|
|
}
|
|
|
|
// Fallback titles from contentstack content
|
|
title ||= data.web?.breadcrumbs?.title || data.heading || data.header?.heading
|
|
|
|
return combineSegments([prefix, title, suffix])
|
|
}
|
|
|
|
function combineSegments(
|
|
segments: (string | null | undefined)[],
|
|
delimiter = " | "
|
|
) {
|
|
return segments.filter(Boolean).join(delimiter).trim()
|
|
}
|