-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create split-content-body utility function
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
}; |