Feat/SW-1454 listing skeletons * feat(SW-1453): added skeleton for city listning * feat(SW-1454): added skeleton for hotel listning Approved-by: Fredrik Thorsson
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import { generateTag, generateTagsFromSystem } from "@/utils/generateTag"
|
|
|
|
import { DestinationCityPageEnum } from "@/types/enums/destinationCityPage"
|
|
import type { System } from "@/types/requests/system"
|
|
import type { DestinationCityPageRefs } from "@/types/trpc/routers/contentstack/destinationCityPage"
|
|
import type { Lang } from "@/constants/languages"
|
|
|
|
export function generatePageTags(
|
|
validatedData: DestinationCityPageRefs,
|
|
lang: Lang
|
|
): string[] {
|
|
const connections = getConnections(validatedData)
|
|
return [
|
|
generateTagsFromSystem(lang, connections),
|
|
generateTag(lang, validatedData.destination_city_page.system.uid),
|
|
].flat()
|
|
}
|
|
|
|
export function getConnections({
|
|
destination_city_page,
|
|
}: DestinationCityPageRefs) {
|
|
const connections: System["system"][] = [destination_city_page.system]
|
|
if (destination_city_page.blocks) {
|
|
destination_city_page.blocks.forEach((block) => {
|
|
switch (block.__typename) {
|
|
case DestinationCityPageEnum.ContentStack.blocks.Accordion: {
|
|
if (block.accordion.length) {
|
|
connections.push(...block.accordion)
|
|
}
|
|
break
|
|
}
|
|
case DestinationCityPageEnum.ContentStack.blocks.Content:
|
|
{
|
|
if (block.content.length) {
|
|
// TS has trouble infering the filtered types
|
|
// @ts-ignore
|
|
connections.push(...block.content)
|
|
}
|
|
}
|
|
break
|
|
}
|
|
})
|
|
}
|
|
if (destination_city_page.sidepeek_content) {
|
|
destination_city_page.sidepeek_content.content.embedded_itemsConnection.edges.forEach(
|
|
({ node }) => {
|
|
connections.push(node.system)
|
|
}
|
|
)
|
|
}
|
|
|
|
return connections
|
|
}
|