Skip to content

Commit

Permalink
Create split-content-body utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinsina committed Sep 30, 2024
1 parent c76f39b commit 1a01e52
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/global/utils/split-content-body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const cheerio = require('cheerio');

module.exports = ({ body } = {}) => {
const $ = cheerio.load(body);
// Suspecting halfway needs to be calculated like quarterway due to injected ads here
const likelyHalfwayElement = Math.floor($('div').children().length / 4);
const part1Nodes = [];
const part2Nodes = [];
$('div').children().each((index, node) => {
if (index < likelyHalfwayElement) {
part1Nodes.push($.html(node));
} else {
part2Nodes.push($.html(node));
}
});
const partOne = part1Nodes.join('');
const partTwo = part2Nodes.join('');
return { partOne, partTwo };
};

0 comments on commit 1a01e52

Please sign in to comment.