jekyll_href 1.2.2 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e9e6357f4c5f4d4dd7815aab9142ab5dadfbc48b3ba719fdc6b1cd70265d3d3
4
- data.tar.gz: '068d3c6821f1f8578fee4331179be452ad50fdfd620cc990a0dbdb1359f605cc'
3
+ metadata.gz: 13925ae2b44abe077101e5302d6aee8a640cdf3c50dcb4a29c76e2c355dae039
4
+ data.tar.gz: cf41c3a1c8424fc3e3ba67ccf6f27238e71766c72ed7006442291d855a933c4f
5
5
  SHA512:
6
- metadata.gz: d4411b3c9cfad7062eb75206f487e6e1a5589874479ae09815d044177069fd567b069875b9fabd4018dc9aafed9dc5dcc656354917c90935311ee958b6c1d5c2
7
- data.tar.gz: abc4e78a0745ab9f455c5e1a1f85d0a41aa85c242f155c8d064503d5682df69806ef98c06c838833d37b1d3468713d5a21e798b7bf33570d48e2e27f76450fb8
6
+ metadata.gz: afa3c62bf2806362a3e52d6978a8ea9ad3b5eb21e5f685b5328c04c0e19728e680a58961bd0daac805fcfbef1f031e98c6de769b085c9c8e4f058a209793c325
7
+ data.tar.gz: ce210b8cecefb1282991e9f4cca6ca5f80e7d94b9738f875f4848e9c445e24744e57c5a93f099e83362ed6e10448a38499f1907b96a04ef402db63710589f2aa
data/.rubocop.yml CHANGED
@@ -64,7 +64,7 @@ Metrics/MethodLength:
64
64
  Max: 40
65
65
 
66
66
  Metrics/PerceivedComplexity:
67
- Max: 15
67
+ Max: 20
68
68
 
69
69
  Naming/FileName:
70
70
  Exclude:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.2.4 / 2023-05-18
2
+ * When only a URI is provided, the plugin now generates the `http` scheme for IP4 & IP6 loopback addresses like
3
+ `localhost`, and `127.0.0.0`, as well as private IP4 addresses like 192.168.0.0 and 172.16.0.0;
4
+ otherwise it generates the `https` scheme.
5
+
6
+ ## 1.2.3 / 2023-05-16
7
+ * Added `label` option.
8
+
1
9
  ## 1.2.2 / 2023-03-25
2
10
  * Added **References** capability:
3
11
  * Added `summary_exclude` keyword option to `href` tag.
data/README.md CHANGED
@@ -85,6 +85,15 @@ If both are specified, `blank` prevails.
85
85
  ### `follow`
86
86
  To suppress the `nofollow` attribute, preface the link with the word `follow`.
87
87
 
88
+ ### `label='whatever you want'`
89
+ If the text to be linked contains an optional keyword argument,
90
+ for example `summary`, that word will be removed from the displayed link text,
91
+ unless the link text is provided via the `label` option.
92
+ Both of the following produce the same output:
93
+ ```
94
+ {% href https://mslinn.com label="This is a summary" %}
95
+ {% href label="This is a summary" https://mslinn.com %}
96
+ ```
88
97
 
89
98
  ### `notarget`
90
99
  To suppress the `target` attribute, preface the link with the word `notarget`.
@@ -130,6 +139,7 @@ Expands to:
130
139
  ### `summary`
131
140
  The `summary` name/value option provides an override for the linked text in the **References** section
132
141
  generated by the `{% href_summary %}` tag.
142
+ If the value is the empty string, or no value is provided, the `href` tag is not included in the page summary.
133
143
 
134
144
 
135
145
  ### `summary_exclude`
data/jekyll_href.gemspec CHANGED
@@ -28,9 +28,9 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ['lib']
29
29
  spec.required_ruby_version = '>= 2.6.0'
30
30
  spec.summary = "Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'."
31
- spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
32
31
  spec.version = JekyllHrefVersion::VERSION
33
32
 
33
+ spec.add_dependency 'ipaddress'
34
34
  spec.add_dependency 'jekyll', '>= 3.5.0'
35
35
  spec.add_dependency 'jekyll_all_collections', '~> 0.3.0', '>= 0.3.1'
36
36
  spec.add_dependency 'jekyll_plugin_support', '~> 0.6.0', '>= 0.6.1'
data/lib/href_tag.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'ipaddress'
1
2
  require 'jekyll_all_collections'
2
3
  require 'jekyll_plugin_logger'
3
4
  require 'jekyll_plugin_support'
@@ -55,6 +56,17 @@ module HrefTag
55
56
  return if @summary_exclude || @link_save.start_with?('mailto:') || @link_save.start_with?('#')
56
57
 
57
58
  @summary = @summary.to_s.empty? ? @text : @summary.to_s
59
+ if @summary == true
60
+ warning = <<~END_WARNING
61
+ Warning: a href plugin keyword option was detected in the link text for #{@path} on line #{line_number}.
62
+ The href tag will not be included in the summary, and the link text will not have the word summary included.
63
+ This is probably unintentional. Consider using the label option to correct this problem."
64
+ END_WARNING
65
+ puts warning.red
66
+ return
67
+ end
68
+ return if @summary.class != String || @summary.empty?
69
+
58
70
  @summary = @summary[0].upcase + @summary[1..]
59
71
  @summary_href = "<a href='#{@link_save}'#{@target}#{@follow}>#{@summary}</a>"
60
72
  mini_href = MiniHref.new(
@@ -109,9 +121,10 @@ module HrefTag
109
121
  @path = @page['path']
110
122
  AllCollectionsHooks.compute(@site)
111
123
 
124
+ @blank = @helper.parameter_specified? 'blank'
112
125
  @follow = @helper.parameter_specified?('follow') ? '' : " rel='nofollow'"
113
126
  @match = @helper.parameter_specified? 'match'
114
- @blank = @helper.parameter_specified? 'blank'
127
+ @label = @helper.parameter_specified? 'label'
115
128
  @summary_exclude = @helper.parameter_specified? 'summary_exclude'
116
129
  @shy = @helper.parameter_specified? 'shy'
117
130
  @summary = @helper.parameter_specified? 'summary'
@@ -133,13 +146,19 @@ module HrefTag
133
146
  end
134
147
  return
135
148
  else
136
- @text = tokens.join(' ').strip
149
+ @text = @label || tokens.join(' ').strip
137
150
  if @text.to_s.empty?
138
151
  text = linkk
139
152
  text = linkk.gsub('/', '/&shy;') if @shy
140
153
  text = linkk.gsub('/', '/<wbr>') if @wbr
141
154
  @text = "<code>#{text}</code>"
142
- @link = linkk.start_with?('http') ? linkk : "https://#{linkk}"
155
+ @link = if linkk.start_with?('http')
156
+ linkk
157
+ elsif insecure_ip_address linkk
158
+ "http://#{linkk}"
159
+ else
160
+ "https://#{linkk}"
161
+ end
143
162
  else
144
163
  @link = if @shy
145
164
  linkk.gsub('/', '/&shy;')
@@ -198,6 +217,19 @@ module HrefTag
198
217
  end
199
218
  end
200
219
 
220
+ def insecure_ip_address(string)
221
+ return true if string.start_with? 'localhost'
222
+
223
+ return false unless IPAddress.valid? string
224
+
225
+ ip_address = IPAddress string
226
+ return true if ip_address.loopback? || ip_address.private?
227
+ rescue StandardError
228
+ false
229
+ ensure
230
+ false
231
+ end
232
+
201
233
  # Replace names in plugin-vars with values
202
234
  def replace_vars(text)
203
235
  variables = @site.config['plugin-vars']
@@ -1,3 +1,3 @@
1
1
  module JekyllHrefVersion
2
- VERSION = '1.2.2'.freeze
2
+ VERSION = '1.2.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_href
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-13 00:00:00.000000000 Z
11
+ date: 2023-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ipaddress
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: jekyll
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -119,9 +133,5 @@ rubygems_version: 3.3.3
119
133
  signing_key:
120
134
  specification_version: 4
121
135
  summary: Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'.
122
- test_files:
123
- - spec/hash_array_spec.rb
124
- - spec/href_spec.rb
125
- - spec/spec_helper.rb
126
- - spec/status_persistence.txt
136
+ test_files: []
127
137
  ...