feat(BOOK-57): Adjusted metadata for destination pages with active seo filter
Approved-by: Chuma Mcphoy (We Ahead)
This commit is contained in:
110
apps/scandic-web/utils/metadata/description/destinationPage.ts
Normal file
110
apps/scandic-web/utils/metadata/description/destinationPage.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
import { truncateTextAfterLastPeriod } from "../truncate"
|
||||
|
||||
import type { RawMetadataSchema } from "@scandic-hotels/trpc/routers/contentstack/metadata/output"
|
||||
|
||||
export async function getDestinationCityPageDescription(
|
||||
data: RawMetadataSchema
|
||||
) {
|
||||
const intl = await getIntl()
|
||||
|
||||
if (!data.destinationData?.location) {
|
||||
return null
|
||||
}
|
||||
|
||||
const { hotelCount, location } = data.destinationData
|
||||
|
||||
if (hotelCount === 1) {
|
||||
const destinationCitySingleHotelDescription = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Discover our Scandic hotel in {location}. Start your day with a delicious breakfast before exploring {location}. Book your stay at a Scandic hotel now!",
|
||||
},
|
||||
{ location }
|
||||
)
|
||||
|
||||
return truncateTextAfterLastPeriod(destinationCitySingleHotelDescription)
|
||||
}
|
||||
const destinationCityMultipleHotelDescription = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Discover all our {hotelCount} Scandic hotels in {location}. Start your day with a delicious breakfast before exploring {location}. Book your stay at a Scandic hotel now!",
|
||||
},
|
||||
{ hotelCount, location }
|
||||
)
|
||||
|
||||
return truncateTextAfterLastPeriod(destinationCityMultipleHotelDescription)
|
||||
}
|
||||
|
||||
export async function getDestinationCountryPageDescription(
|
||||
data: RawMetadataSchema
|
||||
) {
|
||||
const intl = await getIntl()
|
||||
|
||||
if (!data.destinationData?.location) {
|
||||
return null
|
||||
}
|
||||
|
||||
const { hotelCount, location, cities } = data.destinationData
|
||||
|
||||
let destinationCountryDescription: string | null = null
|
||||
|
||||
if (!hotelCount) {
|
||||
destinationCountryDescription = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Discover {location}. Enjoy your stay at a Scandic hotel. Book now!",
|
||||
},
|
||||
{ location }
|
||||
)
|
||||
} else if (!cities || cities.length < 2) {
|
||||
destinationCountryDescription = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Discover all our {hotelCount} Scandic hotels in {location}. Enjoy your stay at a Scandic hotel. Book now!",
|
||||
},
|
||||
{ hotelCount, location }
|
||||
)
|
||||
} else {
|
||||
destinationCountryDescription = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"Discover all our {hotelCount} Scandic hotels in {location}. Explore {city1}, {city2}, and more! All while enjoying your stay at a Scandic hotel. Book now!",
|
||||
},
|
||||
{
|
||||
hotelCount: hotelCount,
|
||||
location: location,
|
||||
city1: cities[0],
|
||||
city2: cities[1],
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return truncateTextAfterLastPeriod(destinationCountryDescription)
|
||||
}
|
||||
|
||||
export function getDestinationFilterSeoMetaDescription(
|
||||
data: RawMetadataSchema
|
||||
) {
|
||||
const filter = data.destinationData?.filter
|
||||
|
||||
if (!filter) {
|
||||
return null
|
||||
}
|
||||
const foundSeoFilter = data.seo_filters?.find(
|
||||
(f) => f.filterConnection.edges[0]?.node?.slug === filter
|
||||
)
|
||||
|
||||
if (foundSeoFilter) {
|
||||
if (foundSeoFilter.seo_metadata?.description) {
|
||||
return foundSeoFilter.seo_metadata.description
|
||||
}
|
||||
|
||||
if (foundSeoFilter.preamble) {
|
||||
return truncateTextAfterLastPeriod(foundSeoFilter.preamble)
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user