@financial-times/cp-content-pipeline-schema 1.3.4 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,32 @@
1
1
  import { uuidFromUrl } from '../../../helpers/metadata'
2
2
  import { RecommendedResolvers } from '../../../generated'
3
+ import { logRecoverableError } from '@dotcom-reliability-kit/log-error'
4
+ import { OperationalError } from '@dotcom-reliability-kit/errors'
3
5
 
4
6
  export const Recommended = {
5
7
  async teaser(parent, _args, context) {
6
- let content = await context.dataSources.capi.getContent(
7
- uuidFromUrl(parent.reference.id)
8
- )
8
+ try {
9
+ let content = await context.dataSources.capi.getContent(
10
+ uuidFromUrl(parent.reference.id)
11
+ )
9
12
 
10
- if (parent.reference.teaserTitleOverride) {
11
- content = content.overrideTitle(parent.reference.teaserTitleOverride)
13
+ if (parent.reference.teaserTitleOverride) {
14
+ content = content.overrideTitle(parent.reference.teaserTitleOverride)
15
+ }
16
+ return content
17
+ } catch (error) {
18
+ if (error instanceof Error) {
19
+ logRecoverableError({
20
+ logger: context.logger,
21
+ error: new OperationalError({
22
+ code: 'RECOMMENDED_TEASER_ERROR',
23
+ message: `Couldn't load teaser for recommended article ${parent.reference.id}`,
24
+ cause: error,
25
+ }),
26
+ })
27
+ }
28
+
29
+ return null
12
30
  }
13
- return content
14
31
  },
15
32
  } satisfies RecommendedResolvers
@@ -18,6 +18,7 @@ import {
18
18
 
19
19
  import * as scrollytelling from '@financial-times/n-scrollytelling-image/server'
20
20
  import { LiteralToPrimitiveDeep } from 'type-fest'
21
+ import { CapiResponse } from '../../model/CapiResponse'
21
22
 
22
23
  const tableResponsiveStyleMap: Record<string, Table['responsiveStyle']> = {
23
24
  stacked: 'flat',
@@ -79,10 +80,10 @@ const validScrollytellingOption = <
79
80
  : false
80
81
  }
81
82
 
82
- const articleTagMappings: TagMappings = {
83
+ const articleTagMappings = (capiData?: CapiResponse): TagMappings => ({
83
84
  'body > ft-content[type="http://www.ft.com/ontology/content/ImageSet"]:first-child':
84
85
  ($el) => ({
85
- type: 'main-image',
86
+ type: capiData?.topperHasImage() ? 'image-set' : 'main-image',
86
87
  id: $el.attr('url') || '',
87
88
  }),
88
89
  'body > ft-content[type="http://www.ft.com/ontology/content/ImageSet"]:not(:first-child),:not(body) > ft-content[type="http://www.ft.com/ontology/content/ImageSet"]':
@@ -90,7 +91,7 @@ const articleTagMappings: TagMappings = {
90
91
  type: 'image-set',
91
92
  id: $el.attr('url') || '',
92
93
  }),
93
- }
94
+ })
94
95
 
95
96
  const liveBlogPostTagMappings: TagMappings = {
96
97
  'body > ft-content[type="http://www.ft.com/ontology/content/ImageSet"]': (
@@ -152,6 +153,33 @@ const commonTagMappings: TagMappings = {
152
153
  type: 'tweet',
153
154
  id: $el.attr('href') || '',
154
155
  }),
156
+
157
+ 'scrollable-text > p,h1,h2': ($el, traverse, context) => {
158
+ const textStyle = $el.attr('theme-style')
159
+
160
+ if (validScrollytellingOption('textStyle', textStyle)) {
161
+ return {
162
+ type: 'scrolly-heading',
163
+ level: scrollytellingOptionsToContentTree.textStyle[textStyle],
164
+ children: everyChildIsType(
165
+ 'text',
166
+ traverse(),
167
+ 'scrolly-heading',
168
+ context
169
+ ),
170
+ }
171
+ }
172
+
173
+ return {
174
+ type: 'paragraph',
175
+ children: childrenOfTypes(
176
+ phrasingTypes,
177
+ traverse(),
178
+ 'paragraph',
179
+ context
180
+ ),
181
+ }
182
+ },
155
183
  h1: ($el, traverse, context) => ({
156
184
  type: 'heading',
157
185
  level: 'chapter',
@@ -552,33 +580,6 @@ const commonTagMappings: TagMappings = {
552
580
  ),
553
581
  }),
554
582
 
555
- 'scrollable-text > p': ($el, traverse, context) => {
556
- const textStyle = $el.attr('theme-style')
557
-
558
- if (validScrollytellingOption('textStyle', textStyle)) {
559
- return {
560
- type: 'scrolly-heading',
561
- level: scrollytellingOptionsToContentTree.textStyle[textStyle],
562
- children: everyChildIsType(
563
- 'text',
564
- traverse(),
565
- 'scrolly-heading',
566
- context
567
- ),
568
- }
569
- }
570
-
571
- return {
572
- type: 'paragraph',
573
- children: childrenOfTypes(
574
- phrasingTypes,
575
- traverse(),
576
- 'paragraph',
577
- context
578
- ),
579
- }
580
- },
581
-
582
583
  // HACK:KB:20230703 needs to come after `scrollable-text > p`. todo sort by specificity
583
584
  p: ($el, traverse, context) => ({
584
585
  type: 'paragraph',