feat(BOOK-57): Adjusted metadata for destination pages with active seo filter
Approved-by: Chuma Mcphoy (We Ahead)
This commit is contained in:
79
apps/scandic-web/utils/metadata/title/index.ts
Normal file
79
apps/scandic-web/utils/metadata/title/index.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { PageContentTypeEnum } from "@scandic-hotels/trpc/enums/contentType"
|
||||
|
||||
import {
|
||||
getDestinationFilterSeoMetaTitle,
|
||||
getDestinationPageTitle,
|
||||
} from "./destinationPage"
|
||||
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 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,
|
||||
suffix
|
||||
)
|
||||
if (destinationFilterSeoMetaTitle) {
|
||||
return destinationFilterSeoMetaTitle
|
||||
}
|
||||
}
|
||||
|
||||
if (metadata?.title) {
|
||||
return `${metadata.title}${suffix}`
|
||||
}
|
||||
|
||||
let title: string | null = null
|
||||
|
||||
switch (data.system.content_type_uid) {
|
||||
case PageContentTypeEnum.hotelPage:
|
||||
title = await getHotelPageTitle(data)
|
||||
break
|
||||
case PageContentTypeEnum.destinationCityPage:
|
||||
title = await getDestinationPageTitle(data, "city", suffix)
|
||||
break
|
||||
case PageContentTypeEnum.destinationCountryPage:
|
||||
title = await getDestinationPageTitle(data, "country", suffix)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if (title) {
|
||||
return title
|
||||
}
|
||||
|
||||
// Fallback titles from contentstack content
|
||||
if (data.web?.breadcrumbs?.title) {
|
||||
return `${data.web.breadcrumbs.title}${suffix}`
|
||||
}
|
||||
if (data.heading) {
|
||||
return `${data.heading}${suffix}`
|
||||
}
|
||||
if (data.header?.heading) {
|
||||
return `${data.header.heading}${suffix}`
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user