Skip to content

Commit

Permalink
Validate layoutWidth attribute and fall back to full-width
Browse files Browse the repository at this point in the history
  • Loading branch information
adgad authored and chee committed Jan 28, 2025
1 parent 77292bb commit 6fa51ff
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions libraries/from-bodyxml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ let ContentType = {
article: "http://www.ft.com/ontology/content/Article",
}

/**
* @param {string} layoutWidth
* @returns {ContentTree.LayoutWidth}
*/
function toValidLayoutWidth(layoutWidth) {
if(["auto", "in-line", "inset-left", "inset-right", "full-bleed", "full-grid", "mid-grid", "full-width"].includes(layoutWidth)) {
return /** @type {ContentTree.LayoutWidth} */(layoutWidth);
} else {
return 'full-width';
}
}
/**
* @typedef {import("unist").Parent} UParent
* @typedef {import("unist").Node} UNode
Expand Down Expand Up @@ -238,7 +249,7 @@ export let defaultTransformers = {
return /** @type {ContentTree.transit.Flourish} */ ({
type: "flourish",
flourishType: content.attributes["data-flourish-type"] || "",
layoutWidth: content.attributes["data-layout-width"] || "",
layoutWidth: toValidLayoutWidth(content.attributes["data-layout-width"] || ""),
description: content.attributes["alt"] || "",
timestamp: content.attributes["data-time-stamp"] || "",
// fallbackImage -- TODO should this be external in content-tree?
Expand Down Expand Up @@ -291,7 +302,7 @@ export let defaultTransformers = {
return /** @type {ContentTree.transit.Layout} */({
type: "layout",
layoutName: div.attributes['data-layout-name'] ?? "auto",
layoutWidth: div.attributes['data-layout-width'] ?? "",
layoutWidth: toValidLayoutWidth(div.attributes['data-layout-width'] ?? ""),
});
}
if(div.attributes.class === "n-content-layout__container") {
Expand Down

0 comments on commit 6fa51ff

Please sign in to comment.