I have a Hugo site with some JavaScript and Gulp.
I would like to automatically detect and format <a> links so that an "external link" icon and "target=_blank" are added.
For now I do it in the client browser with some JavaScript:
// EXTERNAL LINKS
$(document.links).filter(function() {
return this.hostname != window.location.hostname
&& this.hostname != "domain-name-base-url.com"
&& this.hostname != "another-domain-name-base-url-to-be-treated-as-internal.com"
}).attr('target', '_blank').addClass("external");
But I would like to do it at build time for performance reasons.
How can I move this to a post-build gulp task? I tried some stuff with .pipe(replace...) but couldn't manage to do it. Can I even do it at Hugo build time?
If anyone knows even a simpler way to achieve this (allow the user to type in Markdown forgetting about whether a link is external or no, and adding `target=_blank" and an icon at build time)... any magical library or best practice?