feat(BOOK-609): Using embedded url for assets instead of href since that is not updated when the asset is updated)
* feat(BOOK-609): Updated refs handling for assets inside content pages Approved-by: Linus Flood
This commit is contained in:
@@ -16,9 +16,10 @@ export type Node<T> = {
|
|||||||
export type Embeds =
|
export type Embeds =
|
||||||
| {
|
| {
|
||||||
__typename: Exclude<ContentBlockType, "ImageContainer">
|
__typename: Exclude<ContentBlockType, "ImageContainer">
|
||||||
system?: { uid: string } | undefined | null
|
system?: { uid: string } | null
|
||||||
url?: string | undefined | null
|
url?: string | null
|
||||||
title?: string | undefined | null
|
permanent_url?: string | null
|
||||||
|
title?: string | null
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
__typename: "ImageContainer"
|
__typename: "ImageContainer"
|
||||||
|
|||||||
@@ -404,13 +404,29 @@ export const renderOptions: RenderOptions = {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (node.attrs["display-type"] === "link" && node.attrs.href) {
|
} else if (node.attrs["display-type"] === "link") {
|
||||||
|
const asset = embeds?.[node?.attrs?.["asset-uid"] as string]
|
||||||
|
|
||||||
|
// Decision note 2026-01-07:
|
||||||
|
// Content team sometimes updates assets without updating the RTE reference.
|
||||||
|
// The `permanent_url` should be used on the asset in Contentstack.
|
||||||
|
// If this is not provided, we should not render the link.
|
||||||
|
const rawUrl =
|
||||||
|
asset?.node && "permanent_url" in asset.node
|
||||||
|
? asset.node.permanent_url
|
||||||
|
: null
|
||||||
|
if (!rawUrl) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const { className, ...props } = extractPossibleAttributes(node.attrs)
|
const { className, ...props } = extractPossibleAttributes(node.attrs)
|
||||||
|
|
||||||
|
const cleanUrl = rawUrl.split("?")[0]
|
||||||
return (
|
return (
|
||||||
<TextLink
|
<TextLink
|
||||||
key={node.uid}
|
key={node.uid}
|
||||||
className={className}
|
className={className}
|
||||||
href={node.attrs.href as string}
|
href={cleanUrl}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
isInline
|
isInline
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import { PromoCampaignPageLink } from "../PageLink/PromoCampaignPageLink.graphql
|
|||||||
import { StartPageLink } from "../PageLink/StartPageLink.graphql"
|
import { StartPageLink } from "../PageLink/StartPageLink.graphql"
|
||||||
import { PromoCampaignPageRef } from "../PromoCampaignPage/Ref.graphql"
|
import { PromoCampaignPageRef } from "../PromoCampaignPage/Ref.graphql"
|
||||||
import { StartPageRef } from "../StartPage/Ref.graphql"
|
import { StartPageRef } from "../StartPage/Ref.graphql"
|
||||||
import { SysAsset } from "../SysAsset.graphql"
|
import { SysAsset, SysAssetRef } from "../SysAsset.graphql"
|
||||||
|
|
||||||
export const Content_ContentPage = gql`
|
export const Content_ContentPage = gql`
|
||||||
fragment Content_ContentPage on ContentPageBlocksContent {
|
fragment Content_ContentPage on ContentPageBlocksContent {
|
||||||
@@ -80,6 +80,7 @@ export const Content_ContentPageRefs = gql`
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
|
...SysAssetRef
|
||||||
...ImageContainerRef
|
...ImageContainerRef
|
||||||
...AccountPageRef
|
...AccountPageRef
|
||||||
...CampaignOverviewPageRef
|
...CampaignOverviewPageRef
|
||||||
@@ -99,6 +100,7 @@ export const Content_ContentPageRefs = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
${SysAssetRef}
|
||||||
${ImageContainerRef}
|
${ImageContainerRef}
|
||||||
${AccountPageRef}
|
${AccountPageRef}
|
||||||
${CampaignOverviewPageRef}
|
${CampaignOverviewPageRef}
|
||||||
@@ -167,6 +169,7 @@ export const Content_LoyaltyPageRefs = gql`
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
|
...SysAssetRef
|
||||||
...AccountPageRef
|
...AccountPageRef
|
||||||
...CampaignOverviewPageRef
|
...CampaignOverviewPageRef
|
||||||
...CampaignPageRef
|
...CampaignPageRef
|
||||||
@@ -185,6 +188,7 @@ export const Content_LoyaltyPageRefs = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
${SysAssetRef}
|
||||||
${AccountPageRef}
|
${AccountPageRef}
|
||||||
${CampaignOverviewPageRef}
|
${CampaignOverviewPageRef}
|
||||||
${CampaignPageRef}
|
${CampaignPageRef}
|
||||||
@@ -450,6 +454,7 @@ export const Content_PromoCampaignPage = gql`
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
|
...SysAsset
|
||||||
...AccountPageLink
|
...AccountPageLink
|
||||||
...CampaignOverviewPageLink
|
...CampaignOverviewPageLink
|
||||||
...CampaignPageLink
|
...CampaignPageLink
|
||||||
@@ -469,6 +474,7 @@ export const Content_PromoCampaignPage = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
${SysAsset}
|
||||||
${AccountPageLink}
|
${AccountPageLink}
|
||||||
${CampaignOverviewPageLink}
|
${CampaignOverviewPageLink}
|
||||||
${CampaignPageLink}
|
${CampaignPageLink}
|
||||||
@@ -491,6 +497,7 @@ export const Content_PromoCampaignPageRefs = gql`
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
|
...SysAssetRef
|
||||||
...AccountPageRef
|
...AccountPageRef
|
||||||
...CampaignOverviewPageRef
|
...CampaignOverviewPageRef
|
||||||
...CampaignPageRef
|
...CampaignPageRef
|
||||||
@@ -509,6 +516,7 @@ export const Content_PromoCampaignPageRefs = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
${SysAssetRef}
|
||||||
${AccountPageRef}
|
${AccountPageRef}
|
||||||
${CampaignOverviewPageRef}
|
${CampaignOverviewPageRef}
|
||||||
${CampaignPageRef}
|
${CampaignPageRef}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import { PromoCampaignPageLink } from "../PageLink/PromoCampaignPageLink.graphql
|
|||||||
import { StartPageLink } from "../PageLink/StartPageLink.graphql"
|
import { StartPageLink } from "../PageLink/StartPageLink.graphql"
|
||||||
import { PromoCampaignPageRef } from "../PromoCampaignPage/Ref.graphql"
|
import { PromoCampaignPageRef } from "../PromoCampaignPage/Ref.graphql"
|
||||||
import { StartPageRef } from "../StartPage/Ref.graphql"
|
import { StartPageRef } from "../StartPage/Ref.graphql"
|
||||||
import { SysAsset } from "../SysAsset.graphql"
|
import { SysAsset, SysAssetRef } from "../SysAsset.graphql"
|
||||||
|
|
||||||
export const ContentSidebar_ContentPage = gql`
|
export const ContentSidebar_ContentPage = gql`
|
||||||
fragment ContentSidebar_ContentPage on ContentPageSidebarContent {
|
fragment ContentSidebar_ContentPage on ContentPageSidebarContent {
|
||||||
@@ -80,6 +80,7 @@ export const ContentSidebar_ContentPageRefs = gql`
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
|
...SysAssetRef
|
||||||
...ImageContainerRef
|
...ImageContainerRef
|
||||||
...AccountPageRef
|
...AccountPageRef
|
||||||
...CampaignOverviewPageRef
|
...CampaignOverviewPageRef
|
||||||
@@ -99,6 +100,7 @@ export const ContentSidebar_ContentPageRefs = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
${SysAssetRef}
|
||||||
${ImageContainerRef}
|
${ImageContainerRef}
|
||||||
${AccountPageRef}
|
${AccountPageRef}
|
||||||
${CampaignOverviewPageRef}
|
${CampaignOverviewPageRef}
|
||||||
@@ -167,6 +169,7 @@ export const ContentSidebar_LoyaltyPageRefs = gql`
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
|
...SysAssetRef
|
||||||
...ImageContainerRef
|
...ImageContainerRef
|
||||||
...AccountPageRef
|
...AccountPageRef
|
||||||
...CampaignOverviewPageRef
|
...CampaignOverviewPageRef
|
||||||
@@ -186,6 +189,7 @@ export const ContentSidebar_LoyaltyPageRefs = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
${SysAssetRef}
|
||||||
${ImageContainerRef}
|
${ImageContainerRef}
|
||||||
${AccountPageRef}
|
${AccountPageRef}
|
||||||
${CampaignOverviewPageRef}
|
${CampaignOverviewPageRef}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { gql } from "graphql-tag"
|
import { gql } from "graphql-tag"
|
||||||
|
|
||||||
|
import { AssetSystem } from "./System.graphql"
|
||||||
|
|
||||||
export const SysAsset = gql`
|
export const SysAsset = gql`
|
||||||
fragment SysAsset on SysAsset {
|
fragment SysAsset on SysAsset {
|
||||||
content_type
|
content_type
|
||||||
@@ -10,9 +12,22 @@ export const SysAsset = gql`
|
|||||||
}
|
}
|
||||||
metadata
|
metadata
|
||||||
system {
|
system {
|
||||||
uid
|
...AssetSystem
|
||||||
}
|
}
|
||||||
title
|
title
|
||||||
url
|
url
|
||||||
|
permanent_url
|
||||||
}
|
}
|
||||||
|
${AssetSystem}
|
||||||
|
`
|
||||||
|
|
||||||
|
export const SysAssetRef = gql`
|
||||||
|
fragment SysAssetRef on SysAsset {
|
||||||
|
system {
|
||||||
|
...AssetSystem
|
||||||
|
}
|
||||||
|
url
|
||||||
|
permanent_url
|
||||||
|
}
|
||||||
|
${AssetSystem}
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export const VideoRef = gql`
|
|||||||
system {
|
system {
|
||||||
...AssetSystem
|
...AssetSystem
|
||||||
}
|
}
|
||||||
|
url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,8 +84,7 @@ export function generatePageTags(
|
|||||||
validatedData: CollectionPageRefs,
|
validatedData: CollectionPageRefs,
|
||||||
lang: Lang
|
lang: Lang
|
||||||
): string[] {
|
): string[] {
|
||||||
const connections = getConnections(validatedData)
|
const { connections, assetConnections } = getConnections(validatedData)
|
||||||
const assetConnections = getConnectionsFromAssets(validatedData)
|
|
||||||
return [
|
return [
|
||||||
generateTagsFromSystem(lang, connections),
|
generateTagsFromSystem(lang, connections),
|
||||||
generateTagsFromAssetSystem(assetConnections),
|
generateTagsFromAssetSystem(assetConnections),
|
||||||
@@ -93,38 +92,16 @@ export function generatePageTags(
|
|||||||
].flat()
|
].flat()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConnectionsFromAssets({
|
export function getConnections({ collection_page }: CollectionPageRefs) {
|
||||||
collection_page,
|
const connections: System["system"][] = [collection_page.system]
|
||||||
}: CollectionPageRefs) {
|
const assetConnections: AssetSystem[] = []
|
||||||
const connections: AssetSystem["system"][] = []
|
|
||||||
|
|
||||||
if (collection_page.hero_video?.sourceConnection.edges[0]) {
|
if (collection_page.hero_video?.sourceConnection.edges[0]) {
|
||||||
connections.push(
|
assetConnections.push(
|
||||||
collection_page.hero_video.sourceConnection.edges[0].node.system
|
collection_page.hero_video.sourceConnection.edges[0].node
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collection_page.blocks) {
|
|
||||||
collection_page.blocks.forEach((block) => {
|
|
||||||
switch (block.__typename) {
|
|
||||||
case CollectionPageEnum.ContentStack.blocks.VideoCard:
|
|
||||||
if (block.video_card?.video.sourceConnection.edges[0]) {
|
|
||||||
connections.push(
|
|
||||||
block.video_card.video.sourceConnection.edges[0].node.system
|
|
||||||
)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return connections
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getConnections({ collection_page }: CollectionPageRefs) {
|
|
||||||
const connections: System["system"][] = [collection_page.system]
|
|
||||||
if (collection_page.blocks) {
|
if (collection_page.blocks) {
|
||||||
collection_page.blocks.forEach((block) => {
|
collection_page.blocks.forEach((block) => {
|
||||||
const typeName = block.__typename
|
const typeName = block.__typename
|
||||||
@@ -148,6 +125,11 @@ export function getConnections({ collection_page }: CollectionPageRefs) {
|
|||||||
if (block.video_card?.system) {
|
if (block.video_card?.system) {
|
||||||
connections.push(block.video_card.system)
|
connections.push(block.video_card.system)
|
||||||
}
|
}
|
||||||
|
if (block.video_card?.video.sourceConnection.edges[0]) {
|
||||||
|
assetConnections.push(
|
||||||
|
block.video_card.video.sourceConnection.edges[0].node
|
||||||
|
)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case CollectionPageEnum.ContentStack.blocks.DynamicContent:
|
case CollectionPageEnum.ContentStack.blocks.DynamicContent:
|
||||||
break
|
break
|
||||||
@@ -158,5 +140,5 @@ export function getConnections({ collection_page }: CollectionPageRefs) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return connections
|
return { connections, assetConnections }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,8 +76,7 @@ export function generatePageTags(
|
|||||||
validatedData: ContentPageRefs,
|
validatedData: ContentPageRefs,
|
||||||
lang: Lang
|
lang: Lang
|
||||||
): string[] {
|
): string[] {
|
||||||
const connections = getConnections(validatedData)
|
const { connections, assetConnections } = getConnections(validatedData)
|
||||||
const assetConnections = getConnectionsFromAssets(validatedData)
|
|
||||||
return [
|
return [
|
||||||
generateTagsFromSystem(lang, connections),
|
generateTagsFromSystem(lang, connections),
|
||||||
generateTagsFromAssetSystem(assetConnections),
|
generateTagsFromAssetSystem(assetConnections),
|
||||||
@@ -85,40 +84,15 @@ export function generatePageTags(
|
|||||||
].flat()
|
].flat()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConnectionsFromAssets({ content_page }: ContentPageRefs) {
|
|
||||||
const connections: AssetSystem["system"][] = []
|
|
||||||
|
|
||||||
if (content_page.hero_video?.sourceConnection.edges[0]) {
|
|
||||||
connections.push(
|
|
||||||
content_page.hero_video.sourceConnection.edges[0].node.system
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (content_page.blocks) {
|
|
||||||
content_page.blocks.forEach((block) => {
|
|
||||||
switch (block.__typename) {
|
|
||||||
case ContentPageEnum.ContentStack.blocks.VideoCard:
|
|
||||||
if (block.video_card?.video.sourceConnection.edges[0]) {
|
|
||||||
connections.push(
|
|
||||||
block.video_card.video.sourceConnection.edges[0].node.system
|
|
||||||
)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case ContentPageEnum.ContentStack.blocks.Video:
|
|
||||||
if (block.video?.sourceConnection.edges[0]) {
|
|
||||||
connections.push(block.video.sourceConnection.edges[0].node.system)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return connections
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getConnections({ content_page }: ContentPageRefs) {
|
export function getConnections({ content_page }: ContentPageRefs) {
|
||||||
const connections: System["system"][] = [content_page.system]
|
const connections: System["system"][] = [content_page.system]
|
||||||
|
const assetConnections: AssetSystem[] = []
|
||||||
|
|
||||||
|
if (content_page.hero_video?.sourceConnection.edges[0]) {
|
||||||
|
assetConnections.push(
|
||||||
|
content_page.hero_video.sourceConnection.edges[0].node
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (content_page.blocks) {
|
if (content_page.blocks) {
|
||||||
content_page.blocks.forEach((block) => {
|
content_page.blocks.forEach((block) => {
|
||||||
@@ -130,10 +104,14 @@ export function getConnections({ content_page }: ContentPageRefs) {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case ContentPageEnum.ContentStack.blocks.Content:
|
case ContentPageEnum.ContentStack.blocks.Content:
|
||||||
{
|
if (block?.content?.length) {
|
||||||
if (block?.content?.length) {
|
block.content.forEach((contentBlock) => {
|
||||||
connections.push(...block.content)
|
if ("system" in contentBlock) {
|
||||||
}
|
assetConnections.push(contentBlock)
|
||||||
|
} else {
|
||||||
|
connections.push(contentBlock)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case ContentPageEnum.ContentStack.blocks.CardsGrid:
|
case ContentPageEnum.ContentStack.blocks.CardsGrid:
|
||||||
@@ -172,8 +150,16 @@ export function getConnections({ content_page }: ContentPageRefs) {
|
|||||||
if (block.video_card) {
|
if (block.video_card) {
|
||||||
connections.push(block.video_card.system)
|
connections.push(block.video_card.system)
|
||||||
}
|
}
|
||||||
|
if (block.video_card?.video.sourceConnection.edges[0]) {
|
||||||
|
assetConnections.push(
|
||||||
|
block.video_card.video.sourceConnection.edges[0].node
|
||||||
|
)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case ContentPageEnum.ContentStack.blocks.Video:
|
case ContentPageEnum.ContentStack.blocks.Video:
|
||||||
|
if (block.video?.sourceConnection.edges[0]) {
|
||||||
|
assetConnections.push(block.video.sourceConnection.edges[0].node)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case ContentPageEnum.ContentStack.blocks.Jotform:
|
case ContentPageEnum.ContentStack.blocks.Jotform:
|
||||||
if (block.jotform) {
|
if (block.jotform) {
|
||||||
@@ -192,8 +178,14 @@ export function getConnections({ content_page }: ContentPageRefs) {
|
|||||||
const typeName = block.__typename
|
const typeName = block.__typename
|
||||||
switch (typeName) {
|
switch (typeName) {
|
||||||
case ContentPageEnum.ContentStack.sidebar.Content:
|
case ContentPageEnum.ContentStack.sidebar.Content:
|
||||||
if (block.content.length) {
|
if (block.content?.length) {
|
||||||
connections.push(...block.content.filter((c) => !!c))
|
block.content.forEach((contentBlock) => {
|
||||||
|
if ("system" in contentBlock) {
|
||||||
|
assetConnections.push(contentBlock)
|
||||||
|
} else {
|
||||||
|
connections.push(contentBlock)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case ContentPageEnum.ContentStack.sidebar.JoinLoyaltyContact:
|
case ContentPageEnum.ContentStack.sidebar.JoinLoyaltyContact:
|
||||||
@@ -222,5 +214,5 @@ export function getConnections({ content_page }: ContentPageRefs) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return connections
|
return { connections, assetConnections }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { contentstackExtendedProcedureUID } from "../../../procedures"
|
|||||||
import {
|
import {
|
||||||
generateRefsResponseTag,
|
generateRefsResponseTag,
|
||||||
generateTag,
|
generateTag,
|
||||||
|
generateTagsFromAssetSystem,
|
||||||
generateTagsFromSystem,
|
generateTagsFromSystem,
|
||||||
} from "../../../utils/generateTag"
|
} from "../../../utils/generateTag"
|
||||||
import { loyaltyPageRefsSchema, loyaltyPageSchema } from "./output"
|
import { loyaltyPageRefsSchema, loyaltyPageSchema } from "./output"
|
||||||
@@ -64,10 +65,13 @@ export const loyaltyPageQueryRouter = router({
|
|||||||
|
|
||||||
metricsGetLoyaltyPageRefs.success()
|
metricsGetLoyaltyPageRefs.success()
|
||||||
|
|
||||||
const connections = getConnections(validatedLoyaltyPageRefs.data)
|
const { connections, assetConnections } = getConnections(
|
||||||
|
validatedLoyaltyPageRefs.data
|
||||||
|
)
|
||||||
|
|
||||||
const tags = [
|
const tags = [
|
||||||
generateTagsFromSystem(lang, connections),
|
generateTagsFromSystem(lang, connections),
|
||||||
|
generateTagsFromAssetSystem(assetConnections),
|
||||||
generateTag(lang, validatedLoyaltyPageRefs.data.loyalty_page.system.uid),
|
generateTag(lang, validatedLoyaltyPageRefs.data.loyalty_page.system.uid),
|
||||||
].flat()
|
].flat()
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { LoyaltyPageEnum } from "../../../enums/loyaltyPage"
|
import { LoyaltyPageEnum } from "../../../enums/loyaltyPage"
|
||||||
|
|
||||||
import type { LoyaltyPageRefs } from "../../../types/loyaltyPage"
|
import type { LoyaltyPageRefs } from "../../../types/loyaltyPage"
|
||||||
import type { System } from "../schemas/system"
|
import type { AssetSystem, System } from "../schemas/system"
|
||||||
|
|
||||||
export function getConnections({ loyalty_page }: LoyaltyPageRefs) {
|
export function getConnections({ loyalty_page }: LoyaltyPageRefs) {
|
||||||
const connections: System["system"][] = [loyalty_page.system]
|
const connections: System["system"][] = [loyalty_page.system]
|
||||||
|
const assetConnections: AssetSystem[] = []
|
||||||
|
|
||||||
if (loyalty_page.blocks) {
|
if (loyalty_page.blocks) {
|
||||||
loyalty_page.blocks.forEach((block) => {
|
loyalty_page.blocks.forEach((block) => {
|
||||||
@@ -16,9 +17,13 @@ export function getConnections({ loyalty_page }: LoyaltyPageRefs) {
|
|||||||
break
|
break
|
||||||
case LoyaltyPageEnum.ContentStack.blocks.Content:
|
case LoyaltyPageEnum.ContentStack.blocks.Content:
|
||||||
if (block?.content?.length) {
|
if (block?.content?.length) {
|
||||||
// TS has trouble infering the filtered types
|
block.content.forEach((contentBlock) => {
|
||||||
// @ts-ignore
|
if ("system" in contentBlock) {
|
||||||
connections.push(...block.content)
|
assetConnections.push(contentBlock)
|
||||||
|
} else {
|
||||||
|
connections.push(contentBlock)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case LoyaltyPageEnum.ContentStack.blocks.DynamicContent:
|
case LoyaltyPageEnum.ContentStack.blocks.DynamicContent:
|
||||||
@@ -41,10 +46,14 @@ export function getConnections({ loyalty_page }: LoyaltyPageRefs) {
|
|||||||
loyalty_page.sidebar.forEach((block) => {
|
loyalty_page.sidebar.forEach((block) => {
|
||||||
switch (block?.__typename) {
|
switch (block?.__typename) {
|
||||||
case LoyaltyPageEnum.ContentStack.sidebar.Content:
|
case LoyaltyPageEnum.ContentStack.sidebar.Content:
|
||||||
if (block.content.length) {
|
if (block?.content?.length) {
|
||||||
// TS has trouble infering the filtered types
|
block.content.forEach((contentBlock) => {
|
||||||
// @ts-ignore
|
if ("system" in contentBlock) {
|
||||||
connections.push(...block.content)
|
assetConnections.push(contentBlock)
|
||||||
|
} else {
|
||||||
|
connections.push(contentBlock)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case LoyaltyPageEnum.ContentStack.sidebar.JoinLoyaltyContact:
|
case LoyaltyPageEnum.ContentStack.sidebar.JoinLoyaltyContact:
|
||||||
@@ -59,5 +68,5 @@ export function getConnections({ loyalty_page }: LoyaltyPageRefs) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return connections
|
return { connections, assetConnections }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,44 +2,53 @@ import {
|
|||||||
PromoCampaignPageEnum,
|
PromoCampaignPageEnum,
|
||||||
type PromoCampaignPageRefs,
|
type PromoCampaignPageRefs,
|
||||||
} from "../../../types/promoCampaignPage"
|
} from "../../../types/promoCampaignPage"
|
||||||
import { generateTag, generateTagsFromSystem } from "../../../utils/generateTag"
|
import {
|
||||||
|
generateTag,
|
||||||
|
generateTagsFromAssetSystem,
|
||||||
|
generateTagsFromSystem,
|
||||||
|
} from "../../../utils/generateTag"
|
||||||
|
|
||||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
|
|
||||||
import type { System } from "../schemas/system"
|
import type { AssetSystem, System } from "../schemas/system"
|
||||||
|
|
||||||
export function generatePageTags(
|
export function generatePageTags(
|
||||||
validatedData: PromoCampaignPageRefs,
|
validatedData: PromoCampaignPageRefs,
|
||||||
lang: Lang
|
lang: Lang
|
||||||
): string[] {
|
): string[] {
|
||||||
const connections = getConnections(validatedData)
|
const { connections, assetConnections } = getConnections(validatedData)
|
||||||
return [
|
return [
|
||||||
generateTagsFromSystem(lang, connections),
|
generateTagsFromSystem(lang, connections),
|
||||||
|
generateTagsFromAssetSystem(assetConnections),
|
||||||
generateTag(lang, validatedData.promo_campaign_page.system.uid),
|
generateTag(lang, validatedData.promo_campaign_page.system.uid),
|
||||||
].flat()
|
].flat()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConnections({ promo_campaign_page }: PromoCampaignPageRefs) {
|
export function getConnections({ promo_campaign_page }: PromoCampaignPageRefs) {
|
||||||
const connections: System["system"][] = [promo_campaign_page.system]
|
const connections: System["system"][] = [promo_campaign_page.system]
|
||||||
|
const assetConnections: AssetSystem[] = []
|
||||||
|
|
||||||
if (promo_campaign_page.blocks) {
|
if (promo_campaign_page.blocks) {
|
||||||
promo_campaign_page.blocks.forEach((block) => {
|
promo_campaign_page.blocks.forEach((block) => {
|
||||||
switch (block.__typename) {
|
switch (block.__typename) {
|
||||||
case PromoCampaignPageEnum.ContentStack.blocks.Accordion: {
|
case PromoCampaignPageEnum.ContentStack.blocks.Accordion:
|
||||||
if (block.accordion.length) {
|
if (block.accordion.length) {
|
||||||
connections.push(...block.accordion.filter((c) => !!c))
|
connections.push(...block.accordion.filter((c) => !!c))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
|
||||||
case PromoCampaignPageEnum.ContentStack.blocks.Content:
|
case PromoCampaignPageEnum.ContentStack.blocks.Content:
|
||||||
{
|
if (block?.content?.length) {
|
||||||
if (block?.content?.length) {
|
block.content.forEach((contentBlock) => {
|
||||||
connections.push(...block.content)
|
if ("system" in contentBlock) {
|
||||||
}
|
assetConnections.push(contentBlock)
|
||||||
|
} else {
|
||||||
|
connections.push(contentBlock)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return connections
|
return { connections, assetConnections }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,12 +73,15 @@ export const contentRefsSchema = z.object({
|
|||||||
.nullish()
|
.nullish()
|
||||||
.transform((data) => {
|
.transform((data) => {
|
||||||
return data?.content?.embedded_itemsConnection.edges
|
return data?.content?.embedded_itemsConnection.edges
|
||||||
.filter(({ node }) => node.__typename !== ContentEnum.blocks.SysAsset)
|
|
||||||
.map(({ node }) => {
|
.map(({ node }) => {
|
||||||
if ("system" in node) {
|
switch (node.__typename) {
|
||||||
return node.system
|
case ContentEnum.blocks.SysAsset:
|
||||||
|
return node.system && (node.permanent_url || node.url)
|
||||||
|
? { system: node.system, url: node.permanent_url || node.url }
|
||||||
|
: null
|
||||||
|
default:
|
||||||
|
return node.system
|
||||||
}
|
}
|
||||||
return null
|
|
||||||
})
|
})
|
||||||
.filter((node) => !!node)
|
.filter((node) => !!node)
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import { ContentEnum } from "../../../../types/content"
|
import { ContentEnum } from "../../../../types/content"
|
||||||
|
import { assetSystemSchema } from "../system"
|
||||||
|
|
||||||
// SysAsset is used for several different assets in ContentStack, such as images, pdf-files, etc.
|
// SysAsset is used for several different assets in ContentStack, such as images, pdf-files, etc.
|
||||||
// It is a generic asset type that can represent any file type.
|
// It is a generic asset type that can represent any file type.
|
||||||
@@ -22,15 +23,21 @@ export const sysAssetSchema = z.object({
|
|||||||
// the exact same structure, that's why systemSchema
|
// the exact same structure, that's why systemSchema
|
||||||
// is not used as that correlates to the
|
// is not used as that correlates to the
|
||||||
// EntrySystemField type
|
// EntrySystemField type
|
||||||
system: z
|
system: assetSystemSchema.nullish(),
|
||||||
.object({
|
|
||||||
uid: z.string(),
|
|
||||||
})
|
|
||||||
.nullish(),
|
|
||||||
title: z.string().nullish(),
|
title: z.string().nullish(),
|
||||||
url: z.string().nullish(),
|
url: z.string().nullish(),
|
||||||
|
permanent_url: z
|
||||||
|
.string()
|
||||||
|
.nullish()
|
||||||
|
.transform((val) => (val === "Permanent URL Not Defined!" ? null : val)), // ContentStack returns this string when permanent_url is not defined
|
||||||
})
|
})
|
||||||
|
|
||||||
export const sysAssetRefsSchema = z.object({
|
export const sysAssetRefsSchema = z.object({
|
||||||
__typename: z.literal(ContentEnum.blocks.SysAsset),
|
__typename: z.literal(ContentEnum.blocks.SysAsset),
|
||||||
|
url: z.string().nullish(),
|
||||||
|
permanent_url: z
|
||||||
|
.string()
|
||||||
|
.nullish()
|
||||||
|
.transform((val) => (val === "Permanent URL Not Defined!" ? null : val)), // ContentStack returns this string when permanent_url is not defined
|
||||||
|
system: assetSystemSchema.nullish(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -56,11 +56,6 @@ const actualRefs = z.discriminatedUnion("__typename", [
|
|||||||
...rawLinkRefsUnionSchema.options,
|
...rawLinkRefsUnionSchema.options,
|
||||||
])
|
])
|
||||||
|
|
||||||
type Ref = typeof actualRefs._type
|
|
||||||
type Refs = {
|
|
||||||
node: Ref
|
|
||||||
}
|
|
||||||
|
|
||||||
export const contentRefsSchema = z.object({
|
export const contentRefsSchema = z.object({
|
||||||
content: z
|
content: z
|
||||||
.object({
|
.object({
|
||||||
@@ -78,9 +73,17 @@ export const contentRefsSchema = z.object({
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.transform((data) => {
|
.transform((data) => {
|
||||||
const filtered = data.content.embedded_itemsConnection.edges.filter(
|
return data?.content?.embedded_itemsConnection.edges
|
||||||
(block) => block.node.__typename !== ContentEnum.blocks.SysAsset
|
.map(({ node }) => {
|
||||||
) as unknown as Refs[] // TS issues with filtered arrays
|
switch (node.__typename) {
|
||||||
return filtered.map((block) => block.node.system)
|
case ContentEnum.blocks.SysAsset:
|
||||||
|
return node.system && (node.permanent_url || node.url)
|
||||||
|
? { system: node.system, url: node.permanent_url || node.url }
|
||||||
|
: null
|
||||||
|
default:
|
||||||
|
return node.system
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter((node) => !!node)
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -19,4 +19,6 @@ export const assetSystemSchema = z.object({
|
|||||||
|
|
||||||
export interface AssetSystem {
|
export interface AssetSystem {
|
||||||
system: z.output<typeof assetSystemSchema>
|
system: z.output<typeof assetSystemSchema>
|
||||||
|
url?: string | null
|
||||||
|
permanent_url?: string | null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ export const videoRefSchema = z.object({
|
|||||||
z.object({
|
z.object({
|
||||||
node: z.object({
|
node: z.object({
|
||||||
system: assetSystemSchema,
|
system: assetSystemSchema,
|
||||||
|
url: z.string(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
generateTagsFromSystem,
|
generateTagsFromSystem,
|
||||||
} from "../../../utils/generateTag"
|
} from "../../../utils/generateTag"
|
||||||
import { startPageRefsSchema, startPageSchema } from "./output"
|
import { startPageRefsSchema, startPageSchema } from "./output"
|
||||||
import { getConnections, getConnectionsFromAssets } from "./utils"
|
import { getConnections } from "./utils"
|
||||||
|
|
||||||
import type { z } from "zod"
|
import type { z } from "zod"
|
||||||
|
|
||||||
@@ -75,8 +75,9 @@ export const startPageQueryRouter = router({
|
|||||||
|
|
||||||
metricsGetStartPage.start()
|
metricsGetStartPage.start()
|
||||||
|
|
||||||
const connections = getConnections(validatedRefsData.data)
|
const { connections, assetConnections } = getConnections(
|
||||||
const assetConnections = getConnectionsFromAssets(validatedRefsData.data)
|
validatedRefsData.data
|
||||||
|
)
|
||||||
|
|
||||||
const tags = [
|
const tags = [
|
||||||
generateTagsFromSystem(lang, connections),
|
generateTagsFromSystem(lang, connections),
|
||||||
|
|||||||
@@ -17,29 +17,9 @@ export namespace StartPageEnum {
|
|||||||
|
|
||||||
export interface StartPageRefs extends z.output<typeof startPageRefsSchema> {}
|
export interface StartPageRefs extends z.output<typeof startPageRefsSchema> {}
|
||||||
|
|
||||||
export function getConnectionsFromAssets({ start_page }: StartPageRefs) {
|
|
||||||
const connections: AssetSystem["system"][] = []
|
|
||||||
|
|
||||||
if (start_page.blocks) {
|
|
||||||
start_page.blocks.forEach((block) => {
|
|
||||||
switch (block.__typename) {
|
|
||||||
case StartPageEnum.ContentStack.blocks.VideoCard:
|
|
||||||
if (block.video_card?.video.sourceConnection.edges[0]) {
|
|
||||||
connections.push(
|
|
||||||
block.video_card.video.sourceConnection.edges[0].node.system
|
|
||||||
)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return connections
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getConnections({ start_page }: StartPageRefs) {
|
export function getConnections({ start_page }: StartPageRefs) {
|
||||||
const connections: System["system"][] = [start_page.system]
|
const connections: System["system"][] = [start_page.system]
|
||||||
|
const assetConnections: AssetSystem[] = []
|
||||||
|
|
||||||
if (start_page.blocks) {
|
if (start_page.blocks) {
|
||||||
start_page.blocks.forEach((block) => {
|
start_page.blocks.forEach((block) => {
|
||||||
@@ -75,6 +55,11 @@ export function getConnections({ start_page }: StartPageRefs) {
|
|||||||
if (block.video_card?.system) {
|
if (block.video_card?.system) {
|
||||||
connections.push(block.video_card.system)
|
connections.push(block.video_card.system)
|
||||||
}
|
}
|
||||||
|
if (block.video_card?.video.sourceConnection.edges[0]) {
|
||||||
|
assetConnections.push(
|
||||||
|
block.video_card.video.sourceConnection.edges[0].node
|
||||||
|
)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -84,5 +69,5 @@ export function getConnections({ start_page }: StartPageRefs) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return connections
|
return { connections, assetConnections }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,11 +88,15 @@ export function generateTagsFromSystem(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateTagsFromAssetSystem(
|
export function generateTagsFromAssetSystem(connections: AssetSystem[]) {
|
||||||
connections: AssetSystem["system"][]
|
return connections.map(({ system, url, permanent_url }) => {
|
||||||
) {
|
let affix = system.uid
|
||||||
return connections.map((system) => {
|
|
||||||
return generateTag(Lang.en, system.content_type_uid, system.uid)
|
if (permanent_url || url) {
|
||||||
|
affix += `:${permanent_url || url}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return generateTag(Lang.en, system.content_type_uid, affix)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user