Feat/BOOK-240 hero video
Approved-by: Chuma Mcphoy (We Ahead) Approved-by: Christel Westerberg
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
} from "../schemas/linkConnection"
|
||||
import { internalOrExternalLinkSchema } from "../schemas/pageLinks"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
import { transformedVideoSchema, videoRefSchema } from "../schemas/video"
|
||||
|
||||
// Block schemas
|
||||
export const collectionPageCards = z
|
||||
@@ -78,6 +79,7 @@ const navigationLinksSchema = z
|
||||
export const collectionPageSchema = z.object({
|
||||
collection_page: z.object({
|
||||
hero_image: transformedImageVaultAssetSchema,
|
||||
hero_video: transformedVideoSchema,
|
||||
blocks: discriminatedUnionArray(blocksSchema.options).nullable(),
|
||||
title: z.string(),
|
||||
header: z.object({
|
||||
@@ -145,6 +147,7 @@ const collectionPageHeaderRefs = z.object({
|
||||
|
||||
export const collectionPageRefsSchema = z.object({
|
||||
collection_page: z.object({
|
||||
hero_video: videoRefSchema.nullish(),
|
||||
header: collectionPageHeaderRefs,
|
||||
blocks: discriminatedUnionArray(
|
||||
collectionPageBlockRefsItem.options
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import {
|
||||
generateRefsResponseTag,
|
||||
generateTag,
|
||||
generateTagsFromAssetSystem,
|
||||
generateTagsFromSystem,
|
||||
} from "../../../utils/generateTag"
|
||||
import { collectionPageRefsSchema } from "./output"
|
||||
@@ -84,6 +85,7 @@ export function generatePageTags(
|
||||
const connections = getConnections(validatedData)
|
||||
return [
|
||||
generateTagsFromSystem(lang, connections),
|
||||
generateTagsFromAssetSystem(connections),
|
||||
generateTag(lang, validatedData.collection_page.system.uid),
|
||||
].flat()
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ import {
|
||||
teaserCardsSchema,
|
||||
} from "../schemas/sidebar/teaserCard"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
import { transformedVideoSchema, videoRefSchema } from "../schemas/video"
|
||||
|
||||
// Block schemas
|
||||
export const contentPageCards = z
|
||||
@@ -194,6 +195,7 @@ const navigationLinksSchema = z
|
||||
export const contentPageSchema = z.object({
|
||||
content_page: z.object({
|
||||
hero_image: transformedImageVaultAssetSchema,
|
||||
hero_video: transformedVideoSchema,
|
||||
blocks: discriminatedUnionArray(blocksSchema.options).nullable(),
|
||||
sidebar: discriminatedUnionArray(sidebarSchema.options).nullable(),
|
||||
title: z.string(),
|
||||
@@ -323,6 +325,7 @@ const contentPageHeaderRefs = z.object({
|
||||
|
||||
export const contentPageRefsSchema = z.object({
|
||||
content_page: z.object({
|
||||
hero_video: videoRefSchema.nullish(),
|
||||
header: contentPageHeaderRefs,
|
||||
blocks: discriminatedUnionArray(
|
||||
contentPageBlockRefsItem.options
|
||||
|
||||
@@ -10,6 +10,7 @@ import { ContentPageEnum } from "../../../types/contentPage"
|
||||
import {
|
||||
generateRefsResponseTag,
|
||||
generateTag,
|
||||
generateTagsFromAssetSystem,
|
||||
generateTagsFromSystem,
|
||||
} from "../../../utils/generateTag"
|
||||
import { contentPageRefsSchema } from "./output"
|
||||
@@ -75,12 +76,14 @@ export function generatePageTags(
|
||||
const connections = getConnections(validatedData)
|
||||
return [
|
||||
generateTagsFromSystem(lang, connections),
|
||||
generateTagsFromAssetSystem(connections),
|
||||
generateTag(lang, validatedData.content_page.system.uid),
|
||||
].flat()
|
||||
}
|
||||
|
||||
export function getConnections({ content_page }: ContentPageRefs) {
|
||||
const connections: System["system"][] = [content_page.system]
|
||||
|
||||
if (content_page.blocks) {
|
||||
content_page.blocks.forEach((block) => {
|
||||
switch (block.__typename) {
|
||||
|
||||
@@ -11,3 +11,12 @@ export const systemSchema = z.object({
|
||||
export interface System {
|
||||
system: z.output<typeof systemSchema>
|
||||
}
|
||||
|
||||
export const assetSystemSchema = z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
})
|
||||
|
||||
export interface AssetSystem {
|
||||
system: z.output<typeof assetSystemSchema>
|
||||
}
|
||||
|
||||
75
packages/trpc/lib/routers/contentstack/schemas/video.ts
Normal file
75
packages/trpc/lib/routers/contentstack/schemas/video.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { focalPointSchema } from "@scandic-hotels/common/utils/focalPoint"
|
||||
|
||||
import { assetSystemSchema } from "./system"
|
||||
|
||||
export const videoSchema = z.object({
|
||||
sourceConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
url: z.string().url(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
focal_point: focalPointSchema.nullish(),
|
||||
captions: z.array(
|
||||
z.object({
|
||||
is_default: z.boolean(),
|
||||
fileConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
url: z.string().url(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
language: z.nativeEnum(Lang),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export const transformedVideoSchema = videoSchema
|
||||
.nullish()
|
||||
.transform((video) => {
|
||||
const src = video?.sourceConnection.edges[0]?.node.url || ""
|
||||
|
||||
if (!video || !src) {
|
||||
return null
|
||||
}
|
||||
|
||||
const captions = video.captions
|
||||
.filter((caption) => caption.fileConnection.edges[0]?.node.url)
|
||||
.map((caption) => ({
|
||||
src: caption.fileConnection.edges[0]?.node.url || "",
|
||||
srcLang: caption.language,
|
||||
isDefault: caption.is_default,
|
||||
}))
|
||||
|
||||
return {
|
||||
src,
|
||||
focalPoint: video.focal_point
|
||||
? { x: video.focal_point.x, y: video.focal_point.y }
|
||||
: { x: 50, y: 50 },
|
||||
captions,
|
||||
}
|
||||
})
|
||||
|
||||
export const videoRefSchema = z.object({
|
||||
sourceConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: assetSystemSchema,
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
|
||||
export type Video = z.output<typeof transformedVideoSchema>
|
||||
export type VideoCaptions = NonNullable<Video>["captions"]
|
||||
Reference in New Issue
Block a user