From 8b85235f1d6130f5f53557b08a8e041a012a246d Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Tue, 27 May 2025 05:32:50 +0000 Subject: [PATCH] feat(SW-2408): Improved meta titles for Hotel subpages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Approved-by: Matilda Landström --- .../contentstack/metadata/utils/title.ts | 93 +++++++++++++++++-- 1 file changed, 87 insertions(+), 6 deletions(-) diff --git a/apps/scandic-web/server/routers/contentstack/metadata/utils/title.ts b/apps/scandic-web/server/routers/contentstack/metadata/utils/title.ts index d34f75de3..c033dc639 100644 --- a/apps/scandic-web/server/routers/contentstack/metadata/utils/title.ts +++ b/apps/scandic-web/server/routers/contentstack/metadata/utils/title.ts @@ -15,7 +15,7 @@ export async function getTitle(data: RawMetadataSchema) { (restaurant) => restaurant.nameInUrl === data.subpageUrl ) if (restaurantSubPage) { - return intl.formatMessage( + const restaurantTitleLong = intl.formatMessage( { defaultMessage: "Explore {restaurantName} at {hotelName} in {destination}", @@ -26,11 +26,44 @@ export async function getTitle(data: RawMetadataSchema) { destination: data.hotelData.address.city, } ) + const restaurantTitleShort = intl.formatMessage( + { + defaultMessage: "Explore {restaurantName} at {hotelName}", + }, + { + restaurantName: restaurantSubPage.name, + hotelName: data.hotelData.name, + } + ) + + if (restaurantTitleLong.length > 60) { + return restaurantTitleShort + } + return restaurantTitleLong } switch (data.subpageUrl) { + case "reviews": + const reviewsTitleLong = intl.formatMessage( + { + defaultMessage: + "Ratings and reviews for {hotelName} in {destination}", + }, + { + hotelName: data.hotelData.name, + destination: data.hotelData.address.city, + } + ) + const reviewsTitleShort = intl.formatMessage( + { defaultMessage: "Ratings and reviews for {hotelName}" }, + { hotelName: data.hotelData.name } + ) + if (reviewsTitleLong.length > 60) { + return reviewsTitleShort + } + return reviewsTitleLong case data.additionalHotelData?.hotelParking.nameInUrl: - return intl.formatMessage( + const parkingTitleLong = intl.formatMessage( { defaultMessage: "Parking information for {hotelName} in {destination}", @@ -40,8 +73,17 @@ export async function getTitle(data: RawMetadataSchema) { destination: data.hotelData.address.city, } ) + const parkingTitleShort = intl.formatMessage( + { defaultMessage: "Parking information for {hotelName}" }, + { hotelName: data.hotelData.name } + ) + + if (parkingTitleLong.length > 60) { + return parkingTitleShort + } + return parkingTitleLong case data.additionalHotelData?.healthAndFitness.nameInUrl: - return intl.formatMessage( + const wellnessTitleLong = intl.formatMessage( { defaultMessage: "Gym & Health Facilities at {hotelName} in {destination}", @@ -51,8 +93,21 @@ export async function getTitle(data: RawMetadataSchema) { destination: data.hotelData.address.city, } ) + const wellnessTitleShort = intl.formatMessage( + { + defaultMessage: "Gym & Health Facilities at {hotelName}", + }, + { + hotelName: data.hotelData.name, + } + ) + + if (wellnessTitleLong.length > 60) { + return wellnessTitleShort + } + return wellnessTitleLong case data.additionalHotelData?.hotelSpecialNeeds.nameInUrl: - return intl.formatMessage( + const accessibilityTitleLong = intl.formatMessage( { defaultMessage: "Accessibility information for {hotelName} in {destination}", @@ -62,17 +117,43 @@ export async function getTitle(data: RawMetadataSchema) { destination: data.hotelData.address.city, } ) + const accessibilityTitleShort = intl.formatMessage( + { + defaultMessage: "Accessibility information for {hotelName}", + }, + { + hotelName: data.hotelData.name, + } + ) + + if (accessibilityTitleLong.length > 60) { + return accessibilityTitleShort + } + return accessibilityTitleLong case data.additionalHotelData?.meetingRooms.nameInUrl: - return intl.formatMessage( + const meetingsTitleLong = intl.formatMessage( { defaultMessage: - "Meetings, Conferences & Events at {hotelName} in {destination}", + "Meetings & Conferences at {hotelName} in {destination}", }, { hotelName: data.hotelData.name, destination: data.hotelData.address.city, } ) + const meetingsTitleShort = intl.formatMessage( + { + defaultMessage: "Meetings & Conferences at {hotelName}", + }, + { + hotelName: data.hotelData.name, + } + ) + + if (meetingsTitleLong.length > 60) { + return meetingsTitleShort + } + return meetingsTitleLong default: break }