const parser = require("fast-xml-parser") const config = require('./../config') const dayjs = require('dayjs') const customParseFormat = require('dayjs/plugin/customParseFormat') dayjs.extend(customParseFormat) const parseOpts = { ignoreAttributes: false } function collectHrefsFromDescription(description) { // first thought: use parser.parse() and traverse recursively. turned out to be way too slow. const linksMatch = description.match(/href="([^"]*")/g) if(!linksMatch) return [] const links = linksMatch .map(match => match.replace("href=", "").replace(/\"/g, "")) .filter(match => !(/\.(gif|zip|rar|bz2|gz|7z|jpe?g|tiff?|png|webp|bmp)$/i).test(match)) .filter(match => !config.disallowedWebmentionDomains.some(domain => match.indexOf(domain) >= 0)) return [...new Set(links)] } /** * a typical RSS item looks like this: -- if