You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
516 B
JavaScript
25 lines
516 B
JavaScript
import URL from 'url';
|
|
|
|
import {
|
|
getAttrs,
|
|
setAttr,
|
|
} from 'utils/dom';
|
|
|
|
function absolutize($, rootUrl, attr, $content) {
|
|
$(`[${attr}]`, $content).each((_, node) => {
|
|
const attrs = getAttrs(node);
|
|
const url = attrs[attr];
|
|
|
|
if (url) {
|
|
const absoluteUrl = URL.resolve(rootUrl, url);
|
|
setAttr(node, attr, absoluteUrl);
|
|
}
|
|
});
|
|
}
|
|
|
|
export default function makeLinksAbsolute($content, $, url) {
|
|
['href', 'src'].forEach(attr => absolutize($, url, attr, $content));
|
|
|
|
return $content;
|
|
}
|