const config = require('@/config').value;
const cheerio = require('cheerio');
const logger = require('@/utils/logger');
// match path or sub-path
const matchPath = (path, paths) => {
for (const p of paths) {
if (path.startsWith(p) && (path.length === p.length || path[p.length] === '/')) {
return true;
}
}
return false;
};
// return ture if the path needs to be processed
const filterPath = (path) => {
const include = config.hotlink.includePaths;
const exclude = config.hotlink.excludePaths;
return !(include && !matchPath(path, include)) && !(exclude && matchPath(path, exclude));
};
const interpolate = (str, obj) => str.replace(/\${([^}]+)}/g, (_, prop) => obj[prop]);
// I don't want to keep another regex and
// URL will be the standard way to parse URL
const parseUrl = (str) => {
let url;
try {
url = new URL(str);
} catch (e) {
logger.error(`Failed to parse ${str}`);
}
return url;
};
const replaceUrls = (body, template) => {
// const $ = cheerio.load(body, { decodeEntities: false, xmlMode: true });
// `