feat(BOOK-57): Adjusted metadata for destination pages with active seo filter
Approved-by: Chuma Mcphoy (We Ahead)
This commit is contained in:
148
apps/scandic-web/utils/metadata/title/hotelPage.ts
Normal file
148
apps/scandic-web/utils/metadata/title/hotelPage.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
import type { RawMetadataSchema } from "@scandic-hotels/trpc/routers/contentstack/metadata/output"
|
||||
|
||||
async function getSubpageTitle(
|
||||
subpageUrl: string,
|
||||
additionalHotelData: RawMetadataSchema["additionalHotelData"],
|
||||
hotelRestaurants: RawMetadataSchema["hotelRestaurants"],
|
||||
hotelName: string,
|
||||
destination: string
|
||||
) {
|
||||
const intl = await getIntl()
|
||||
const restaurantSubPage = hotelRestaurants?.find(
|
||||
(restaurant) => restaurant.nameInUrl === subpageUrl
|
||||
)
|
||||
if (restaurantSubPage) {
|
||||
const restaurantTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Explore {restaurantName} at {hotelName} in {destination}",
|
||||
},
|
||||
{
|
||||
restaurantName: restaurantSubPage.name,
|
||||
hotelName,
|
||||
destination,
|
||||
}
|
||||
)
|
||||
const restaurantTitleShort = intl.formatMessage(
|
||||
{
|
||||
defaultMessage: "Explore {restaurantName} at {hotelName}",
|
||||
},
|
||||
{
|
||||
restaurantName: restaurantSubPage.name,
|
||||
hotelName,
|
||||
}
|
||||
)
|
||||
|
||||
if (restaurantTitleLong.length > 60) {
|
||||
return restaurantTitleShort
|
||||
}
|
||||
return restaurantTitleLong
|
||||
}
|
||||
|
||||
if (!additionalHotelData) {
|
||||
return null
|
||||
}
|
||||
|
||||
switch (subpageUrl) {
|
||||
case additionalHotelData.hotelParking.nameInUrl:
|
||||
const parkingTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Parking information for {hotelName} in {destination}",
|
||||
},
|
||||
{ hotelName, destination }
|
||||
)
|
||||
const parkingTitleShort = intl.formatMessage(
|
||||
{ defaultMessage: "Parking information for {hotelName}" },
|
||||
{ hotelName }
|
||||
)
|
||||
|
||||
if (parkingTitleLong.length > 60) {
|
||||
return parkingTitleShort
|
||||
}
|
||||
return parkingTitleLong
|
||||
case additionalHotelData.healthAndFitness.nameInUrl:
|
||||
const wellnessTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Gym & health facilities at {hotelName} in {destination}",
|
||||
},
|
||||
{ hotelName, destination }
|
||||
)
|
||||
const wellnessTitleShort = intl.formatMessage(
|
||||
{ defaultMessage: "Gym & health facilities at {hotelName}" },
|
||||
{ hotelName }
|
||||
)
|
||||
|
||||
if (wellnessTitleLong.length > 60) {
|
||||
return wellnessTitleShort
|
||||
}
|
||||
return wellnessTitleLong
|
||||
case additionalHotelData.hotelSpecialNeeds.nameInUrl:
|
||||
const accessibilityTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Accessibility information for {hotelName} in {destination}",
|
||||
},
|
||||
{ hotelName, destination }
|
||||
)
|
||||
const accessibilityTitleShort = intl.formatMessage(
|
||||
{ defaultMessage: "Accessibility information for {hotelName}" },
|
||||
{ hotelName }
|
||||
)
|
||||
|
||||
if (accessibilityTitleLong.length > 60) {
|
||||
return accessibilityTitleShort
|
||||
}
|
||||
return accessibilityTitleLong
|
||||
case additionalHotelData.meetingRooms.nameInUrl:
|
||||
const meetingsTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Meetings & conferences at {hotelName} in {destination}",
|
||||
},
|
||||
{ hotelName, destination }
|
||||
)
|
||||
const meetingsTitleShort = intl.formatMessage(
|
||||
{ defaultMessage: "Meetings & conferences at {hotelName}" },
|
||||
{ hotelName }
|
||||
)
|
||||
|
||||
if (meetingsTitleLong.length > 60) {
|
||||
return meetingsTitleShort
|
||||
}
|
||||
return meetingsTitleLong
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function getHotelPageTitle(data: RawMetadataSchema) {
|
||||
const intl = await getIntl()
|
||||
const { subpageUrl, hotelData, additionalHotelData, hotelRestaurants } = data
|
||||
if (!hotelData) {
|
||||
return null
|
||||
}
|
||||
|
||||
const hotelName = hotelData.name
|
||||
const destination = hotelData.translatedCityName
|
||||
|
||||
if (subpageUrl) {
|
||||
const subpageTitle = await getSubpageTitle(
|
||||
subpageUrl,
|
||||
additionalHotelData,
|
||||
hotelRestaurants,
|
||||
hotelName,
|
||||
destination
|
||||
)
|
||||
|
||||
return subpageTitle
|
||||
}
|
||||
|
||||
return intl.formatMessage(
|
||||
{ defaultMessage: "Stay at {hotelName} | Hotel in {destination}" },
|
||||
{ hotelName, destination }
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user