Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1015 from parameter1/native-x-teasers
Browse files Browse the repository at this point in the history
Move html teaser logic to fetch-email-ad util
  • Loading branch information
brandonbk authored Nov 16, 2024
2 parents f708638 + 6dc3af8 commit a6d9543
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,10 @@ $ const timestamp = date ? dateToTimestamp(date) : undefined;
req,
debug,
})>
$ const regex = /^\s+<p/;
<if(Array.isArray(resolved.data))>
$ const results = resolved.data.map((node) => ({
...node,
...(node.teaser && !regex.test(node.teaser) && {
teaser: `<p>${node.teaser}</p>`,
}),
}));
<${input.renderBody}
data=results
tenant=mindfulTenant
/>
</if>
<else-if(resolved.data && resolved.data.teaser && !regex.test(resolved.data.teaser))>
$ const results = {
data: {
...resolved.data,
teaser: `<p>${resolved.data.teaser}</p>`,
},
tenant: mindfulTenant,
};
<${input.renderBody}
data=results
tenant=mindfulTenant
/>
</else-if>
<else>
<${input.renderBody}
data=resolved.data
tenant=mindfulTenant
/>
</else>

<${input.renderBody}
data=resolved.data
tenant=mindfulTenant
/>
</marko-web-resolve>
</if>
<else>
Expand Down
28 changes: 28 additions & 0 deletions packages/marko-newsletters-native-x/utils/fetch-email-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,33 @@ module.exports = async ({
err.body = json;
throw err;
}
const regex = /^\s+<p/;
if (Array.isArray(json.data)) {
const results = json.data.map((node) => ({
...node,
creative: {
...node.creative,
...(node.creative.teaser && !regex.test(node.creative.teaser) && {
teaser: `<p>${node.creative.teaser}</p>`,
}),
},
}));
return results;
}
if (json.data && json.data.creative) {
const results = {
...json,
data: {
...json.data,
creative: {
...json.data.creative,
...(json.data.creative.teaser && !regex.test(json.data.creative.teaser) && {
teaser: `<p>${json.data.creative.teaser}</p>`,
}),
},
},
};
return results;
}
return json;
};

0 comments on commit a6d9543

Please sign in to comment.