Class: Jekyll::LinkAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-link-attributes.rb,
lib/jekyll-link-attributes/version.rb

Overview

Adjusts external links in HTML documents.

Constant Summary collapse

VERSION =
'0.0.2'

Class Method Summary collapse

Class Method Details

.post_render_html(article) ⇒ Object

Perform post_render processing on the specified document/page/post

Parameters:

  • article (Object)

    a Jekyll document, page, or post



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll-link-attributes.rb', line 14

def self.post_render_html(article)
  config = article.site.config
  return unless external_links_enabled?(config: config)

  output = Nokogiri::HTML(article.output)
  output.css('a').each do |a|
    next unless external_link?(config: config, url: a['href'])
    next if excludes_external_link?(config: config, url: a['href'])

    a['rel'] = external_link_rel(config: config)
    a['target'] = external_link_target(config: config)
  end

  article.output = output.to_s
end