jekyll-target-blank 1.2.0 → 2.0.2
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 +4 -4
- data/.gitignore +3 -1
- data/.rubocop.yml +3 -4
- data/.travis.yml +1 -1
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/Rakefile +2 -2
- data/jekyll-target-blank.gemspec +18 -18
- data/lib/jekyll-target-blank/version.rb +1 -1
- data/lib/jekyll-target-blank.rb +21 -22
- data/spec/jekyll-target_spec.rb +169 -171
- data/spec/spec_helper.rb +4 -4
- metadata +31 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d09306731b5daf78557b35c07d12b01ce9454066f6bbff6366a586f8eff3ef77
|
4
|
+
data.tar.gz: 5a4b74d1e06d47c1f00ba015df4eae7ba90ff91f3ed7a2a237639d2eaa853244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c672f8fcdc9464870295b847e901f13733c66e33628a25026078bd2f87b4cc3f1a1bb0ebf02f4c05b5007c1f778dbe856bf09962c68422480bcad9c59ddf7040
|
7
|
+
data.tar.gz: 000db26fb7adb11f4f5f0c7c675eb6625e7253f43d8d5097cb6c50d4ca7e2039eb31f7cae99a2a5508a5d3f55de01281fa27264a02ce1f3cb28df44250ea9902
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/jekyll-target-blank.gemspec
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require 'jekyll-target-blank/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'jekyll-target-blank'
|
9
9
|
spec.version = JekyllTargetBlank::VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
10
|
+
spec.authors = ['Keith Mifsud']
|
11
|
+
spec.email = ['mifsud.k@gmail.com']
|
12
|
+
spec.summary = 'Target Blank automatically changes the external links to open in a new browser.'
|
13
|
+
spec.description = 'Target Blank automatically changes the external links to open in a new browser for Jekyll sites.'
|
14
|
+
spec.homepage = 'https://github.com/keithmifsud/jekyll-target-blank'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.require_paths = [
|
18
|
-
spec.required_ruby_version =
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
spec.required_ruby_version = '>= 2.3.0'
|
19
|
+
spec.add_dependency 'jekyll', '>= 3.0', '<5.0'
|
20
|
+
spec.add_dependency 'nokogiri', '~> 1.10'
|
21
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
22
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
|
+
spec.add_development_dependency 'rubocop', '~> 1'
|
25
|
+
spec.add_development_dependency "rubocop-jekyll", "~> 0.12.0"
|
19
26
|
|
20
|
-
spec.add_dependency "jekyll", "~> 3.0"
|
21
|
-
spec.add_dependency "nokogiri", "~> 1.10.4"
|
22
|
-
|
23
|
-
spec.add_development_dependency "bundler", "~> 2.0"
|
24
|
-
spec.add_development_dependency "rake", "~> 12.0"
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
-
spec.add_development_dependency "rubocop", "0.55"
|
27
27
|
end
|
data/lib/jekyll-target-blank.rb
CHANGED
@@ -7,7 +7,7 @@ require "uri"
|
|
7
7
|
module Jekyll
|
8
8
|
class TargetBlank
|
9
9
|
BODY_START_TAG = "<body"
|
10
|
-
OPENING_BODY_TAG_REGEX = %r!<body([^<>]*)>\s
|
10
|
+
OPENING_BODY_TAG_REGEX = %r!<body([^<>]*)>\s*!.freeze
|
11
11
|
|
12
12
|
class << self
|
13
13
|
# Public: Processes the content and updated the external links
|
@@ -117,13 +117,9 @@ module Jekyll
|
|
117
117
|
|
118
118
|
# Private: Handles the default rel attribute values
|
119
119
|
def add_default_rel_attributes?
|
120
|
-
if should_not_include_noopener?
|
121
|
-
@should_add_noopener = false
|
122
|
-
end
|
120
|
+
@should_add_noopener = false if should_not_include_noopener?
|
123
121
|
|
124
|
-
if should_not_include_noreferrer?
|
125
|
-
@should_add_noreferrrer = false
|
126
|
-
end
|
122
|
+
@should_add_noreferrrer = false if should_not_include_noreferrer?
|
127
123
|
end
|
128
124
|
|
129
125
|
# Private: Sets any extra rel attribute values
|
@@ -142,7 +138,7 @@ module Jekyll
|
|
142
138
|
if @should_add_css_classes
|
143
139
|
existing_classes = get_existing_css_classes(link)
|
144
140
|
existing_classes = " " + existing_classes unless existing_classes.to_s.empty?
|
145
|
-
link["class"]
|
141
|
+
link["class"] = @css_classes_to_add + existing_classes
|
146
142
|
end
|
147
143
|
end
|
148
144
|
|
@@ -157,28 +153,31 @@ module Jekyll
|
|
157
153
|
#
|
158
154
|
# link = Nokogiri node.
|
159
155
|
def add_rel_attributes(link)
|
160
|
-
rel = ""
|
161
|
-
|
162
|
-
rel = "noopener"
|
163
|
-
end
|
156
|
+
rel = link["rel"] || ""
|
157
|
+
rel = add_noopener_to_rel(rel)
|
164
158
|
|
165
159
|
if @should_add_noreferrrer
|
166
|
-
unless rel.empty?
|
167
|
-
rel += " "
|
168
|
-
end
|
160
|
+
rel += " " unless rel.empty?
|
169
161
|
rel += "noreferrer"
|
170
162
|
end
|
171
163
|
|
172
164
|
if @should_add_extra_rel_attribute_values
|
173
|
-
unless rel.empty?
|
174
|
-
rel += " "
|
175
|
-
end
|
165
|
+
rel += " " unless rel.empty?
|
176
166
|
rel += @extra_rel_attribute_values
|
177
167
|
end
|
178
168
|
|
179
|
-
unless rel.empty?
|
180
|
-
|
169
|
+
link["rel"] = rel unless rel.empty?
|
170
|
+
end
|
171
|
+
|
172
|
+
# Private: Adds noopener attribute.
|
173
|
+
#
|
174
|
+
# rel = string
|
175
|
+
def add_noopener_to_rel(rel)
|
176
|
+
if @should_add_noopener
|
177
|
+
rel += " " unless rel.empty?
|
178
|
+
rel += "noopener"
|
181
179
|
end
|
180
|
+
rel
|
182
181
|
end
|
183
182
|
|
184
183
|
# Private: Checks if the link is a mailto url.
|
@@ -193,7 +192,7 @@ module Jekyll
|
|
193
192
|
#
|
194
193
|
# link - a url.
|
195
194
|
def external?(link)
|
196
|
-
if link
|
195
|
+
if link&.match?(URI.regexp(%w(http https)))
|
197
196
|
URI.parse(link).host != URI.parse(@site_url).host
|
198
197
|
end
|
199
198
|
end
|
@@ -332,6 +331,6 @@ module Jekyll
|
|
332
331
|
end
|
333
332
|
|
334
333
|
# Hooks into Jekyll's post_render event.
|
335
|
-
Jekyll::Hooks.register
|
334
|
+
Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
|
336
335
|
Jekyll::TargetBlank.process(doc) if Jekyll::TargetBlank.document_processable?(doc)
|
337
336
|
end
|
data/spec/jekyll-target_spec.rb
CHANGED
@@ -6,53 +6,51 @@ RSpec.describe(Jekyll::TargetBlank) do
|
|
6
6
|
let(:config_overrides) { {} }
|
7
7
|
let(:config_overrides) do
|
8
8
|
{
|
9
|
-
|
10
|
-
|
9
|
+
'url' => 'https://keith-mifsud.me',
|
10
|
+
'collections' => { 'docs' => { 'output' => 'true' } }
|
11
11
|
}
|
12
12
|
end
|
13
13
|
let(:configs) do
|
14
14
|
Jekyll.configuration(config_overrides.merge(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
21
|
-
))
|
15
|
+
'skip_config_files' => false,
|
16
|
+
'collections' => { 'docs' => { 'output' => true } },
|
17
|
+
'source' => unit_fixtures_dir,
|
18
|
+
'destination' => unit_fixtures_dir('_site')
|
19
|
+
))
|
22
20
|
end
|
23
21
|
let(:target_blank) { described_class }
|
24
22
|
let(:site) { Jekyll::Site.new(configs) }
|
25
23
|
let(:posts) { site.posts.docs.sort.reverse }
|
26
24
|
|
27
25
|
# get some fixtures
|
28
|
-
let(:post_with_external_markdown_link) { find_by_title(posts,
|
26
|
+
let(:post_with_external_markdown_link) { find_by_title(posts, 'Post with external markdown link') }
|
29
27
|
|
30
|
-
let(:post_with_multiple_external_markdown_links) { find_by_title(posts,
|
28
|
+
let(:post_with_multiple_external_markdown_links) { find_by_title(posts, 'Post with multiple external markdown links') }
|
31
29
|
|
32
|
-
let(:post_with_relative_markdown_link) { find_by_title(posts,
|
30
|
+
let(:post_with_relative_markdown_link) { find_by_title(posts, 'Post with relative markdown link') }
|
33
31
|
|
34
|
-
let(:post_with_absolute_internal_markdown_link) { find_by_title(posts,
|
32
|
+
let(:post_with_absolute_internal_markdown_link) { find_by_title(posts, 'Post with absolute internal markdown link') }
|
35
33
|
|
36
|
-
let(:post_with_html_anchor_tag) { find_by_title(posts,
|
34
|
+
let(:post_with_html_anchor_tag) { find_by_title(posts, 'Post with html anchor tag') }
|
37
35
|
|
38
|
-
let(:post_with_plain_text_link) { find_by_title(posts,
|
36
|
+
let(:post_with_plain_text_link) { find_by_title(posts, 'Post with plain text link') }
|
39
37
|
|
40
|
-
let(:document_with_a_processable_link) { find_by_title(site.collections[
|
38
|
+
let(:document_with_a_processable_link) { find_by_title(site.collections['docs'].docs, 'Document with a processable link') }
|
41
39
|
|
42
|
-
let(:text_file) { find_by_title(site.collections[
|
40
|
+
let(:text_file) { find_by_title(site.collections['docs'].docs, 'Text file') }
|
43
41
|
|
44
|
-
let(:post_with_code_block) { find_by_title(posts,
|
45
|
-
let(:document_with_liquid_tag) { find_by_title(site.collections[
|
42
|
+
let(:post_with_code_block) { find_by_title(posts, 'Post with code block') }
|
43
|
+
let(:document_with_liquid_tag) { find_by_title(site.collections['docs'].docs, 'Document with liquid tag') }
|
46
44
|
|
47
|
-
let(:document_with_include) { find_by_title(site.collections[
|
45
|
+
let(:document_with_include) { find_by_title(site.collections['docs'].docs, 'Document with include') }
|
48
46
|
|
49
|
-
let(:post_with_mailto_link) { find_by_title(posts,
|
47
|
+
let(:post_with_mailto_link) { find_by_title(posts, 'Post with mailto link') }
|
50
48
|
|
51
|
-
let(:post_with_external_html_link_and_random_css_classes) { find_by_title(posts,
|
49
|
+
let(:post_with_external_html_link_and_random_css_classes) { find_by_title(posts, 'Post with external html link and random css classes') }
|
52
50
|
|
53
|
-
let(:post_with_html_link_containing_the_specified_css_class) { find_by_title(posts,
|
51
|
+
let(:post_with_html_link_containing_the_specified_css_class) { find_by_title(posts, 'Post with html link containing the specified css class') }
|
54
52
|
|
55
|
-
let(:post_with_external_link_containing_the_specified_css_class_and_other_css_classes) { find_by_title(posts,
|
53
|
+
let(:post_with_external_link_containing_the_specified_css_class_and_other_css_classes) { find_by_title(posts, 'Post with external link containing the specified css class and other css classes') }
|
56
54
|
|
57
55
|
# define common wrappers.
|
58
56
|
def para(content)
|
@@ -66,50 +64,50 @@ RSpec.describe(Jekyll::TargetBlank) do
|
|
66
64
|
site.render
|
67
65
|
end
|
68
66
|
|
69
|
-
context
|
67
|
+
context 'Without entries in config file' do
|
70
68
|
let(:config_overrides) do
|
71
|
-
{
|
69
|
+
{ 'target-blank' => { 'add_css_classes' => false } }
|
72
70
|
end
|
73
71
|
|
74
|
-
it
|
72
|
+
it 'should add target attribute to external markdown link' do
|
75
73
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.'))
|
76
74
|
end
|
77
75
|
|
78
|
-
it
|
76
|
+
it 'should add target attribute to multiple external markdown links' do
|
79
77
|
expect(post_with_multiple_external_markdown_links.output).to include('<p>This post contains three links. The first link is to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>, the second link is, well, to <a href="https://keithmifsud.github.io" target="_blank" rel="noopener noreferrer">my website</a> and since <a href="https://github.com" target="_blank" rel="noopener noreferrer">GitHub</a> is so awesome, why not link to them too?</p>')
|
80
78
|
end
|
81
79
|
|
82
|
-
it
|
80
|
+
it 'should not add target attribute to relative markdown link' do
|
83
81
|
expect(post_with_relative_markdown_link.output).to include(para('Link to <a href="/contact">contact page</a>.'))
|
84
82
|
|
85
83
|
expect(post_with_relative_markdown_link.output).to_not include(para('Link to <a href="/contact" target="_blank" rel="noopener noreferrer">contact page</a>'))
|
86
84
|
end
|
87
85
|
|
88
|
-
it
|
86
|
+
it 'should not add target attribute to absolute internal link' do
|
89
87
|
expect(post_with_absolute_internal_markdown_link.output).to include('<p>This is an absolute internal <a href="https://keith-mifsud.me/contact">link</a>.</p>')
|
90
88
|
end
|
91
89
|
|
92
|
-
it
|
90
|
+
it 'should correctly handle existing html anchor tag' do
|
93
91
|
expect(post_with_html_anchor_tag.output).to include('<p>This is an <a href="https://google.com" target="_blank" rel="noopener noreferrer">anchor tag</a>.</p>')
|
94
92
|
end
|
95
93
|
|
96
|
-
it
|
97
|
-
expect(post_with_plain_text_link.output).to include(
|
94
|
+
it 'should not interfere with plain text link' do
|
95
|
+
expect(post_with_plain_text_link.output).to include('<p>This is a plain text link to https://google.com.</p>')
|
98
96
|
end
|
99
97
|
|
100
|
-
it
|
98
|
+
it 'should process external links in collections' do
|
101
99
|
expect(document_with_a_processable_link.output).to include('<p>This is a valid <a href="https://google.com" target="_blank" rel="noopener noreferrer">link</a>.</p>')
|
102
100
|
end
|
103
101
|
|
104
|
-
it
|
102
|
+
it 'should process external links in pages' do
|
105
103
|
expect(site.pages.first.output).to include('<p>This is a valid <a href="https://google.com" target="_blank" rel="noopener noreferrer">link</a>.</p>')
|
106
104
|
end
|
107
105
|
|
108
|
-
it
|
109
|
-
expect(text_file.output).to eq(
|
106
|
+
it 'should not process links in non html files' do
|
107
|
+
expect(text_file.output).to eq('Valid [link](https://google.com).')
|
110
108
|
end
|
111
109
|
|
112
|
-
it
|
110
|
+
it 'should not process link in code block but process link outside of block' do
|
113
111
|
expect(post_with_code_block.output).to include('<span class="s1">\'https://google.com\'</span>')
|
114
112
|
|
115
113
|
expect(post_with_code_block.output).not_to include('<span class="s1"><a href="https://google.com" target="_blank" rel="noopener noreferrer">https://google.com</a></span>')
|
@@ -117,307 +115,307 @@ RSpec.describe(Jekyll::TargetBlank) do
|
|
117
115
|
expect(post_with_code_block.output).to include('<p>Valid <a href="https://google.com" target="_blank" rel="noopener noreferrer">link</a></p>')
|
118
116
|
end
|
119
117
|
|
120
|
-
it
|
118
|
+
it 'should not break layouts' do
|
121
119
|
expect(site.pages.first.output).to include('<html lang="en-US">')
|
122
120
|
expect(site.pages.first.output).to include('<body class="wrap">')
|
123
121
|
end
|
124
122
|
|
125
|
-
it
|
123
|
+
it 'should not interfere with liquid tags' do
|
126
124
|
expect(document_with_liquid_tag.output).to include('<p>This <a href="/docs/document-with-liquid-tag.html">_docs/document-with-liquid-tag.md</a> is a document with a liquid tag.</p>')
|
127
125
|
end
|
128
126
|
|
129
|
-
it
|
130
|
-
expect(document_with_include.output).to include(
|
127
|
+
it 'should not interfere with includes' do
|
128
|
+
expect(document_with_include.output).to include('<p>This is a document with an include: This is an include.</p>')
|
131
129
|
end
|
132
130
|
|
133
|
-
it
|
134
|
-
expect(site.pages.first.output).to include(
|
131
|
+
it 'should not break layout content' do
|
132
|
+
expect(site.pages.first.output).to include('<div>Layout content started.</div>')
|
135
133
|
|
136
|
-
expect(site.pages.first.output).to include(
|
134
|
+
expect(site.pages.first.output).to include('<div>Layout content ended.</div>')
|
137
135
|
end
|
138
136
|
|
139
|
-
it
|
137
|
+
it 'should not duplicate post content' do
|
140
138
|
expect(post_with_external_markdown_link.output).to eq(post_with_layout_result)
|
141
139
|
end
|
142
140
|
|
143
|
-
it
|
141
|
+
it 'should ignore mailto links' do
|
144
142
|
expect(post_with_mailto_link.output).to include(para('This is a <a href="mailto:mifsud.k@gmail.com?Subject=Just%20an%20email">mailto link</a>.'))
|
145
143
|
end
|
146
144
|
end
|
147
145
|
|
148
|
-
context
|
149
|
-
let(:target_blank_css_class) {
|
146
|
+
context 'With a specified css class name' do
|
147
|
+
let(:target_blank_css_class) { 'ext-link' }
|
150
148
|
let(:config_overrides) do
|
151
149
|
{
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
}
|
150
|
+
'target-blank' => {
|
151
|
+
'css_class' => target_blank_css_class,
|
152
|
+
'add_css_classes' => false
|
153
|
+
}
|
156
154
|
}
|
157
155
|
end
|
158
156
|
|
159
|
-
it
|
157
|
+
it 'should not add target attribute to external markdown link that does not have the specified css class' do
|
160
158
|
expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank">Google</a>.'))
|
161
159
|
end
|
162
160
|
|
163
|
-
it
|
161
|
+
it 'should not add target attribute to external markdown link that does not have the specified css class even if it does have other css classes' do
|
164
162
|
expect(post_with_external_html_link_and_random_css_classes.output).to include(para('<a href="https://google.com" class="random-class another-random-class">Link</a>.'))
|
165
163
|
|
166
164
|
expect(post_with_external_html_link_and_random_css_classes.output).to_not include('target="_blank" rel="noopener noreferrer"')
|
167
165
|
end
|
168
166
|
|
169
|
-
it
|
167
|
+
it 'should add target attribute to an external link containing the specified css class' do
|
170
168
|
expect(post_with_html_link_containing_the_specified_css_class.output).to include(para('<a href="https://google.com" class="ext-link" target="_blank" rel="noopener noreferrer">Link with the css class specified in config</a>.'))
|
171
169
|
end
|
172
170
|
|
173
|
-
it
|
171
|
+
it 'should add target attribute to an external link containing the specified css class even when other css classes are specified' do
|
174
172
|
expect(post_with_external_link_containing_the_specified_css_class_and_other_css_classes.output).to include(para('This is <a href="https://not-keith-mifsud.me" class="random-class ext-link another-random-class" target="_blank" rel="noopener noreferrer">a link containing the specified css class and two other random css classes</a>.'))
|
175
173
|
end
|
176
174
|
end
|
177
175
|
|
178
|
-
context
|
179
|
-
let(:target_blank_add_css_class) {
|
176
|
+
context 'Adds a CSS classes to the links' do
|
177
|
+
let(:target_blank_add_css_class) { 'some-class' }
|
180
178
|
let(:config_overrides) do
|
181
|
-
{
|
179
|
+
{ 'target-blank' => { 'add_css_classes' => target_blank_add_css_class } }
|
182
180
|
end
|
183
181
|
|
184
|
-
it
|
182
|
+
it 'should add the CSS class specified in config' do
|
185
183
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer" class="some-class">Google</a>.'))
|
186
184
|
end
|
187
185
|
|
188
|
-
it
|
186
|
+
it 'should add the CSS class specified in config even when the link already has a CSS class specified' do
|
189
187
|
expect(post_with_html_link_containing_the_specified_css_class.output).to include(para('<a href="https://google.com" class="some-class ext-link" target="_blank" rel="noopener noreferrer">Link with the css class specified in config</a>.'))
|
190
188
|
end
|
191
189
|
|
192
|
-
it
|
190
|
+
it 'should add the CSS class specified in config even when the link has more than CSS classes already included' do
|
193
191
|
expect(post_with_external_link_containing_the_specified_css_class_and_other_css_classes.output).to include(para('This is <a href="https://not-keith-mifsud.me" class="some-class random-class ext-link another-random-class" target="_blank" rel="noopener noreferrer">a link containing the specified css class and two other random css classes</a>.'))
|
194
192
|
end
|
195
193
|
end
|
196
194
|
|
197
|
-
context
|
198
|
-
it
|
195
|
+
context 'When more than one CSS classes are specified in config' do
|
196
|
+
it 'should add the CSS classes specified in config' do
|
199
197
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer" class="some-class other-some-class another-some-class">Google</a>.'))
|
200
198
|
end
|
201
199
|
|
202
|
-
it
|
200
|
+
it 'should add the CSS classes specified in config even when the link already has a CSS class included' do
|
203
201
|
expect(post_with_html_link_containing_the_specified_css_class.output).to include(para('<a href="https://google.com" class="some-class other-some-class another-some-class ext-link" target="_blank" rel="noopener noreferrer">Link with the css class specified in config</a>.'))
|
204
202
|
end
|
205
203
|
|
206
|
-
it
|
204
|
+
it 'should add the CSS classes specified in config even when the link already has more than one CSS classes included' do
|
207
205
|
expect(post_with_external_link_containing_the_specified_css_class_and_other_css_classes.output).to include(para('This is <a href="https://not-keith-mifsud.me" class="some-class other-some-class another-some-class random-class ext-link another-random-class" target="_blank" rel="noopener noreferrer">a link containing the specified css class and two other random css classes</a>.'))
|
208
206
|
end
|
209
207
|
end
|
210
208
|
|
211
|
-
context
|
209
|
+
context 'When noopener is set to false in config' do
|
212
210
|
let(:noopener) { false }
|
213
211
|
let(:config_overrides) do
|
214
212
|
{
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
}
|
213
|
+
'target-blank' => {
|
214
|
+
'add_css_classes' => false,
|
215
|
+
'noopener' => noopener
|
216
|
+
}
|
219
217
|
}
|
220
218
|
end
|
221
219
|
|
222
|
-
it
|
220
|
+
it 'should not add noopener value to the rel attribute' do
|
223
221
|
expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.'))
|
224
222
|
end
|
225
223
|
|
226
|
-
it
|
224
|
+
it 'should still add noreferrer value to the rel attribute' do
|
227
225
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer">Google</a>.'))
|
228
226
|
end
|
229
227
|
end
|
230
228
|
|
231
|
-
context
|
229
|
+
context 'When noreferrer is set to false in config' do
|
232
230
|
let(:noreferrer) { false }
|
233
231
|
let(:config_overrides) do
|
234
232
|
{
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
}
|
233
|
+
'target-blank' => {
|
234
|
+
'add_css_classes' => false,
|
235
|
+
'noreferrer' => noreferrer
|
236
|
+
}
|
239
237
|
}
|
240
238
|
end
|
241
239
|
|
242
|
-
it
|
240
|
+
it 'should not add noreferrer value to the rel attribute' do
|
243
241
|
expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.'))
|
244
242
|
end
|
245
243
|
|
246
|
-
it
|
244
|
+
it 'should still add noopener value to the rel attribute' do
|
247
245
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener">Google</a>.'))
|
248
246
|
end
|
249
247
|
end
|
250
248
|
|
251
|
-
context
|
249
|
+
context 'When both noopener and noreferrer values are set to false in config' do
|
252
250
|
let(:noopener) { false }
|
253
251
|
let(:noreferrer) { false }
|
254
252
|
let(:config_overrides) do
|
255
253
|
{
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
}
|
254
|
+
'target-blank' => {
|
255
|
+
'add_css_classes' => false,
|
256
|
+
'noopener' => noopener,
|
257
|
+
'noreferrer' => noreferrer
|
258
|
+
}
|
261
259
|
}
|
262
260
|
end
|
263
261
|
|
264
|
-
it
|
262
|
+
it 'should not include the rel attribute values' do
|
265
263
|
expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.'))
|
266
264
|
end
|
267
265
|
|
268
|
-
it
|
266
|
+
it 'should not include the rel attribute noopener value' do
|
269
267
|
expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer">Google</a>.'))
|
270
268
|
end
|
271
269
|
|
272
|
-
it
|
270
|
+
it 'should not include the rel attribute noreferrer value' do
|
273
271
|
expect(post_with_external_markdown_link.output).to_not include(para('Link to <a href="https://google.com" target="_blank" rel="noopener">Google</a>.'))
|
274
272
|
end
|
275
273
|
|
276
|
-
it
|
274
|
+
it 'should not include any rel attributes' do
|
277
275
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank">Google</a>.'))
|
278
276
|
end
|
279
277
|
end
|
280
278
|
|
281
|
-
context
|
282
|
-
let(:rel_attribute) {
|
279
|
+
context 'When one additional rel attribute is added in config' do
|
280
|
+
let(:rel_attribute) { 'nofollow' }
|
283
281
|
let(:config_overrides) do
|
284
282
|
{
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
}
|
283
|
+
'target-blank' => {
|
284
|
+
'add_css_classes' => false,
|
285
|
+
'rel' => rel_attribute
|
286
|
+
}
|
289
287
|
}
|
290
288
|
end
|
291
289
|
|
292
|
-
it
|
290
|
+
it 'should add the extra rel attribute together with the default ones' do
|
293
291
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer nofollow">Google</a>.'))
|
294
292
|
end
|
295
293
|
end
|
296
294
|
|
297
|
-
context
|
298
|
-
let(:rel_attribute) {
|
295
|
+
context 'When more than one additional rel attributes are added in config' do
|
296
|
+
let(:rel_attribute) { 'nofollow tag' }
|
299
297
|
let(:config_overrides) do
|
300
298
|
{
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
}
|
299
|
+
'target-blank' => {
|
300
|
+
'add_css_classes' => false,
|
301
|
+
'rel' => rel_attribute
|
302
|
+
}
|
305
303
|
}
|
306
304
|
end
|
307
305
|
|
308
|
-
it
|
306
|
+
it 'should add the extra rel attributes together with the default ones' do
|
309
307
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer nofollow tag">Google</a>.'))
|
310
308
|
end
|
311
309
|
end
|
312
310
|
|
313
|
-
context
|
314
|
-
let(:rel_attribute) {
|
311
|
+
context 'When one extra rel attribute value are set in config and noopener is set to false' do
|
312
|
+
let(:rel_attribute) { 'nofollow' }
|
315
313
|
let(:noopener) { false }
|
316
314
|
let(:config_overrides) do
|
317
315
|
{
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
}
|
316
|
+
'target-blank' => {
|
317
|
+
'add_css_classes' => false,
|
318
|
+
'noopener' => noopener,
|
319
|
+
'rel' => rel_attribute
|
320
|
+
}
|
323
321
|
}
|
324
322
|
end
|
325
323
|
|
326
|
-
it
|
324
|
+
it 'should the extra rel attribute value and not add the default noopener value' do
|
327
325
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer nofollow">Google</a>.'))
|
328
326
|
end
|
329
327
|
end
|
330
328
|
|
331
|
-
context
|
332
|
-
let(:rel_attribute) {
|
329
|
+
context 'When more than one extra rel attribute values are set in config and noopener is set to false' do
|
330
|
+
let(:rel_attribute) { 'nofollow tag' }
|
333
331
|
let(:noopener) { false }
|
334
332
|
let(:config_overrides) do
|
335
333
|
{
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
}
|
334
|
+
'target-blank' => {
|
335
|
+
'add_css_classes' => false,
|
336
|
+
'noopener' => noopener,
|
337
|
+
'rel' => rel_attribute
|
338
|
+
}
|
341
339
|
}
|
342
340
|
end
|
343
341
|
|
344
|
-
it
|
342
|
+
it 'should the extra rel attribute values and not add the default noopener value' do
|
345
343
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer nofollow tag">Google</a>.'))
|
346
344
|
end
|
347
345
|
end
|
348
346
|
|
349
|
-
context
|
350
|
-
let(:rel_attribute) {
|
347
|
+
context 'When one extra rel attributes is set in config and both noopener and noreferer are set to false' do
|
348
|
+
let(:rel_attribute) { 'nofollow' }
|
351
349
|
let(:noopener) { false }
|
352
350
|
let(:noreferrer) { false }
|
353
351
|
let(:config_overrides) do
|
354
352
|
{
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
}
|
353
|
+
'target-blank' => {
|
354
|
+
'add_css_classes' => false,
|
355
|
+
'noopener' => noopener,
|
356
|
+
'noreferrer' => noreferrer,
|
357
|
+
'rel' => rel_attribute
|
358
|
+
}
|
361
359
|
}
|
362
360
|
end
|
363
361
|
|
364
|
-
it
|
362
|
+
it 'should add the extra rel attribute value and no default ones' do
|
365
363
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="nofollow">Google</a>.'))
|
366
364
|
end
|
367
365
|
end
|
368
366
|
|
369
|
-
context
|
370
|
-
let(:rel_attribute) {
|
367
|
+
context 'When more than one extra rel attribute values are set in config and both noopener and noreferer are set to false' do
|
368
|
+
let(:rel_attribute) { 'nofollow tag' }
|
371
369
|
let(:noopener) { false }
|
372
370
|
let(:noreferrer) { false }
|
373
371
|
let(:config_overrides) do
|
374
372
|
{
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
}
|
373
|
+
'target-blank' => {
|
374
|
+
'add_css_classes' => false,
|
375
|
+
'noopener' => noopener,
|
376
|
+
'noreferrer' => noreferrer,
|
377
|
+
'rel' => rel_attribute
|
378
|
+
}
|
381
379
|
}
|
382
380
|
end
|
383
381
|
|
384
|
-
it
|
382
|
+
it 'should add the extra rel attribute values and no default ones' do
|
385
383
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="nofollow tag">Google</a>.'))
|
386
384
|
end
|
387
385
|
end
|
388
386
|
|
389
|
-
context
|
390
|
-
let(:rel_attribute) {
|
387
|
+
context 'When noopener is set to false in config but added to the rel config property' do
|
388
|
+
let(:rel_attribute) { 'noopener' }
|
391
389
|
let(:noopener) { false }
|
392
390
|
let(:config_overrides) do
|
393
391
|
{
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
}
|
392
|
+
'target-blank' => {
|
393
|
+
'add_css_classes' => false,
|
394
|
+
'noopener' => noopener,
|
395
|
+
'rel' => rel_attribute
|
396
|
+
}
|
399
397
|
}
|
400
398
|
end
|
401
399
|
|
402
|
-
it
|
400
|
+
it 'should still include the noopener rel attribute value' do
|
403
401
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer noopener">Google</a>.'))
|
404
402
|
end
|
405
403
|
end
|
406
404
|
|
407
|
-
context
|
408
|
-
let(:rel_attribute) {
|
405
|
+
context 'When noopener is set to false in config but added t0 the rel config property alongside one more extra rel attribute value.' do
|
406
|
+
let(:rel_attribute) { 'noopener nofollow' }
|
409
407
|
let(:noopener) { false }
|
410
408
|
let(:config_overrides) do
|
411
409
|
{
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
}
|
410
|
+
'target-blank' => {
|
411
|
+
'add_css_classes' => false,
|
412
|
+
'noopener' => noopener,
|
413
|
+
'rel' => rel_attribute
|
414
|
+
}
|
417
415
|
}
|
418
416
|
end
|
419
417
|
|
420
|
-
it
|
418
|
+
it 'should still include the noopener rel attribute value along the extra one' do
|
421
419
|
expect(post_with_external_markdown_link.output).to include(para('Link to <a href="https://google.com" target="_blank" rel="noreferrer noopener nofollow">Google</a>.'))
|
422
420
|
end
|
423
421
|
end
|
@@ -425,22 +423,22 @@ RSpec.describe(Jekyll::TargetBlank) do
|
|
425
423
|
private
|
426
424
|
|
427
425
|
def post_with_layout_result
|
428
|
-
|
429
|
-
<!DOCTYPE HTML>
|
430
|
-
<html lang="en-US">
|
431
|
-
<head>
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
</head>
|
437
|
-
<body class="wrap">
|
438
|
-
|
439
|
-
<p>Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.</p>
|
440
|
-
|
441
|
-
|
442
|
-
</body>
|
443
|
-
</html>
|
426
|
+
<<~RESULT
|
427
|
+
<!DOCTYPE HTML>
|
428
|
+
<html lang="en-US">
|
429
|
+
<head>
|
430
|
+
<meta charset="UTF-8">
|
431
|
+
<title>Post with external markdown link</title>
|
432
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
433
|
+
<link rel="stylesheet" href="/css/screen.css">
|
434
|
+
</head>
|
435
|
+
<body class="wrap">
|
436
|
+
<div>Layout content started.</div>
|
437
|
+
<p>Link to <a href="https://google.com" target="_blank" rel="noopener noreferrer">Google</a>.</p>
|
438
|
+
|
439
|
+
<div>Layout content ended.</div>
|
440
|
+
</body>
|
441
|
+
</html>
|
444
442
|
RESULT
|
445
443
|
end
|
446
444
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path('../lib/jekyll-target-blank.rb', __dir__)
|
4
4
|
|
5
5
|
RSpec.configure do |config|
|
6
|
-
UNIT_FIXTURES_DIR = File.expand_path(
|
6
|
+
UNIT_FIXTURES_DIR = File.expand_path('fixtures/unit', __dir__)
|
7
7
|
|
8
|
-
INTEGRATION_FIXTURES_DIR = File.expand_path(
|
8
|
+
INTEGRATION_FIXTURES_DIR = File.expand_path('fixtures/integration', __dir__)
|
9
9
|
|
10
10
|
def unit_fixtures_dir(*paths)
|
11
11
|
File.join(UNIT_FIXTURES_DIR, *paths)
|
@@ -16,7 +16,7 @@ RSpec.configure do |config|
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def find_by_title(docs, title)
|
19
|
-
docs.find { |d| d.data[
|
19
|
+
docs.find { |d| d.data['title'] == title }
|
20
20
|
end
|
21
21
|
|
22
22
|
# rspec-expectations config goes here. You can use an alternate
|
metadata
CHANGED
@@ -1,43 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-target-blank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Mifsud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '3.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: nokogiri
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.10
|
39
|
+
version: '1.10'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.10
|
46
|
+
version: '1.10'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: bundler
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,16 +90,30 @@ dependencies:
|
|
84
90
|
name: rubocop
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
|
-
- -
|
93
|
+
- - "~>"
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
95
|
+
version: '1'
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
|
-
- -
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rubocop-jekyll
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.12.0
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
95
115
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
116
|
+
version: 0.12.0
|
97
117
|
description: Target Blank automatically changes the external links to open in a new
|
98
118
|
browser for Jekyll sites.
|
99
119
|
email:
|
@@ -157,8 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
177
|
- !ruby/object:Gem::Version
|
158
178
|
version: '0'
|
159
179
|
requirements: []
|
160
|
-
|
161
|
-
rubygems_version: 2.7.6
|
180
|
+
rubygems_version: 3.3.5
|
162
181
|
signing_key:
|
163
182
|
specification_version: 4
|
164
183
|
summary: Target Blank automatically changes the external links to open in a new browser.
|