Merged in feat/sw-2863-move-contentstack-router-to-trpc-package (pull request #2389)
feat(SW-2863): Move contentstack router to trpc package * Add exports to packages and lint rule to prevent relative imports * Add env to trpc package * Add eslint to trpc package * Apply lint rules * Use direct imports from trpc package * Add lint-staged config to trpc * Move lang enum to common * Restructure trpc package folder structure * WIP first step * update internal imports in trpc * Fix most errors in scandic-web Just 100 left... * Move Props type out of trpc * Fix CategorizedFilters types * Move more schemas in hotel router * Fix deps * fix getNonContentstackUrls * Fix import error * Fix entry error handling * Fix generateMetadata metrics * Fix alertType enum * Fix duplicated types * lint:fix * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package * Fix broken imports * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package Approved-by: Linus Flood
This commit is contained in:
59
apps/scandic-web/utils/metadata/description/index.ts
Normal file
59
apps/scandic-web/utils/metadata/description/index.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { PageContentTypeEnum } from "@scandic-hotels/trpc/enums/contentType"
|
||||
import { RTETypeEnum } from "@scandic-hotels/trpc/types/RTEenums"
|
||||
|
||||
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
|
||||
|
||||
if (metadata?.description) {
|
||||
return metadata.description
|
||||
}
|
||||
|
||||
let description: string | null = null
|
||||
switch (data.system.content_type_uid) {
|
||||
case PageContentTypeEnum.hotelPage:
|
||||
description = await getHotelPageDescription(data)
|
||||
break
|
||||
case PageContentTypeEnum.destinationCityPage:
|
||||
description = await getDestinationCityPageDescription(data)
|
||||
break
|
||||
case PageContentTypeEnum.destinationCountryPage:
|
||||
description = await getDestinationCountryPageDescription(data)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if (description) {
|
||||
return description
|
||||
}
|
||||
|
||||
// Fallback descriptions from contentstack content
|
||||
if (data.preamble) {
|
||||
return truncateTextAfterLastPeriod(data.preamble)
|
||||
}
|
||||
if (data.header?.preamble) {
|
||||
return truncateTextAfterLastPeriod(data.header.preamble)
|
||||
}
|
||||
if (data.blocks?.length) {
|
||||
const jsonData = data.blocks[0].content?.content?.json
|
||||
// Finding the first paragraph with text
|
||||
const firstParagraph = jsonData?.children?.find(
|
||||
(child) => child.type === RTETypeEnum.p && child.children[0].text
|
||||
)
|
||||
|
||||
if (firstParagraph?.children?.length) {
|
||||
return firstParagraph.children[0].text
|
||||
? truncateTextAfterLastPeriod(firstParagraph.children[0].text)
|
||||
: ""
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user