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
This commit is contained in:
214
apps/scandic-web/utils/metadata/title.ts
Normal file
214
apps/scandic-web/utils/metadata/title.ts
Normal file
@@ -0,0 +1,214 @@
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
import type { RawMetadataSchema } from "@scandic-hotels/trpc/routers/contentstack/metadata/output"
|
||||
|
||||
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) {
|
||||
const restaurantTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Explore {restaurantName} at {hotelName} in {destination}",
|
||||
},
|
||||
{
|
||||
restaurantName: restaurantSubPage.name,
|
||||
hotelName: data.hotelData.name,
|
||||
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 & reviews for {hotelName} in {destination}",
|
||||
},
|
||||
{
|
||||
hotelName: data.hotelData.name,
|
||||
destination: data.hotelData.address.city,
|
||||
}
|
||||
)
|
||||
const reviewsTitleShort = intl.formatMessage(
|
||||
{ defaultMessage: "Ratings & reviews for {hotelName}" },
|
||||
{ hotelName: data.hotelData.name }
|
||||
)
|
||||
if (reviewsTitleLong.length > 60) {
|
||||
return reviewsTitleShort
|
||||
}
|
||||
return reviewsTitleLong
|
||||
case data.additionalHotelData?.hotelParking.nameInUrl:
|
||||
const parkingTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Parking information for {hotelName} in {destination}",
|
||||
},
|
||||
{
|
||||
hotelName: data.hotelData.name,
|
||||
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:
|
||||
const wellnessTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Gym & health facilities at {hotelName} in {destination}",
|
||||
},
|
||||
{
|
||||
hotelName: data.hotelData.name,
|
||||
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:
|
||||
const accessibilityTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Accessibility information for {hotelName} in {destination}",
|
||||
},
|
||||
{
|
||||
hotelName: data.hotelData.name,
|
||||
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:
|
||||
const meetingsTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"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
|
||||
}
|
||||
}
|
||||
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 ""
|
||||
}
|
||||
Reference in New Issue
Block a user