feat(SW-285): Ship support for ContentPageBlocksCardsGrid

This commit is contained in:
Chuma McPhoy
2024-09-02 10:23:21 +02:00
parent dd336ca4ab
commit e88e4d92bf
8 changed files with 320 additions and 5 deletions
@@ -6,6 +6,7 @@ import { request } from "@/lib/graphql/request"
import { notFound } from "@/server/errors/trpc"
import { generateTag, generateTags } from "@/utils/generateTag"
import { removeMultipleSlashes } from "@/utils/url"
import { removeEmptyObjects } from "../../utils"
import { ContentPageRefsDataRaw, validateContentPageRefsSchema } from "./output"
@@ -130,3 +131,29 @@ export function getConnections(refs: ContentPageRefsDataRaw) {
}
return connections
}
export function makeButtonObject(button: any) {
if (!button) return null
const isContenstackLink =
button?.is_contentstack_link || button.linkConnection?.edges?.length
const linkConnnectionNode = isContenstackLink
? button.linkConnection.edges[0]?.node
: null
return {
openInNewTab: button?.open_in_new_tab,
title:
button.cta_text ||
(linkConnnectionNode
? linkConnnectionNode.title
: button.external_link.title),
href: linkConnnectionNode
? linkConnnectionNode.web?.original_url ||
removeMultipleSlashes(
`/${linkConnnectionNode.system.locale}/${linkConnnectionNode.url}`
)
: button.external_link.href,
isExternal: !isContenstackLink,
}
}