Files
web/apps/scandic-web/utils/metadata/description/hotelPage.ts
Anton Gunnarsson 002d093af4 Merged in feat/sw-2863-move-contentstack-router-to-trpc-package (pull request #2389)
feat(SW-2863): Move contentstack router to trpc package

* Add exports to packages and lint rule to prevent relative imports

* Add env to trpc package

* Add eslint to trpc package

* Apply lint rules

* Use direct imports from trpc package

* Add lint-staged config to trpc

* Move lang enum to common

* Restructure trpc package folder structure

* WIP first step

* update internal imports in trpc

* Fix most errors in scandic-web

Just 100 left...

* Move Props type out of trpc

* Fix CategorizedFilters types

* Move more schemas in hotel router

* Fix deps

* fix getNonContentstackUrls

* Fix import error

* Fix entry error handling

* Fix generateMetadata metrics

* Fix alertType enum

* Fix duplicated types

* lint:fix

* Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package

* Fix broken imports

* Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package


Approved-by: Linus Flood
2025-06-26 07:53:01 +00:00

105 lines
2.9 KiB
TypeScript

import { getIntl } from "@/i18n"
import { truncateTextAfterLastPeriod } from "../truncate"
import type { RawMetadataSchema } from "@scandic-hotels/trpc/routers/contentstack/metadata/output"
function getSubpageDescription(
subpageUrl: string,
additionalHotelData: RawMetadataSchema["additionalHotelData"],
hotelRestaurants: RawMetadataSchema["hotelRestaurants"]
) {
const restaurantSubPage = hotelRestaurants?.find(
(restaurant) => restaurant.nameInUrl === subpageUrl
)
if (restaurantSubPage?.elevatorPitch) {
return restaurantSubPage.elevatorPitch
}
if (!additionalHotelData) {
return null
}
switch (subpageUrl) {
case additionalHotelData.hotelParking.nameInUrl:
return additionalHotelData.hotelParking.elevatorPitch
case additionalHotelData.healthAndFitness.nameInUrl:
return additionalHotelData.healthAndFitness.elevatorPitch
case additionalHotelData.hotelSpecialNeeds.nameInUrl:
return additionalHotelData.hotelSpecialNeeds.elevatorPitch
case additionalHotelData.meetingRooms.nameInUrl:
return additionalHotelData.meetingRooms.elevatorPitch
default:
return null
}
}
export async function getHotelPageDescription(data: RawMetadataSchema) {
const intl = await getIntl()
const { subpageUrl, hotelData, additionalHotelData, hotelRestaurants } = data
if (!hotelData) {
return null
}
if (subpageUrl) {
const subpageDescription = getSubpageDescription(
subpageUrl,
additionalHotelData,
hotelRestaurants
)
if (subpageDescription) {
return truncateTextAfterLastPeriod(subpageDescription)
}
}
const hotelName = hotelData.name
const location = hotelData.address.city
const amenities = hotelData.detailedFacilities
if (amenities.length < 4) {
return intl.formatMessage(
{ defaultMessage: "{hotelName} in {location}. Book your stay now!" },
{ hotelName, location }
)
}
const hotelDescription = intl.formatMessage(
{
defaultMessage:
"{hotelName} in {location} offers {amenity1} and {amenity2}. Guests can also enjoy {amenity3} and {amenity4}. Book your stay at {hotelName} today!",
},
{
hotelName,
location,
amenity1: amenities[0].name,
amenity2: amenities[1].name,
amenity3: amenities[2].name,
amenity4: amenities[3].name,
}
)
const shortHotelDescription = intl.formatMessage(
{
defaultMessage:
"{hotelName} in {location} offers {amenity1} and {amenity2}. Guests can also enjoy {amenity3} and {amenity4}.",
},
{
hotelName,
location,
amenity1: amenities[0].name,
amenity2: amenities[1].name,
amenity3: amenities[2].name,
amenity4: amenities[3].name,
}
)
if (hotelDescription.length > 160) {
if (shortHotelDescription.length > 160) {
return truncateTextAfterLastPeriod(shortHotelDescription)
}
return shortHotelDescription
} else {
return hotelDescription
}
}