Ghost/core/server/services/mega/segment-parser.js
Daniel Lockyer 80d5f89382 Lazy loaded cheerio dependency
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
2021-11-18 17:31:04 +01:00

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;