Skip to content

Commit

Permalink
Revert "✨ Add factboxes and accordion items to index #1864"
Browse files Browse the repository at this point in the history
This reverts commit d316f44.
  • Loading branch information
fernandolucchesi authored Nov 3, 2023
1 parent 1d965ec commit 3096715
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 284 deletions.
58 changes: 0 additions & 58 deletions search/IndexSanityContent/common/mappers.ts

This file was deleted.

5 changes: 0 additions & 5 deletions search/IndexSanityContent/common/news/SharedNewsFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,5 @@ export type SharedNewsFields = Page & {
text: string
}[]
}[]
factboxes: {
blockKey: string
title: string
text: string
}[]
_id: string
}
7 changes: 3 additions & 4 deletions search/IndexSanityContent/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AzureFunction, Context, HttpRequest } from '@azure/functions'
// eslint-disable-next-line import/no-named-as-default
import { dotenv } from 'dotenv-azure'
import DotenvAzure from 'dotenv-azure'
import { indexEvents } from './events'
import { indexTopic } from './topic'
import { indexNews } from './news'
Expand All @@ -25,11 +25,10 @@ const indexTasks: {
}

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
/* await new DotenvAzure().config({
await new DotenvAzure().config({
allowEmptyValues: true,
debug: false,
})*/
await dotenv.config()
})

const logger = context.log
const language = pipe(languageFromIso(req.body.language), languageOrDefault)
Expand Down
37 changes: 2 additions & 35 deletions search/IndexSanityContent/localNews/mapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,16 @@ describe('Local News', () => {
],
},
],
factboxes: [
{
blockKey: 'factboxkey',
title: 'Facts',
text: 'Factbox text',
},
],
}

const sut = mapData
const result = sut(newsArticle)

it('contains one entry', () => {
expect(result).toHaveLength(2)
expect(result).toHaveLength(1)
})

it('entry looks as expected', () => {
expect(result[1]).toEqual({
slug: '/a/slug',
objectID: 'id-factboxkey',
pageTitle: 'title',
ingress: 'ingress',
type: 'localNews',
text: 'Facts\nFactbox text',
publishDateTime: '2021-11-26T07:00:00.000Z',
year: 2021,
localNewsTag: 'Germany',
} as NewsIndex)

expect(result[0]).toEqual({
slug: '/a/slug',
objectID: 'id-blockKey-childKey',
Expand Down Expand Up @@ -105,25 +86,13 @@ describe('Local News', () => {
],
},
],
factboxes: [
{
blockKey: 'factboxkey',
title: 'Facts',
text: 'Factbox text',
},
{
blockKey: 'factboxkey1',
title: 'Facts1',
text: 'Factbox text1',
},
],
}

const sut = mapData
const result = sut(newsArticle)

it('contains one entry', () => {
expect(result).toHaveLength(6)
expect(result).toHaveLength(4)
})

it('entry looks as expected', () => {
Expand Down Expand Up @@ -187,7 +156,6 @@ describe('Local News', () => {
children: [],
},
],
factboxes: [],
}

const sut = mapData
Expand All @@ -206,7 +174,6 @@ describe('Local News', () => {
localNewsTag: 'USA',
_id: 'id',
blocks: [],
factboxes: [],
}

const sut = mapData
Expand Down
18 changes: 1 addition & 17 deletions search/IndexSanityContent/localNews/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { LocalNewsArticle } from './sanity'

type MapDataType = (article: LocalNewsArticle) => NewsIndex[]
export const mapData: MapDataType = (article) => {
const { publishDateTime, localNewsTag, title, ingress, slug, factboxes } = article
const { publishDateTime, localNewsTag, title, ingress, slug } = article
// Hu hei hvor det går
const year = publishDateTime ? new Date(publishDateTime).getFullYear() : ''
return pipe(
Expand All @@ -25,21 +25,5 @@ export const mapData: MapDataType = (article) => {
year,
} as NewsIndex),
),
A.concat(
factboxes.map(
(factbox) =>
({
slug,
objectID: `${article._id}-${factbox.blockKey}`,
type: 'localNews',
pageTitle: title,
ingress,
text: factbox.title + ': ' + factbox.text,
publishDateTime: publishDateTime,
localNewsTag,
year,
} as NewsIndex),
),
),
)
}
5 changes: 0 additions & 5 deletions search/IndexSanityContent/localNews/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ export const query = /* groq */ `*[_type == "localNews" && _lang == $lang && !(_
"text": text
}
},
"factboxes": content[_type == "factbox"] {
"blockKey": _key,
title,
"text": pt::text(content)
},
"docToClear": _id match $id
}
`
Expand Down
90 changes: 65 additions & 25 deletions search/IndexSanityContent/magazine/mapper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { pipe } from 'fp-ts/lib/function'
import { ap } from 'fp-ts/lib/Identity'
import * as A from 'fp-ts/lib/Array'
import * as O from 'fp-ts/lib/Option'
import { ImageWithAlt, MagazineArticle } from './sanity'
import { AccordionIndex, MagazineIndex, TextBlockIndex } from '../../common'
import { mappedAccordions, mappedTextBlocks } from '../common/mappers'
import { MagazineIndex } from '../../common'
import type { ImageWithAltAndCaption } from './sanity'

type MappableObjectType = {
_key: string
title: string
ingress: string
text: string
magazineTags?: string[]
heroFigure?: ImageWithAltAndCaption
publishDateTime?: string
}

type MapperFunctionType = (article: MagazineArticle) => (obj: MappableObjectType) => MagazineIndex

const getHeroImage = (article: MagazineArticle): ImageWithAlt | null => {
if (article?.heroFigure?.image?.asset) {
Expand All @@ -17,28 +30,55 @@ const getHeroImage = (article: MagazineArticle): ImageWithAlt | null => {
return null
}

type MapDataType = (article: MagazineArticle) => MagazineIndex[]
type ContentsDataType = (page: MagazineArticle) => AccordionIndex[] | TextBlockIndex[]
const mapperFunction: MapperFunctionType =
(article) =>
({ _key, title, ingress, text }) => ({
slug: article.slug,
objectID: `${article._id}-${_key}`,
documentID: article._id,
type: 'magazine',
pageTitle: article.title,
title,
ingress,
text,
magazineTags: article.magazineTags,
heroImage: getHeroImage(article),
publishDateTime: article.publishDateTime,
})

const contents: ContentsDataType = (page) => pipe(page, mappedAccordions, A.concat(mappedTextBlocks(page)))
export const mapData: MapDataType = (article: MagazineArticle) =>
pipe(
article,
contents,
O.fromNullable,
O.map((items) => {
return items.map((it) => {
return {
slug: article.slug,
documentID: article._id,
type: 'magazine',
pageTitle: article.title,
magazineTags: article.magazineTags,
heroImage: getHeroImage(article),
publishDateTime: article.publishDateTime,
...it,
} as unknown as MagazineIndex
})
}),
O.getOrElse(() => [] as MagazineIndex[]),
type MapDataType = (article: MagazineArticle) => MagazineIndex[]
export const mapData: MapDataType = (article) =>
pipe(mapperFunction, ap(article), (fn) =>
pipe(
pipe(
O.fromNullable(article.textBlocks),
O.map(A.map(fn)),
O.getOrElse(() => [] as MagazineIndex[]),
),
A.concat(
pipe(
O.fromNullable(article.accordions),
O.map(A.map(fn)),
O.getOrElse(() => [] as MagazineIndex[]),
),
),
A.concat(
pipe(
O.fromNullable(
article.ingress
? Array.of({
_key: `ingress`,
type: 'magazine',
pageTitle: article.title,
title: null,
ingress: article.ingress,
text: null,
} as unknown as MappableObjectType)
: null,
),
O.map(A.map(fn)),
O.getOrElse(() => [] as MagazineIndex[]),
),
),
),
)
16 changes: 12 additions & 4 deletions search/IndexSanityContent/magazine/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as TE from 'fp-ts/lib/TaskEither'
import { pipe } from 'fp-ts/lib/function'
import { SanityClient } from '@sanity/client'
import { Language } from '../../common'
import { MappableAccordionType, MappableTextBlockType } from '../common/mappers'

export enum HeroTypes {
DEFAULT = 'default',
Expand Down Expand Up @@ -91,9 +90,18 @@ export type MagazineArticle = {
slug: string
title: string
ingress: string
type: string
textBlocks: MappableTextBlockType[]
accordions: MappableAccordionType[]
textBlocks: {
_key: string
title: string
ingress: string
text: string
}[]
accordions: {
_key: string
title: string
ingress: string
text: string
}[]
_id: string
magazineTags?: string[]
heroFigure?: { image: ImageWithAlt } | ImageWithAltAndCaption
Expand Down
Loading

0 comments on commit 3096715

Please sign in to comment.