jekyll_href 1.2.10 → 1.2.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ff34de3543f22694104004179a170c7eccaed4ab74c8c454d5d6f9e7e1b95b6
4
- data.tar.gz: cba2381032c48b897e1f1835ce2484b0b5d1c589d077359bade41be88984c9f8
3
+ metadata.gz: 9b91d0d8398def7c990920615a1e12f97de4472f5444ae9fc3869504d49084b8
4
+ data.tar.gz: 19f84b38dc1f3205763a1be316671bad0ac65a3af25621e5455164f362c39ec8
5
5
  SHA512:
6
- metadata.gz: ca46777a4c3d5bd9eeb1b859715d73f45ea793d97b183a862e25eb78c8688387bc91d25ca353c21cfe7b734e4a9aa74d5c12a163872b07dcd3cc1ca179393a18
7
- data.tar.gz: 25a5d7c61e1baf54b767a0b1824c263a52f0bfdf054a428b5290f655ca4c9fe701c633406c8c6da165d14bc0852a1b21a7fcba0f9e1dce03c10fb50917796259
6
+ metadata.gz: 92e483de85abd7cfdf2aeede0de99d0cc0772d3d112b6652394f04f3f97f52d6aaa2b4f39ac150c02cbd25d0162b56809b8c8dec1a356d5a9777b86d888b21aa
7
+ data.tar.gz: fd835168ec7beb443ea70c646aac51cb80b4ab9a9826f881b74ee0af6670ad9ffe74937e3e063f762f44b32d7c060f4c69faeda6d8fe0935fd68525c8d3dbdf2
data/.rubocop.yml CHANGED
@@ -37,6 +37,9 @@ Metrics/BlockLength:
37
37
  - jekyll_plugin_support.gemspec
38
38
  Max: 30
39
39
 
40
+ Metrics/ClassLength:
41
+ Max: 150
42
+
40
43
  Metrics/CyclomaticComplexity:
41
44
  Max: 25
42
45
 
data/CHANGELOG.md CHANGED
@@ -1,9 +1,20 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.2.12 / 2024-08-17
4
+
5
+ * Enhanced `match` so that if no label parameter is provided, the title of the matched web page is used.
6
+ * Now dependent on jekyll_plugin_support v1.0.2+ for better error handling.
7
+
8
+
9
+ ## 1.2.11 / 2024-07-27
10
+
11
+ * Fixed an unqualified reference to `JekyllPluginHelper`.
12
+ * Shortened the very long stack dump for an error condition.
13
+
3
14
 
4
15
  ## 1.2.10 / 2024-07-23
5
16
 
6
- * Make compatible with jekyll_plugin_support 1.0.0
17
+ * Make compatible with `jekyll_plugin_support` 1.0.0
7
18
 
8
19
 
9
20
  ## 1.2.9 / 2024-07-17
data/README.md CHANGED
@@ -46,7 +46,22 @@ href_summary:
46
46
  pry_on_href_error: true # Default value is false
47
47
  ```
48
48
 
49
- ## Syntax 1 (requires `url` without embedded spaces)
49
+ ## Suppprted Syntaxes
50
+
51
+ Square brackets in the [BNF notation](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form)
52
+ below denote optional keyword parameters, and are not meant to be typed.
53
+
54
+ ## Syntax 1 (most verbose, but provides best results and enables implicit matching title)
55
+
56
+ ```html
57
+ {% href [match | [follow] [blank|notarget] [summary_exclude]] url="local_page.html" label="text to display" %}
58
+ ```
59
+
60
+ 1. The url can be #relative, a page in the Jekyll website, or prefaced with a protocol, such as `https:`
61
+ 2. If `match` is provided, and `label` is not provided, then the title of the matched page is used as the label.
62
+
63
+
64
+ ## Syntax 2 (requires `url` without embedded spaces)
50
65
 
51
66
  ```html
52
67
  {% href [match | [follow] [blank|notarget] [page_title] [summary_exclude]] url text to display %}
@@ -54,10 +69,9 @@ href_summary:
54
69
 
55
70
  1. The url must be a single token, without embedded spaces.
56
71
  2. The url need not be enclosed in quotes.
57
- 3. The square brackets denote optional keyword parameters, and should not be typed.
58
72
 
59
73
 
60
- ## Syntax 2 (always works)
74
+ ## Syntax 3 (always works)
61
75
 
62
76
  This syntax is recommended when the URL contains a colon (:).
63
77
 
@@ -68,10 +82,9 @@ This syntax is recommended when the URL contains a colon (:).
68
82
 
69
83
  1. Each of the above examples contain an embedded newline, which is legal.
70
84
  2. The url must be enclosed by either single or double quotes.
71
- 3. The square brackets denote optional keyword parameters, and should not be typed.
72
85
 
73
86
 
74
- ## Syntax 3 (implicit URL)
87
+ ## Syntax 4 (implicit URL)
75
88
 
76
89
  ```html
77
90
  {% href [match | [follow] [blank|notarget] [page_title] [summary_exclude]] [shy|wbr] www.domain.com %}
@@ -287,6 +300,21 @@ Expands to:
287
300
 
288
301
  Substitutions are only made to the URL, not to the linked text.
289
302
 
303
+ 8. Dollar signs
304
+
305
+ If the URL has a dollar sign in it, jekyll_href will attempt to replace an environment variable with its value.
306
+ That will likely fail silently. To work around the problem, replace dollar signs in URLs with $.
307
+
308
+ For example, given this URL:
309
+ https://ammonite.io/#import$ivy
310
+ rewrite as:
311
+ https://ammonite.io/#import$ivy.
312
+
313
+ Here is a complete invocation:
314
+
315
+ {% href url="https://ammonite.io/#import$ivy"
316
+ label="<code>import &dollar;ivy</code>" %}
317
+
290
318
 
291
319
  ## References Generation
292
320
 
data/jekyll_href.gemspec CHANGED
@@ -33,6 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency 'ipaddress'
34
34
  spec.add_dependency 'jekyll', '>= 3.5.0'
35
35
  spec.add_dependency 'jekyll_all_collections'
36
- spec.add_dependency 'jekyll_plugin_support', '>= 1.0.0'
36
+ spec.add_dependency 'jekyll_plugin_support', '>= 1.0.2'
37
37
  spec.add_dependency 'typesafe_enum'
38
38
  end
data/lib/hash_array.rb CHANGED
@@ -6,7 +6,7 @@ module HashArray
6
6
 
7
7
  def add_link_for_page(href, hash)
8
8
  enclosing_page = href.path
9
- hash[enclosing_page] = [] if hash[enclosing_page].nil?
9
+ hash[enclosing_page] = hash[enclosing_page] || []
10
10
  pre_existing = hash[enclosing_page].find { |h| h.link_save == href.link_save }
11
11
  if pre_existing
12
12
  if pre_existing.follow != href.follow
data/lib/href_match.rb CHANGED
@@ -1,20 +1,24 @@
1
- module MSlinn
1
+ module JekyllSupport
2
2
  class HRefTag
3
3
  private
4
4
 
5
- def compute_link_and_text(all_urls)
6
- url_matches = all_urls.select { |url| url&.include? @path }
7
- case url_matches.length
5
+ def compute_link_and_text
6
+ page_matches = @site.all_collections.map.select { |page| page.url&.include? @path }
7
+ case page_matches.length
8
8
  when 0
9
- abort "href error: No url matches '#{@link}', found on line #{@line_number} (after front matter) of #{@path}" if @die_if_nomatch
9
+ msg = "HRef error: No url matches '#{@link}', found on line #{@line_number} (after front matter) of #{@path}"
10
+ @logger.error { msg }
11
+ abort msg if @die_if_nomatch
12
+ @text = "<i class='h_ref_error'>#{@link} is not available</i>"
10
13
  @link_save = @link = '#'
11
- @text = "<i>#{@link} is not available</i>"
12
14
  when 1
13
- @link = url_matches.first
15
+ @link = page_matches.first.url
14
16
  @link = "#{@link}##{@fragment}" if @fragment
15
17
  @link_save = @link
18
+ @text = page_matches.first.title unless @label
16
19
  else
17
- abort "Error: More than one url matched '#{@path}': #{url_matches.join(', ')}"
20
+ logger.error { "Error: More than one url matched '#{@path}': #{url_matches.join(', ')}" }
21
+ exit! 2
18
22
  end
19
23
  end
20
24
 
@@ -31,8 +35,7 @@ module MSlinn
31
35
  END_DEBUG
32
36
  end
33
37
 
34
- all_urls = @site.all_collections.map(&:url)
35
- compute_link_and_text(all_urls)
38
+ compute_link_and_text
36
39
  end
37
40
  end
38
41
  end
@@ -1,4 +1,4 @@
1
- module MSlinn
1
+ module JekyllSupport
2
2
  class HRefTag
3
3
  private
4
4
 
data/lib/href_private.rb CHANGED
@@ -1,4 +1,4 @@
1
- module MSlinn
1
+ module JekyllSupport
2
2
  class HRefTag
3
3
  private
4
4
 
@@ -25,8 +25,8 @@ module MSlinn
25
25
  No URL was provided on #{@path}:#{@line_number} (after front matter).
26
26
  <pre>{% href #{@argument_string.strip} %}</pre>
27
27
  END_MESSAGE
28
- @logger.error { JekyllPluginHelper.remove_html_tags msg.strip }
29
- "<div class='href_error'>HRefError: #{msg}</div>"
28
+ @logger.error { JekyllSupport::JekyllPluginHelper.remove_html_tags msg.strip }
29
+ "<div class='h_ref_error'>HRefError: #{msg}</div>"
30
30
  end
31
31
 
32
32
  # Sets @follow, @helper, @match, @path, @target, @url, @hyphenation
data/lib/href_summary.rb CHANGED
@@ -1,4 +1,4 @@
1
- module MSlinn
1
+ module JekyllSupport
2
2
  class HRefTag
3
3
  private
4
4
 
@@ -2,10 +2,8 @@ require 'jekyll_plugin_logger'
2
2
  require 'jekyll_plugin_support'
3
3
  require_relative 'jekyll_href/version'
4
4
 
5
- module MSlinn
6
- class HrefSummary < JekyllSupport::JekyllTag
7
- include JekyllHrefVersion
8
-
5
+ module JekyllSupport
6
+ class HrefSummary < JekyllTag
9
7
  # Class instance variables accumulate hrefs across invocations.
10
8
  # These are hashes of arrays;
11
9
  # the hash keys are page paths (strings) and the hash values are arrays of HRefTags.
@@ -42,13 +40,10 @@ module MSlinn
42
40
  #{@helper.attribute if @helper.attribution && have_refs}
43
41
  END_RENDER
44
42
  rescue HRefError => e # jekyll_plugin_support handles StandardError
45
- e.shorten_backtrace
46
- msg = format_error_message e.message
47
- @logger.error "#{e.class} raised #{msg}"
48
- binding.pry if @pry_on_img_error # rubocop:disable Lint/Debugger
49
- raise e if @die_on_href_error
43
+ @logger.error { e.logger_message }
44
+ exit! 1 if @die_on_demo_block_error
50
45
 
51
- "<div class='href_error'>#{e.class} raised in #{self.class};\n#{msg}</div>"
46
+ e.html_message
52
47
  end
53
48
 
54
49
  def render_global_refs
@@ -85,6 +80,6 @@ module MSlinn
85
80
  END_RENDER
86
81
  end
87
82
 
88
- ::JekyllSupport::JekyllPluginHelper.register(self, 'href_summary')
83
+ JekyllSupport::JekyllPluginHelper.register(self, 'href_summary')
89
84
  end
90
85
  end
data/lib/href_tag.rb CHANGED
@@ -11,13 +11,13 @@ require_relative 'hash_array'
11
11
  # @license SPDX-License-Identifier: Apache-2.0
12
12
  # Generates an href.
13
13
 
14
- module MSlinn
14
+ module JekyllSupport
15
15
  MiniHref = Struct.new(:follow, :html, :link, :line_number, :link_save, :path, :summary_exclude, :summary_href, keyword_init: true)
16
16
 
17
17
  HRefError = JekyllSupport.define_error
18
18
 
19
19
  # Implements href Jekyll tag
20
- class HRefTag < JekyllSupport::JekyllTag
20
+ class HRefTag < JekyllTag
21
21
  attr_reader :follow, :helper, :line_number, :link_save, :match, :page, :path, :site,
22
22
  :summary, :summary_exclude, :summary_href, :target, :text, :url
23
23
  attr_accessor :link
@@ -46,29 +46,25 @@ module MSlinn
46
46
 
47
47
  @helper_save = @helper.clone
48
48
  globals_update(@helper.argv, linkk) # Sets @link and @text, might clear @follow and @target
49
- handle_match(@link) if @match
50
- raise HrefError, "@link_type was not set" if @link_type == LinkType::UNKNOWN
49
+ handle_match(linkk) if @match # Sets @text if not set by now
50
+ raise HrefError, '@link_type was not set' if @link_type == LinkType::UNKNOWN
51
51
 
52
52
  save_summary
53
53
  klass = " class='#{@klass}'" if @klass
54
54
  style = " style='#{@style}'" if @style
55
55
  "<a href='#{@link}'#{klass}#{style}#{@target}#{@follow}>#{@text}</a>"
56
56
  rescue HRefError => e # jekyll_plugin_support handles StandardError
57
- msg = format_error_message "#{e.message}\n<pre> {% href #{@argument_string.strip} %}</pre>"
58
- @text = "<div class='href_error'>#{msg}</div>"
59
- e.shorten_backtrace
60
- @logger.error "#{e.class} raised #{msg}"
61
- binding.pry if @pry_on_img_error # rubocop:disable Lint/Debugger
62
- raise e if @die_on_href_error
57
+ @logger.error { e.logger_message }
58
+ exit 1 if @die_on_demo_tag_error
63
59
 
64
- "<div class='href_error'>#{e.class} raised in #{self.class};\n#{msg}</div>"
60
+ e.html_message
65
61
  end
66
62
 
67
63
  def to_s
68
64
  "On line #{line_number} of #{path}: #{follow} #{match} #{target} #{link} => '#{text}'"
69
65
  end
70
66
 
71
- ::JekyllSupport::JekyllPluginHelper.register(self, 'href')
67
+ JekyllSupport::JekyllPluginHelper.register(self, 'href')
72
68
  end
73
69
  end
74
70
 
@@ -1,3 +1,3 @@
1
1
  module JekyllHrefVersion
2
- VERSION = '1.2.10'.freeze
2
+ VERSION = '1.2.12'.freeze
3
3
  end
data/lib/jekyll_href.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  require_relative 'href_tag'
2
2
  require_relative 'href_summary_tag'
3
3
 
4
- HrefError = Class.new Liquid::Error
5
-
6
- module JekyllHrefModule
7
- include MSlinn
4
+ module JekyllSupport
8
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_href
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.10
4
+ version: 1.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-26 00:00:00.000000000 Z
11
+ date: 2024-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ipaddress
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 1.0.0
61
+ version: 1.0.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 1.0.0
68
+ version: 1.0.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: typesafe_enum
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  requirements: []
139
- rubygems_version: 3.5.16
139
+ rubygems_version: 3.5.17
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'.