Skip to content

Commit

Permalink
refactor(external_link): arrow function
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Aug 11, 2019
1 parent 41e215d commit d999e24
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/plugins/filter/after_render/external_link.js
Expand Up @@ -12,12 +12,12 @@ function externalLinkFilter(data) {
const $ = cheerio.load(data, {decodeEntities: false});
const siteHost = url.parse(config.url).hostname || config.url;

$('a').each(function() {
$('a').each((index, element) => {
// Exit if the link has target attribute
if ($(this).attr('target')) return;
if ($(element).attr('target')) return;

// Exit if the href attribute doesn't exists
const href = $(this).attr('href');
const href = $(element).attr('href');
if (!href) return;

const parsedUrl = url.parse(href);
Expand All @@ -28,7 +28,7 @@ function externalLinkFilter(data) {
// Exit if the url has same host with config.url
if (parsedUrl.hostname === siteHost) return;

$(this)
$(element)
.attr('target', '_blank')
.attr('rel', 'noopener');
});
Expand Down

0 comments on commit d999e24

Please sign in to comment.