From 6a11ba13026e3dcd5e2d9e974c567e75bcb0355f Mon Sep 17 00:00:00 2001 From: Padmaja <52911293+padms@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:33:57 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Index=20news=20hero=20image=20#2433?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/news/SharedNewsFields.ts | 2 ++ search/IndexSanityContent/common/types.ts | 30 +++++++++++++++++ search/IndexSanityContent/localNews/sanity.ts | 1 + search/IndexSanityContent/magazine/mapper.ts | 3 +- search/IndexSanityContent/magazine/sanity.ts | 32 +------------------ search/IndexSanityContent/news/mapper.ts | 4 ++- search/IndexSanityContent/news/sanity.ts | 1 + search/common/types.ts | 1 + 8 files changed, 41 insertions(+), 33 deletions(-) create mode 100644 search/IndexSanityContent/common/types.ts diff --git a/search/IndexSanityContent/common/news/SharedNewsFields.ts b/search/IndexSanityContent/common/news/SharedNewsFields.ts index d780ddf23..d51341ca7 100644 --- a/search/IndexSanityContent/common/news/SharedNewsFields.ts +++ b/search/IndexSanityContent/common/news/SharedNewsFields.ts @@ -1,4 +1,5 @@ import { Page } from '../../../common' +import { ImageWithAltAndCaption } from '../types' export type SharedNewsFields = Page & { title: string @@ -18,4 +19,5 @@ export type SharedNewsFields = Page & { text: string }[] _id: string + heroImage?: ImageWithAltAndCaption } diff --git a/search/IndexSanityContent/common/types.ts b/search/IndexSanityContent/common/types.ts new file mode 100644 index 000000000..b09a62f06 --- /dev/null +++ b/search/IndexSanityContent/common/types.ts @@ -0,0 +1,30 @@ +export type ImageWithAlt = { + _type: 'imageWithAlt' + alt: string + isDecorative?: boolean + asset: { + _ref: string + _type: 'reference' + } + crop?: { + _type: 'sanity.imageCrop' + bottom: number + left: number + right: number + top: number + } + hotspot?: { + _type: 'sanity.imageHotspot' + height: number + width: number + x: number + y: number + } +} + +export type ImageWithAltAndCaption = { + _type: 'imageWithAltAndCaption' + attribution?: string + caption?: string + image: ImageWithAlt +} diff --git a/search/IndexSanityContent/localNews/sanity.ts b/search/IndexSanityContent/localNews/sanity.ts index e33d744d7..9bdbdcd45 100644 --- a/search/IndexSanityContent/localNews/sanity.ts +++ b/search/IndexSanityContent/localNews/sanity.ts @@ -33,6 +33,7 @@ export const query = /* groq */ `*[_type == "localNews" && lang == $lang && !(_i title, "text": pt::text(content) }, + heroImage, "docToClear": _id match $id } ` diff --git a/search/IndexSanityContent/magazine/mapper.ts b/search/IndexSanityContent/magazine/mapper.ts index d171c1f33..0a9288cef 100644 --- a/search/IndexSanityContent/magazine/mapper.ts +++ b/search/IndexSanityContent/magazine/mapper.ts @@ -1,9 +1,10 @@ import { pipe } from 'fp-ts/lib/function' import * as A from 'fp-ts/lib/Array' import * as O from 'fp-ts/lib/Option' -import { ImageWithAlt, MagazineArticle } from './sanity' +import { MagazineArticle } from './sanity' import { AccordionIndex, MagazineIndex, TextBlockIndex } from '../../common' import { mappedAccordions, mappedTextBlocks } from '../common/mappers' +import { ImageWithAlt } from '../common/types' const getHeroImage = (article: MagazineArticle): ImageWithAlt | null => { if (article?.heroFigure?.image?.asset) { diff --git a/search/IndexSanityContent/magazine/sanity.ts b/search/IndexSanityContent/magazine/sanity.ts index 9f8425744..6da06254e 100644 --- a/search/IndexSanityContent/magazine/sanity.ts +++ b/search/IndexSanityContent/magazine/sanity.ts @@ -5,6 +5,7 @@ import { SanityClient } from '@sanity/client' import { Language } from '../../common' import { MappableAccordionType, MappableTextBlockType } from '../common/mappers' import { plainTextExcludingStrikeThrough } from '../../common/queryHelpers' +import { ImageWithAlt, ImageWithAltAndCaption } from '../common/types' export enum HeroTypes { DEFAULT = 'default', @@ -62,37 +63,6 @@ const getQueryParams = (language: Language, id: string) => ({ id: id, }) -export type ImageWithAlt = { - _type: 'imageWithAlt' - alt: string - isDecorative?: boolean - asset: { - _ref: string - _type: 'reference' - } - crop?: { - _type: 'sanity.imageCrop' - bottom: number - left: number - right: number - top: number - } - hotspot?: { - _type: 'sanity.imageHotspot' - height: number - width: number - x: number - y: number - } -} - -export type ImageWithAltAndCaption = { - _type: 'imageWithAltAndCaption' - attribution?: string - caption?: string - image: ImageWithAlt -} - export type MagazineArticle = { slug: string title: string diff --git a/search/IndexSanityContent/news/mapper.ts b/search/IndexSanityContent/news/mapper.ts index 81633608a..5d8daf60e 100644 --- a/search/IndexSanityContent/news/mapper.ts +++ b/search/IndexSanityContent/news/mapper.ts @@ -5,7 +5,7 @@ import type { NewsArticle } from './sanity' type MapDataType = (article: NewsArticle) => NewsIndex[] export const mapData: MapDataType = (article) => { - const { publishDateTime, topicTags, countryTags, title, ingress, slug, factboxes } = article + const { publishDateTime, topicTags, countryTags, title, ingress, slug, factboxes, heroImage } = article // Hu hei hvor det går const year = publishDateTime ? new Date(publishDateTime).getFullYear() : '' return pipe( @@ -24,6 +24,7 @@ export const mapData: MapDataType = (article) => { topicTags, countryTags, year, + heroImage, } as NewsIndex), ), A.concat( @@ -40,6 +41,7 @@ export const mapData: MapDataType = (article) => { topicTags, countryTags, year, + heroImage, } as NewsIndex), ), ), diff --git a/search/IndexSanityContent/news/sanity.ts b/search/IndexSanityContent/news/sanity.ts index 5e1aec631..e5fea6def 100644 --- a/search/IndexSanityContent/news/sanity.ts +++ b/search/IndexSanityContent/news/sanity.ts @@ -34,6 +34,7 @@ export const query = /* groq */ `*[_type == "news" && lang == $lang && !(_id in title, "text": pt::text(content) }, + heroImage, "docToClear": _id match $id } ` diff --git a/search/common/types.ts b/search/common/types.ts index 2d072a696..2fa403899 100644 --- a/search/common/types.ts +++ b/search/common/types.ts @@ -58,6 +58,7 @@ export type NewsIndex = { countryTags: string[] thumbnailUrl: string localNewsTag: string + heroImage: object } export type MagazineIndex = {