xmitter-11ty/_src/HtmlToAbsoluteUrls.js

23 lines
483 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) {
2018-01-28 00:22:40 -05:00
url = url.trim();
2018-01-27 22:08:43 -05:00
// #anchor in-page
2018-01-28 00:22:40 -05:00
if( url.indexOf("#") === 0 ) {
2018-01-27 22:08:43 -05:00
return url;
}
return absoluteUrl(url, base);
}
};
let modifier = posthtml().use(urls(options));
return modifier.process(htmlContent);
};