Skip to content

Commit e76b3ad

Browse files
authored
Merge pull request #81 from Financial-Times/ccc-transformer
Add transformer for CustomCodeComponent
2 parents f4d650c + dc2e76f commit e76b3ad

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

libraries/from-bodyxml/index.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let ContentType = {
77
video: "http://www.ft.com/ontology/content/Video",
88
content: "http://www.ft.com/ontology/content/Content",
99
article: "http://www.ft.com/ontology/content/Article",
10+
customCodeComponent: "http://www.ft.com/ontology/content/CustomCodeComponent",
1011
};
1112

1213
/**
@@ -292,6 +293,21 @@ export let defaultTransformers = {
292293
title: content.attributes.dataTitle ?? "",
293294
};
294295
},
296+
/**
297+
* @type {Transformer<ContentTree.transit.CustomCodeComponent>}
298+
*/
299+
[ContentType.customCodeComponent](content) {
300+
const id = content.attributes.url ?? "";
301+
const uuid = id.split("/").pop();
302+
return {
303+
type: "custom-code-component",
304+
id: uuid ?? "",
305+
layoutWidth: toValidLayoutWidth(
306+
content.attributes["data-layout-width"] || ""
307+
),
308+
children: null,
309+
};
310+
},
295311
/**
296312
* @type {Transformer<ContentTree.transit.Recommended>}
297313
*/
@@ -311,7 +327,7 @@ export let defaultTransformers = {
311327
* ContentTree.transit.Layout |
312328
* ContentTree.transit.LayoutSlot |
313329
* { type: "__LIFT_CHILDREN__"} |
314-
* { type: "__UNKNOWN__"}
330+
* { type: "__UNKNOWN__", data?: any}
315331
* >}
316332
*/
317333
div(div) {
@@ -332,7 +348,7 @@ export let defaultTransformers = {
332348
type: "layout-slot",
333349
});
334350
}
335-
return { type: "__UNKNOWN__" };
351+
return { type: "__UNKNOWN__", data: div };
336352
},
337353
experimental() {
338354
return { type: "__LIFT_CHILDREN__" };
@@ -408,15 +424,15 @@ export function fromXast(bodyxast, transformers = defaultTransformers) {
408424
}
409425
return ctnode;
410426
} else {
411-
return { type: "__UNKNOWN__" };
427+
return { type: "__UNKNOWN__", data: xmlnode };
412428
}
413429
} else if (isXText(xmlnode)) {
414430
return {
415431
type: "text",
416432
value: xmlnode.value,
417433
};
418434
} else {
419-
return { type: "__UNKNOWN__" };
435+
return { type: "__UNKNOWN__" , data: xmlnode };
420436
}
421437
})(bodyxast);
422438
}

0 commit comments

Comments
 (0)