* feat(SW-2152): Added improved meta descriptions for hotel pages * feat(SW-2152): Added improved meta descriptions for destination pages * feat(SW-2152): Refactoring metadata description functionality * feat(SW-2152): Improved truncate function and added cities check to country page description Approved-by: Michael Zetterberg Approved-by: Matilda Landström
134 lines
3.8 KiB
TypeScript
134 lines
3.8 KiB
TypeScript
import { getIntl } from "@/i18n"
|
|
|
|
import type { RawMetadataSchema } from "@/types/trpc/routers/contentstack/metadata"
|
|
|
|
export async function getTitle(data: RawMetadataSchema) {
|
|
const intl = await getIntl()
|
|
const metadata = data.web?.seo_metadata
|
|
if (metadata?.title) {
|
|
return metadata.title
|
|
}
|
|
|
|
if (data.system.content_type_uid === "hotel_page" && data.hotelData) {
|
|
if (data.subpageUrl) {
|
|
const restaurantSubPage = data.hotelRestaurants?.find(
|
|
(restaurant) => restaurant.nameInUrl === data.subpageUrl
|
|
)
|
|
if (restaurantSubPage) {
|
|
return intl.formatMessage(
|
|
{
|
|
defaultMessage:
|
|
"Explore {restaurantName} at {hotelName} in {destination}",
|
|
},
|
|
{
|
|
restaurantName: restaurantSubPage.name,
|
|
hotelName: data.hotelData.name,
|
|
destination: data.hotelData.address.city,
|
|
}
|
|
)
|
|
}
|
|
|
|
switch (data.subpageUrl) {
|
|
case data.additionalHotelData?.hotelParking.nameInUrl:
|
|
return intl.formatMessage(
|
|
{
|
|
defaultMessage:
|
|
"Parking information for {hotelName} in {destination}",
|
|
},
|
|
{
|
|
hotelName: data.hotelData.name,
|
|
destination: data.hotelData.address.city,
|
|
}
|
|
)
|
|
case data.additionalHotelData?.healthAndFitness.nameInUrl:
|
|
return intl.formatMessage(
|
|
{
|
|
defaultMessage:
|
|
"Gym & Health Facilities at {hotelName} in {destination}",
|
|
},
|
|
{
|
|
hotelName: data.hotelData.name,
|
|
destination: data.hotelData.address.city,
|
|
}
|
|
)
|
|
case data.additionalHotelData?.hotelSpecialNeeds.nameInUrl:
|
|
return intl.formatMessage(
|
|
{
|
|
defaultMessage:
|
|
"Accessibility information for {hotelName} in {destination}",
|
|
},
|
|
{
|
|
hotelName: data.hotelData.name,
|
|
destination: data.hotelData.address.city,
|
|
}
|
|
)
|
|
case data.additionalHotelData?.meetingRooms.nameInUrl:
|
|
return intl.formatMessage(
|
|
{
|
|
defaultMessage:
|
|
"Meetings, Conferences & Events at {hotelName} in {destination}",
|
|
},
|
|
{
|
|
hotelName: data.hotelData.name,
|
|
destination: data.hotelData.address.city,
|
|
}
|
|
)
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
return intl.formatMessage(
|
|
{
|
|
defaultMessage: "Stay at {hotelName} | Hotel in {destination}",
|
|
},
|
|
{
|
|
hotelName: data.hotelData.name,
|
|
destination: data.hotelData.address.city,
|
|
}
|
|
)
|
|
}
|
|
if (
|
|
data.system.content_type_uid === "destination_city_page" ||
|
|
data.system.content_type_uid === "destination_country_page"
|
|
) {
|
|
if (data.destinationData) {
|
|
const { location, filter, filterType } = data.destinationData
|
|
if (location) {
|
|
if (filter) {
|
|
if (filterType === "facility") {
|
|
return intl.formatMessage(
|
|
{
|
|
defaultMessage: "Hotels with {filter} in {location}",
|
|
},
|
|
{ location, filter }
|
|
)
|
|
} else if (filterType === "surroundings") {
|
|
return intl.formatMessage(
|
|
{
|
|
defaultMessage: "Hotels near {filter} in {location}",
|
|
},
|
|
{ location, filter }
|
|
)
|
|
}
|
|
}
|
|
return intl.formatMessage(
|
|
{
|
|
defaultMessage: "Hotels in {location}",
|
|
},
|
|
{ location }
|
|
)
|
|
}
|
|
}
|
|
}
|
|
if (data.web?.breadcrumbs?.title) {
|
|
return data.web.breadcrumbs.title
|
|
}
|
|
if (data.heading) {
|
|
return data.heading
|
|
}
|
|
if (data.header?.heading) {
|
|
return data.header.heading
|
|
}
|
|
return ""
|
|
}
|