feat(BOOK-57): Adjusted metadata for destination pages with active seo filter
Approved-by: Chuma Mcphoy (We Ahead)
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
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 || !data.destinationData.hotelCount) {
|
||||
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: 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: hotelCount,
|
||||
location: location,
|
||||
}
|
||||
)
|
||||
|
||||
return truncateTextAfterLastPeriod(destinationCityMultipleHotelDescription)
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
import { truncateTextAfterLastPeriod } from "../truncate"
|
||||
|
||||
import type { RawMetadataSchema } from "@scandic-hotels/trpc/routers/contentstack/metadata/output"
|
||||
|
||||
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)
|
||||
}
|
||||
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
|
||||
}
|
||||
@@ -1,15 +1,31 @@
|
||||
import { PageContentTypeEnum } from "@scandic-hotels/trpc/enums/contentType"
|
||||
import { RTETypeEnum } from "@scandic-hotels/trpc/types/RTEenums"
|
||||
|
||||
import {
|
||||
getDestinationCityPageDescription,
|
||||
getDestinationCountryPageDescription,
|
||||
getDestinationFilterSeoMetaDescription,
|
||||
} from "@/utils/metadata/description/destinationPage"
|
||||
|
||||
import { truncateTextAfterLastPeriod } from "../truncate"
|
||||
import { getDestinationCityPageDescription } from "./destinationCityPage"
|
||||
import { getDestinationCountryPageDescription } from "./destinationCountryPage"
|
||||
import { getHotelPageDescription } from "./hotelPage"
|
||||
|
||||
import type { RawMetadataSchema } from "@scandic-hotels/trpc/routers/contentstack/metadata/output"
|
||||
|
||||
export async function getDescription(data: RawMetadataSchema) {
|
||||
const metadata = data.web?.seo_metadata
|
||||
const isDestinationPage = [
|
||||
PageContentTypeEnum.destinationCityPage,
|
||||
PageContentTypeEnum.destinationCountryPage,
|
||||
].includes(data.system.content_type_uid as PageContentTypeEnum)
|
||||
|
||||
if (isDestinationPage) {
|
||||
const destinationFilterSeoMetaDescription =
|
||||
getDestinationFilterSeoMetaDescription(data)
|
||||
if (destinationFilterSeoMetaDescription) {
|
||||
return destinationFilterSeoMetaDescription
|
||||
}
|
||||
}
|
||||
|
||||
if (metadata?.description) {
|
||||
return metadata.description
|
||||
|
||||
Reference in New Issue
Block a user