jekyll-link-attributes 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d59a29fc9f1e6e6ec043e624b4cdf4a3694ae2f6440e1c09c4b6199587075fda
4
+ data.tar.gz: 13d53f2e5d102022f32d475cb66eec47dcbc4aac7e3aef874fdf5f8d502b37e0
5
+ SHA512:
6
+ metadata.gz: 8fb6ebbb5691b81672b195b0609ce7f6d29285e6fc0944fae2e06e0f004b4efe32d6286b07c3e629845006c8be916a3f3e4eb8fa2fe1b4a0e236b4335cf8c9fa
7
+ data.tar.gz: 8a79b43d72e9f59174da0e1f5a448c9456f2e29b5877575265f9d651adab0bc242679953cc29d59b820b5143bafd758ad1ceb16ee0167869a5268220242d2756
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .idea
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :test do
8
+ gem 'rspec'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jekyll-link-attributes (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.8.1)
10
+ public_suffix (>= 2.0.2, < 6.0)
11
+ colorator (1.1.0)
12
+ concurrent-ruby (1.1.10)
13
+ diff-lcs (1.5.0)
14
+ em-websocket (0.5.3)
15
+ eventmachine (>= 0.12.9)
16
+ http_parser.rb (~> 0)
17
+ eventmachine (1.2.7)
18
+ ffi (1.15.5)
19
+ forwardable-extended (2.6.0)
20
+ http_parser.rb (0.8.0)
21
+ i18n (1.12.0)
22
+ concurrent-ruby (~> 1.0)
23
+ jekyll (4.2.2)
24
+ addressable (~> 2.4)
25
+ colorator (~> 1.0)
26
+ em-websocket (~> 0.5)
27
+ i18n (~> 1.0)
28
+ jekyll-sass-converter (~> 2.0)
29
+ jekyll-watch (~> 2.0)
30
+ kramdown (~> 2.3)
31
+ kramdown-parser-gfm (~> 1.0)
32
+ liquid (~> 4.0)
33
+ mercenary (~> 0.4.0)
34
+ pathutil (~> 0.9)
35
+ rouge (~> 3.0)
36
+ safe_yaml (~> 1.0)
37
+ terminal-table (~> 2.0)
38
+ jekyll-sass-converter (2.2.0)
39
+ sassc (> 2.0.1, < 3.0)
40
+ jekyll-watch (2.2.1)
41
+ listen (~> 3.0)
42
+ kramdown (2.4.0)
43
+ rexml
44
+ kramdown-parser-gfm (1.1.0)
45
+ kramdown (~> 2.0)
46
+ liquid (4.0.3)
47
+ listen (3.7.1)
48
+ rb-fsevent (~> 0.10, >= 0.10.3)
49
+ rb-inotify (~> 0.9, >= 0.9.10)
50
+ mercenary (0.4.0)
51
+ nokogiri (1.13.8-x86_64-darwin)
52
+ racc (~> 1.4)
53
+ pathutil (0.16.2)
54
+ forwardable-extended (~> 2.6)
55
+ public_suffix (5.0.0)
56
+ racc (1.6.0)
57
+ rake (10.5.0)
58
+ rb-fsevent (0.11.2)
59
+ rb-inotify (0.10.1)
60
+ ffi (~> 1.0)
61
+ rexml (3.2.5)
62
+ rouge (3.30.0)
63
+ rspec (3.11.0)
64
+ rspec-core (~> 3.11.0)
65
+ rspec-expectations (~> 3.11.0)
66
+ rspec-mocks (~> 3.11.0)
67
+ rspec-core (3.11.0)
68
+ rspec-support (~> 3.11.0)
69
+ rspec-expectations (3.11.0)
70
+ diff-lcs (>= 1.2.0, < 2.0)
71
+ rspec-support (~> 3.11.0)
72
+ rspec-mocks (3.11.1)
73
+ diff-lcs (>= 1.2.0, < 2.0)
74
+ rspec-support (~> 3.11.0)
75
+ rspec-support (3.11.0)
76
+ safe_yaml (1.0.5)
77
+ sassc (2.4.0)
78
+ ffi (~> 1.9)
79
+ terminal-table (2.0.0)
80
+ unicode-display_width (~> 1.1, >= 1.1.1)
81
+ unicode-display_width (1.8.0)
82
+
83
+ PLATFORMS
84
+ x86_64-darwin-20
85
+
86
+ DEPENDENCIES
87
+ bundler (>= 2.0.0)
88
+ jekyll (>= 4.0.0)
89
+ jekyll-link-attributes!
90
+ nokogiri (>= 1.0.0)
91
+ rake (>= 10.0.0)
92
+ rspec
93
+
94
+ BUNDLED WITH
95
+ 2.3.21
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright 2022 Twin Sun, LLC
2
+
3
+ Redistribution and use in source and binary forms, with or without modification,
4
+ are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above
9
+ copyright notice, this list of conditions and the following
10
+ disclaimer in the documentation and/or other materials provided
11
+ with the distribution.
12
+ * Neither the name of Twin Sun, LLC nor the names of its
13
+ contributors may be used to endorse or promote products derived
14
+ from this software without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Jekyll Link Attributes
2
+
3
+ This plugin adds `rel` and `target` attributes to all external links in your Jekyll site.
4
+ The default configuration opens external links in a new tab and conserves domain authority for your site.
5
+
6
+ ## Setup
7
+
8
+ 1. Add the gem to your `Gemfile`:
9
+ ```ruby
10
+ gem 'jekyll-link-attributes'
11
+ ```
12
+ 2. Run `bundle install` to install the gem
13
+ 3. Add the following to your `_config.yml`:
14
+ ```yaml
15
+ plugins:
16
+ - jekyll-link-attributes
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ You can override the default configuration by adding the following section to your Jekyll site's `config.yml`:
22
+
23
+ ```yaml
24
+ external_links:
25
+ enabled: true
26
+ rel: external nofollow noopener
27
+ target: _blank
28
+ exclude:
29
+ - "https://example.com"
30
+ - "https://another.example.com/test.html"
31
+ ```
32
+
33
+ ### Default Values
34
+ | Key | Default Value | Description |
35
+ | ---------------------------- | ---------------------------- | -------------------------------------------------- |
36
+ | `external_links.enabled` | `true` | Enable attribute modifications for external links. |
37
+ | `external_links.rel` | `external nofollow noopener` | The `rel` attribute to add to external links. |
38
+ | `external_links.target` | `_blank` | The `target` attribute to add to external links. |
39
+ | `external_links.exclude` | `[]` | A list of URLs to exclude from processing. |
40
+
41
+ ## Contributing
42
+
43
+ Pull requests are welcome!
44
+ If you wish to change existing behavior, please open an issue to discuss the change before investing time in a PR.
45
+ RSpec tests are encouraged for any new features.
46
+
47
+ ## Supported by Twin Sun
48
+
49
+ This project is maintained by [Twin Sun](https://twinsunsolutions.com/), a custom mobile and web app development agency in Nashville, TN.
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'jekyll-link-attributes/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'jekyll-link-attributes'
7
+ spec.version = Jekyll::LinkAttributes::VERSION
8
+ spec.authors = ['twinsunllc']
9
+ spec.email = ['contact@twinsunsolutions.com']
10
+
11
+ spec.summary = 'This plugin adds `rel` and `target` attributes to all external links in your Jekyll site.'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/twinsunllc/jekyll-link-attributes'
14
+ spec.license = 'BSD 3-Clause'
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '>= 2.0.0'
30
+ spec.add_development_dependency 'jekyll', '>= 4.0.0'
31
+ spec.add_development_dependency 'nokogiri', '>= 1.0.0'
32
+ spec.add_development_dependency 'rake', '>= 10.0.0'
33
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/hooks'
4
+ require 'jekyll-link-attributes'
5
+
6
+ Jekyll::Hooks.register :documents, :post_render do |document|
7
+ Jekyll::LinkAttributes.post_render_html(document)
8
+ end
9
+
10
+ Jekyll::Hooks.register :pages, :post_render do |page|
11
+ next unless page.output_ext.eql?('.html')
12
+
13
+ Jekyll::LinkAttributes.post_render_html(page)
14
+ end
15
+
16
+ Jekyll::Hooks.register :posts, :post_render do |post|
17
+ Jekyll::LinkAttributes.post_render_html(post)
18
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ class LinkAttributes
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll-link-attributes/hooks'
4
+ require 'jekyll-link-attributes/version'
5
+ require 'nokogiri'
6
+
7
+ module Jekyll
8
+
9
+ # Adjusts external links in HTML documents.
10
+ class LinkAttributes
11
+
12
+ # Perform post_render processing on the specified document/page/post
13
+ # @param [Object] article a Jekyll document, page, or post
14
+ def self.post_render_html(article)
15
+ config = article.site.config
16
+ return unless external_links_enabled?(config: config)
17
+
18
+ output = Nokogiri::HTML(article.output)
19
+ output.css('a').each do |a|
20
+ next unless external_link?(a['href'])
21
+ next if excludes_external_link?(config: config, url: a['href'])
22
+
23
+ a['rel'] = external_link_rel(config: config)
24
+ a['target'] = external_link_target(config: config)
25
+ end
26
+
27
+ article.output = output.to_s
28
+ end
29
+
30
+ private
31
+
32
+ def self.excludes_external_link?(config:, url:)
33
+ (config.dig('external_links', 'exclude') || []).include?(url)
34
+ end
35
+
36
+ def self.external_link?(url)
37
+ (url =~ %r{^https?://}) != nil
38
+ end
39
+
40
+ def self.external_links_enabled?(config:)
41
+ enabled = config.dig('external_links', 'enabled')
42
+ enabled.nil? || enabled
43
+ end
44
+
45
+ def self.external_link_rel(config:)
46
+ config.dig('external_links', 'rel') || 'external nofollow noopener'
47
+ end
48
+
49
+ def self.external_link_target(config:)
50
+ config.dig('external_links', 'target') || '_blank'
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-link-attributes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - twinsunllc
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 10.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 10.0.0
69
+ description: This plugin adds `rel` and `target` attributes to all external links
70
+ in your Jekyll site.
71
+ email:
72
+ - contact@twinsunsolutions.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".ruby-version"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - jekyll-link-attributes.gemspec
85
+ - lib/jekyll-link-attributes.rb
86
+ - lib/jekyll-link-attributes/hooks.rb
87
+ - lib/jekyll-link-attributes/version.rb
88
+ homepage: https://github.com/twinsunllc/jekyll-link-attributes
89
+ licenses:
90
+ - BSD 3-Clause
91
+ metadata:
92
+ allowed_push_host: https://rubygems.org
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.3.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: This plugin adds `rel` and `target` attributes to all external links in your
112
+ Jekyll site.
113
+ test_files: []