Skip to content

Commit 4a98ce9

Browse files
Merge pull request #103 from Financial-Times/CI-3004-add-identifier-to-certain-blocks-only
Ci 3004 add identifier to certain blocks only
2 parents 1e271e9 + 5163bb8 commit 4a98ce9

File tree

7 files changed

+70
-13
lines changed

7 files changed

+70
-13
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ interface Heading extends Parent {
246246
type: "heading"
247247
children: Text[]
248248
level: "chapter" | "subheading" | "label"
249+
blockIdentifier?: string
249250
}
250251
```
251252

@@ -355,6 +356,7 @@ interface ImageSet extends Node {
355356
type: "image-set"
356357
id: string
357358
external picture: ImageSetPicture
359+
blockIdentifier?: string
358360
}
359361
```
360362

@@ -513,6 +515,7 @@ interface Flourish extends Node {
513515
description?: string
514516
timestamp?: string
515517
external fallbackImage?: Image
518+
blockIdentifier?: string
516519
}
517520
```
518521

content-tree.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export declare namespace ContentTree {
3636
type: "heading";
3737
children: Text[];
3838
level: "chapter" | "subheading" | "label";
39+
blockIdentifier?: string;
3940
}
4041
interface Strong extends Parent {
4142
type: "strong";
@@ -77,6 +78,7 @@ export declare namespace ContentTree {
7778
type: "image-set";
7879
id: string;
7980
picture: ImageSetPicture;
81+
blockIdentifier?: string;
8082
}
8183
type ImageSetPicture = {
8284
layoutWidth: string;
@@ -156,6 +158,7 @@ export declare namespace ContentTree {
156158
description?: string;
157159
timestamp?: string;
158160
fallbackImage?: Image;
161+
blockIdentifier?: string;
159162
}
160163
interface BigNumber extends Node {
161164
type: "big-number";
@@ -311,6 +314,7 @@ export declare namespace ContentTree {
311314
type: "heading";
312315
children: Text[];
313316
level: "chapter" | "subheading" | "label";
317+
blockIdentifier?: string;
314318
}
315319
interface Strong extends Parent {
316320
type: "strong";
@@ -352,6 +356,7 @@ export declare namespace ContentTree {
352356
type: "image-set";
353357
id: string;
354358
picture: ImageSetPicture;
359+
blockIdentifier?: string;
355360
}
356361
type ImageSetPicture = {
357362
layoutWidth: string;
@@ -431,6 +436,7 @@ export declare namespace ContentTree {
431436
description?: string;
432437
timestamp?: string;
433438
fallbackImage?: Image;
439+
blockIdentifier?: string;
434440
}
435441
interface BigNumber extends Node {
436442
type: "big-number";
@@ -587,6 +593,7 @@ export declare namespace ContentTree {
587593
type: "heading";
588594
children: Text[];
589595
level: "chapter" | "subheading" | "label";
596+
blockIdentifier?: string;
590597
}
591598
interface Strong extends Parent {
592599
type: "strong";
@@ -627,6 +634,7 @@ export declare namespace ContentTree {
627634
interface ImageSet extends Node {
628635
type: "image-set";
629636
id: string;
637+
blockIdentifier?: string;
630638
}
631639
type ImageSetPicture = {
632640
layoutWidth: string;
@@ -703,6 +711,7 @@ export declare namespace ContentTree {
703711
flourishType: string;
704712
description?: string;
705713
timestamp?: string;
714+
blockIdentifier?: string;
706715
}
707716
interface BigNumber extends Node {
708717
type: "big-number";
@@ -848,6 +857,7 @@ export declare namespace ContentTree {
848857
type: "heading";
849858
children: Text[];
850859
level: "chapter" | "subheading" | "label";
860+
blockIdentifier?: string;
851861
}
852862
interface Strong extends Parent {
853863
type: "strong";
@@ -889,6 +899,7 @@ export declare namespace ContentTree {
889899
type: "image-set";
890900
id: string;
891901
picture?: ImageSetPicture;
902+
blockIdentifier?: string;
892903
}
893904
type ImageSetPicture = {
894905
layoutWidth: string;
@@ -968,6 +979,7 @@ export declare namespace ContentTree {
968979
description?: string;
969980
timestamp?: string;
970981
fallbackImage?: Image;
982+
blockIdentifier?: string;
971983
}
972984
interface BigNumber extends Node {
973985
type: "big-number";

content_tree.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ type ColumnSettingsItems struct {
103103

104104
type BigNumber struct {
105105
Type string `json:"type"`
106-
Data interface{} `json:"data,omitempty"`
106+
Data interface{} `json:"data,omitempty"`
107107
Description string `json:"description,omitempty"`
108108
Number string `json:"number,omitempty"`
109109
}
@@ -586,14 +586,15 @@ func (n *Emphasis) GetChildren() []Node {
586586
}
587587

588588
type Flourish struct {
589-
Type string `json:"type"`
590-
Data interface{} `json:"data,omitempty"`
591-
Description string `json:"description,omitempty"`
592-
FallbackImage *FlourishFallbackImage `json:"fallbackImage,omitempty"`
593-
FlourishType string `json:"flourishType,omitempty"`
594-
Id string `json:"id,omitempty"`
595-
LayoutWidth string `json:"layoutWidth,omitempty"`
596-
Timestamp string `json:"timestamp,omitempty"`
589+
Type string `json:"type"`
590+
Data interface{} `json:"data,omitempty"`
591+
Description string `json:"description,omitempty"`
592+
FallbackImage *FlourishFallbackImage `json:"fallbackImage,omitempty"`
593+
FlourishType string `json:"flourishType,omitempty"`
594+
Id string `json:"id,omitempty"`
595+
LayoutWidth string `json:"layoutWidth,omitempty"`
596+
Timestamp string `json:"timestamp,omitempty"`
597+
BlockIdentifier string `json:"blockIdentifier,omitempty"`
597598
}
598599

599600
func (n *Flourish) GetType() string {
@@ -628,6 +629,7 @@ type Heading struct {
628629
Children []*Text `json:"children,omitempty"`
629630
Data interface{} `json:"data,omitempty"`
630631
Level string `json:"level,omitempty"`
632+
BlockIdentifier string `json:"blockIdentifier,omitempty"`
631633
}
632634

633635
func (n *Heading) GetType() string {
@@ -647,10 +649,11 @@ func (n *Heading) GetChildren() []Node {
647649
}
648650

649651
type ImageSet struct {
650-
Type string `json:"type"`
651-
Data interface{} `json:"data,omitempty"`
652-
ID string `json:"id,omitempty"`
653-
Picture *Picture `json:"picture,omitempty"`
652+
Type string `json:"type"`
653+
Data interface{} `json:"data,omitempty"`
654+
ID string `json:"id,omitempty"`
655+
Picture *Picture `json:"picture,omitempty"`
656+
BlockIdentifier string `json:"blockIdentifier,omitempty"`
654657
}
655658

656659
func (n *ImageSet) GetType() string {

libraries/from-bodyxml/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,44 @@ export let defaultTransformers = {
5656
* @type {Transformer<ContentTree.transit.Heading>}
5757
*/
5858
h1(h1) {
59+
const blockId = h1.attributes["data-fragment-id"] || h1.attributes["id"];
5960
return {
6061
type: "heading",
6162
level: "chapter",
63+
...(blockId && { blockIdentifier: blockId }),
6264
};
6365
},
6466
/**
6567
* @type {Transformer<ContentTree.transit.Heading>}
6668
*/
6769
h2(h2) {
70+
const blockId = h2.attributes["data-fragment-id"] || h2.attributes["id"];
6871
return {
6972
type: "heading",
7073
level: "subheading",
74+
...(blockId && { blockIdentifier: blockId }),
7175
};
7276
},
7377
/**
7478
* @type {Transformer<ContentTree.transit.Heading>}
7579
*/
7680
h3(h3) {
81+
const blockId = h3.attributes["data-fragment-id"] || h3.attributes["id"];
7782
return {
7883
type: "heading",
7984
level: "subheading",
85+
...(blockId && { blockIdentifier: blockId }),
8086
};
8187
},
8288
/**
8389
* @type {Transformer<ContentTree.transit.Heading>}
8490
*/
8591
h4(h4) {
92+
const blockId = h4.attributes["data-fragment-id"] || h4.attributes["id"];
8693
return {
8794
type: "heading",
8895
level: "label",
96+
...(blockId && { blockIdentifier: blockId }),
8997
};
9098
},
9199
/**
@@ -237,9 +245,11 @@ export let defaultTransformers = {
237245
* @type {Transformer<ContentTree.transit.ImageSet>}
238246
*/
239247
[ContentType.imageset](content) {
248+
const blockId = content.attributes["data-fragment-id"] || content.attributes["id"];
240249
return {
241250
type: "image-set",
242251
id: content.attributes.url ?? "",
252+
...(blockId && { blockIdentifier: blockId }),
243253
children: null,
244254
};
245255
},
@@ -260,6 +270,7 @@ export let defaultTransformers = {
260270
[ContentType.content](content) {
261271
const id = content.attributes.url ?? "";
262272
const uuid = id.split("/").pop();
273+
const blockId = content.attributes["data-fragment-id"] || content.attributes["id"];
263274

264275
if (content.attributes["data-asset-type"] == "flourish") {
265276
return /** @type {ContentTree.transit.Flourish} */ ({
@@ -271,6 +282,7 @@ export let defaultTransformers = {
271282
),
272283
description: content.attributes["alt"] || "",
273284
timestamp: content.attributes["data-time-stamp"] || "",
285+
...(blockId && { blockIdentifier: blockId }),
274286
children: null,
275287
});
276288
}

schemas/body-tree.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@
188188
"ContentTree.transit.Flourish": {
189189
"additionalProperties": false,
190190
"properties": {
191+
"blockIdentifier": {
192+
"type": "string"
193+
},
191194
"data": {},
192195
"description": {
193196
"type": "string"
@@ -220,6 +223,9 @@
220223
"ContentTree.transit.Heading": {
221224
"additionalProperties": false,
222225
"properties": {
226+
"blockIdentifier": {
227+
"type": "string"
228+
},
223229
"children": {
224230
"items": {
225231
"$ref": "#/definitions/ContentTree.transit.Text"
@@ -250,6 +256,9 @@
250256
"ContentTree.transit.ImageSet": {
251257
"additionalProperties": false,
252258
"properties": {
259+
"blockIdentifier": {
260+
"type": "string"
261+
},
253262
"data": {},
254263
"id": {
255264
"type": "string"

schemas/content-tree.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@
239239
"ContentTree.full.Flourish": {
240240
"additionalProperties": false,
241241
"properties": {
242+
"blockIdentifier": {
243+
"type": "string"
244+
},
242245
"data": {},
243246
"description": {
244247
"type": "string"
@@ -331,6 +334,9 @@
331334
"ContentTree.full.Heading": {
332335
"additionalProperties": false,
333336
"properties": {
337+
"blockIdentifier": {
338+
"type": "string"
339+
},
334340
"children": {
335341
"items": {
336342
"$ref": "#/definitions/ContentTree.full.Text"
@@ -361,6 +367,9 @@
361367
"ContentTree.full.ImageSet": {
362368
"additionalProperties": false,
363369
"properties": {
370+
"blockIdentifier": {
371+
"type": "string"
372+
},
364373
"data": {},
365374
"id": {
366375
"type": "string"

schemas/transit-tree.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@
213213
"ContentTree.transit.Flourish": {
214214
"additionalProperties": false,
215215
"properties": {
216+
"blockIdentifier": {
217+
"type": "string"
218+
},
216219
"data": {},
217220
"description": {
218221
"type": "string"
@@ -245,6 +248,9 @@
245248
"ContentTree.transit.Heading": {
246249
"additionalProperties": false,
247250
"properties": {
251+
"blockIdentifier": {
252+
"type": "string"
253+
},
248254
"children": {
249255
"items": {
250256
"$ref": "#/definitions/ContentTree.transit.Text"
@@ -275,6 +281,9 @@
275281
"ContentTree.transit.ImageSet": {
276282
"additionalProperties": false,
277283
"properties": {
284+
"blockIdentifier": {
285+
"type": "string"
286+
},
278287
"data": {},
279288
"id": {
280289
"type": "string"

0 commit comments

Comments
 (0)