rittenhop-dev/versions/5.94.2/node_modules/@tryghost/url-utils/lib/utils/html-absolute-to-relative.js
2024-09-23 19:40:12 -04:00

21 lines
933 B
JavaScript

const htmlTransform = require('./html-transform');
const absoluteToRelative = require('./absolute-to-relative');
function htmlAbsoluteToRelative(html = '', siteUrl, _options) {
const defaultOptions = {assetsOnly: false, ignoreProtocol: true};
const options = Object.assign({}, defaultOptions, _options || {});
// exit early and avoid parsing if the content does not contain the siteUrl
options.earlyExitMatchStr = options.ignoreProtocol ? siteUrl.replace(/http:|https:/, '') : siteUrl;
options.earlyExitMatchStr = options.earlyExitMatchStr.replace(/\/$/, '');
// need to ignore itemPath because absoluteToRelative doesn't take that option
const transformFunction = function (_url, _siteUrl, _itemPath, __options) {
return absoluteToRelative(_url, _siteUrl, __options);
};
return htmlTransform(html, siteUrl, transformFunction, '', options);
}
module.exports = htmlAbsoluteToRelative;