Ghost/core/server/services/mega/segment-parser.js
Naz bb8cf6001e Added unique filtering for segment parser
refs https://github.com/TryGhost/Team/issues/828

- When detecting email segments and later creating a member filter out of this data we only care about unique segments otherwise we'd be creating multiple batches with the same segment filter
2021-06-30 17:43:28 +04:00

15 lines
361 B
JavaScript

const cheerio = require('cheerio');
const getSegmentsFromHtml = (html) => {
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;