xmitter-11ty/_src/HtmlToAbsoluteUrls.js

21 lines
465 B
JavaScript
Raw Normal View History

2018-01-27 22:08:43 -05:00
const posthtml = require('posthtml');
const urls = require('posthtml-urls')
const absoluteUrl = require("./AbsoluteUrl");
module.exports = function(htmlContent, base) {
let options = {
eachURL: function(url, attr, element) {
// #anchor in-page
if( url.trim().indexOf("#") === 0 ) {
return url;
}
return absoluteUrl(url, base);
}
};
let modifier = posthtml().use(urls(options));
return modifier.process(htmlContent);
};