mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
80d5f89382
refs https://github.com/TryGhost/Toolbox/issues/136 - `cheerio` isn't needed during the boot but it takes time and memory to load the library - this commit moves `cheerio` requires later into the code to when they are needed
14 lines
364 B
JavaScript
14 lines
364 B
JavaScript
const getSegmentsFromHtml = (html) => {
|
|
const cheerio = require('cheerio');
|
|
const $ = cheerio.load(html);
|
|
|
|
const allSegments = $('[data-gh-segment]')
|
|
.get()
|
|
.map(el => el.attribs['data-gh-segment']);
|
|
|
|
// only return unique elements
|
|
return [...new Set(allSegments)];
|
|
};
|
|
|
|
module.exports.getSegmentsFromHtml = getSegmentsFromHtml;
|