62 lines
1.3 KiB
TypeScript
62 lines
1.3 KiB
TypeScript
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
|
|
}
|