Merged in feat/SW-1845-metadata-hreflang (pull request #1504)
feat(SW-1845): Added alternates to metadata * feat(SW-1845): Added alternates to metadata Approved-by: Linus Flood
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { baseUrls } from "@/constants/routes/baseUrls"
|
||||
import { findMyBooking } from "@/constants/routes/findMyBooking"
|
||||
import { hotelreservation } from "@/constants/routes/hotelReservation"
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import { attributesSchema as hotelAttributesSchema } from "../../hotels/schemas/hotel"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
@@ -8,7 +13,9 @@ import { getDescription, getImage, getTitle } from "./utils"
|
||||
import type { Metadata } from "next"
|
||||
|
||||
import { Country } from "@/types/enums/country"
|
||||
import type { LanguageSwitcherData } from "@/types/requests/languageSwitcher"
|
||||
import { RTETypeEnum } from "@/types/rte/enums"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
const metaDataJsonSchema = z.object({
|
||||
children: z.array(
|
||||
@@ -101,6 +108,7 @@ export const metadataSchema = rawMetadataSchema.transform(async (data) => {
|
||||
const noIndex = !!data.web?.seo_metadata?.noindex
|
||||
|
||||
const metadata: Metadata = {
|
||||
metadataBase: new URL(env.PUBLIC_URL),
|
||||
title: await getTitle(data),
|
||||
description: getDescription(data),
|
||||
openGraph: {
|
||||
@@ -116,3 +124,21 @@ export const metadataSchema = rawMetadataSchema.transform(async (data) => {
|
||||
}
|
||||
return metadata
|
||||
})
|
||||
|
||||
// Several pages are not currently routed within contentstack context.
|
||||
// This function is used to generate the urls for these pages.
|
||||
export function getNonContentstackUrls(lang: Lang, pathName: string) {
|
||||
if (Object.values(findMyBooking).includes(pathName)) {
|
||||
const urls: LanguageSwitcherData = {}
|
||||
return Object.entries(findMyBooking).reduce((acc, [lang, url]) => {
|
||||
acc[lang as Lang] = { url }
|
||||
return urls
|
||||
}, urls)
|
||||
}
|
||||
|
||||
if (pathName.startsWith(hotelreservation(lang))) {
|
||||
return baseUrls
|
||||
}
|
||||
|
||||
return { [lang]: { url: pathName } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user