feat(BOOK-57): Adjusted metadata for destination pages with active seo filter
Approved-by: Chuma Mcphoy (We Ahead)
This commit is contained in:
61
apps/scandic-web/utils/metadata/title/destinationPage.ts
Normal file
61
apps/scandic-web/utils/metadata/title/destinationPage.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
import type { RawMetadataSchema } from "@scandic-hotels/trpc/routers/contentstack/metadata/output"
|
||||
|
||||
export async function getDestinationPageTitle(
|
||||
data: RawMetadataSchema,
|
||||
pageType: "city" | "country",
|
||||
suffix: string
|
||||
) {
|
||||
const intl = await getIntl()
|
||||
const { destinationData } = data
|
||||
if (!destinationData) {
|
||||
return null
|
||||
}
|
||||
|
||||
const location = destinationData.location
|
||||
|
||||
if (!location) {
|
||||
return null
|
||||
}
|
||||
const destinationTitle =
|
||||
pageType === "country"
|
||||
? intl.formatMessage(
|
||||
{
|
||||
defaultMessage: "Destinations in {location}",
|
||||
},
|
||||
{ location }
|
||||
)
|
||||
: intl.formatMessage(
|
||||
{
|
||||
defaultMessage: "Hotels in {location}",
|
||||
},
|
||||
{ location }
|
||||
)
|
||||
|
||||
return `${destinationTitle}${suffix}`
|
||||
}
|
||||
|
||||
export function getDestinationFilterSeoMetaTitle(
|
||||
data: RawMetadataSchema,
|
||||
suffix: string
|
||||
) {
|
||||
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?.title) {
|
||||
return `${foundSeoFilter.seo_metadata.title}${suffix}`
|
||||
}
|
||||
|
||||
return `${foundSeoFilter.heading}${suffix}`
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user