Skip to content

Commit

Permalink
✨ Index news hero image #2433
Browse files Browse the repository at this point in the history
  • Loading branch information
padms committed Aug 8, 2024
1 parent dce7a69 commit 6a11ba1
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 33 deletions.
2 changes: 2 additions & 0 deletions search/IndexSanityContent/common/news/SharedNewsFields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Page } from '../../../common'
import { ImageWithAltAndCaption } from '../types'

export type SharedNewsFields = Page & {
title: string
Expand All @@ -18,4 +19,5 @@ export type SharedNewsFields = Page & {
text: string
}[]
_id: string
heroImage?: ImageWithAltAndCaption
}
30 changes: 30 additions & 0 deletions search/IndexSanityContent/common/types.ts
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions search/IndexSanityContent/localNews/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const query = /* groq */ `*[_type == "localNews" && lang == $lang && !(_i
title,
"text": pt::text(content)
},
heroImage,
"docToClear": _id match $id
}
`
Expand Down
3 changes: 2 additions & 1 deletion search/IndexSanityContent/magazine/mapper.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
32 changes: 1 addition & 31 deletions search/IndexSanityContent/magazine/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion search/IndexSanityContent/news/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -24,6 +24,7 @@ export const mapData: MapDataType = (article) => {
topicTags,
countryTags,
year,
heroImage,
} as NewsIndex),
),
A.concat(
Expand All @@ -40,6 +41,7 @@ export const mapData: MapDataType = (article) => {
topicTags,
countryTags,
year,
heroImage,
} as NewsIndex),
),
),
Expand Down
1 change: 1 addition & 0 deletions search/IndexSanityContent/news/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const query = /* groq */ `*[_type == "news" && lang == $lang && !(_id in
title,
"text": pt::text(content)
},
heroImage,
"docToClear": _id match $id
}
`
Expand Down
1 change: 1 addition & 0 deletions search/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type NewsIndex = {
countryTags: string[]
thumbnailUrl: string
localNewsTag: string
heroImage: object
}

export type MagazineIndex = {
Expand Down

0 comments on commit 6a11ba1

Please sign in to comment.