jekyll_href 1.2.11 → 1.2.13

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: 79cf3cccc7fc8072d6b2f7ae73d59845633f48026e0d0923d9749fbdcdd75ddf
4
- data.tar.gz: 3e93f0d18068f86997210ddd93a3d90f899f28d82dd130c08177f4c70915e315
3
+ metadata.gz: 15395e432574a69be4a28def40f3c20bf199fa762f8ca94155408e864921c406
4
+ data.tar.gz: 4d7385465ad6ddd8b9f52c6efbb62f7fd757015d10f23017e63639ddfc8e6670
5
5
  SHA512:
6
- metadata.gz: acafa56a136b24199a00febabfc2ff420974ae0d3e09eb6a772ce482691adc1709a765cc7a8e78ce7160eff6c819da8e72350c52160a8dc0c615cef4ee4063dc
7
- data.tar.gz: c0c4e34adb9ef314b270f742860ee52ddcc82855f031693233ae8516d69e86c107bd0ed415958a872356e52e3afae58f5e82c53a4d43d5a8ae03a992b7f53adb
6
+ metadata.gz: 595817a332ef1fe8044249f075efc94a8fc6ba4f284ba2d97ef504d72cabf63799831c808e8450fe6c935d859c5296dda3805e42fd3ada764be2fe2c9985b616
7
+ data.tar.gz: 07b1e783d4b0015097229fda3a2257fdfc8b7b523673f212bdde3c7423eb889badd30a6f36b57c3dcd95eaea321f1f48cdd9db90f96cee167852b6f9b8aa4341
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.2.13 / 2024-12-23
4
+
5
+ * Fixed reference to undefined `url_matches`.
6
+ * References that point to draft pages are rendered differently in production mode,
7
+ and an info-level log message is generated.
8
+
9
+
10
+ ## 1.2.12 / 2024-08-17
11
+
12
+ * Enhanced `match` so that if no label parameter is provided, the title of the matched web page is used.
13
+ * Now dependent on jekyll_plugin_support v1.0.2+ for better error handling.
14
+
3
15
 
4
16
  ## 1.2.11 / 2024-07-27
5
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
@@ -3,15 +3,15 @@ require_relative 'lib/jekyll_href/version'
3
3
  Gem::Specification.new do |spec|
4
4
  github = 'https://github.com/mslinn/jekyll_href'
5
5
 
6
- spec.authors = ['Mike Slinn']
7
- spec.bindir = 'exe'
6
+ spec.authors = ['Mike Slinn']
7
+ spec.bindir = 'exe'
8
8
  spec.description = <<~END_OF_DESC
9
9
  Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'.
10
10
  END_OF_DESC
11
- spec.email = ['mslinn@mslinn.com']
12
- spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
11
+ spec.email = ['mslinn@mslinn.com']
12
+ spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
13
13
  spec.homepage = 'https://www.mslinn.com/jekyll_plugins/jekyll_href.html'
14
- spec.license = 'MIT'
14
+ spec.license = 'MIT'
15
15
  spec.metadata = {
16
16
  'allowed_push_host' => 'https://rubygems.org',
17
17
  'bug_tracker_uri' => "#{github}/issues",
@@ -19,20 +19,21 @@ Gem::Specification.new do |spec|
19
19
  'homepage_uri' => spec.homepage,
20
20
  'source_code_uri' => github,
21
21
  }
22
- spec.name = 'jekyll_href'
22
+ spec.name = 'jekyll_href'
23
+ spec.platform = Gem::Platform::RUBY
23
24
  spec.post_install_message = <<~END_MESSAGE
24
25
 
25
26
  Thanks for installing #{spec.name}!
26
27
 
27
28
  END_MESSAGE
28
- spec.require_paths = ['lib']
29
+ spec.require_paths = ['lib']
29
30
  spec.required_ruby_version = '>= 2.6.0'
30
- spec.summary = "Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'."
31
- spec.version = JekyllHrefVersion::VERSION
31
+ spec.summary = "Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'."
32
+ spec.version = JekyllHrefVersion::VERSION
32
33
 
33
34
  spec.add_dependency 'ipaddress'
34
35
  spec.add_dependency 'jekyll', '>= 3.5.0'
35
36
  spec.add_dependency 'jekyll_all_collections'
36
- spec.add_dependency 'jekyll_plugin_support', '>= 1.0.0'
37
+ spec.add_dependency 'jekyll_plugin_support', '>= 1.0.3'
37
38
  spec.add_dependency 'typesafe_enum'
38
39
  end
data/lib/href_match.rb CHANGED
@@ -2,19 +2,24 @@ 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
+
13
+ @text = "<i class='h_ref_error'>#{@link} is not a valid local page</i>"
10
14
  @link_save = @link = '#'
11
- @text = "<i>#{@link} is not available</i>"
12
15
  when 1
13
- @link = url_matches.first
16
+ @link = page_matches.first.url
14
17
  @link = "#{@link}##{@fragment}" if @fragment
15
18
  @link_save = @link
19
+ @text = page_matches.first.title unless @label
16
20
  else
17
- abort "Error: More than one url matched '#{@path}': #{url_matches.join(', ')}"
21
+ logger.error { "Error: More than one url matched '#{@path}':\n #{page_matches.map(&:url).join("\n ")}" }
22
+ exit! 2
18
23
  end
19
24
  end
20
25
 
@@ -31,8 +36,7 @@ module JekyllSupport
31
36
  END_DEBUG
32
37
  end
33
38
 
34
- all_urls = @site.all_collections.map(&:url)
35
- compute_link_and_text(all_urls)
39
+ compute_link_and_text
36
40
  end
37
41
  end
38
42
  end
data/lib/href_private.rb CHANGED
@@ -26,7 +26,7 @@ module JekyllSupport
26
26
  <pre>{% href #{@argument_string.strip} %}</pre>
27
27
  END_MESSAGE
28
28
  @logger.error { JekyllSupport::JekyllPluginHelper.remove_html_tags msg.strip }
29
- "<div class='href_error'>HRefError: #{msg}</div>"
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
@@ -29,7 +29,7 @@ module JekyllSupport
29
29
  summary_exclude: @summary_exclude,
30
30
  summary_href: @summary_href
31
31
  )
32
- if @link_save.start_with? 'http'
32
+ if @link_type == LinkType::EXTERNAL
33
33
  add_global_link_for_page mini_href
34
34
  else
35
35
  add_local_link_for_page mini_href
@@ -40,13 +40,10 @@ module JekyllSupport
40
40
  #{@helper.attribute if @helper.attribution && have_refs}
41
41
  END_RENDER
42
42
  rescue HRefError => e # jekyll_plugin_support handles StandardError
43
- e.shorten_backtrace
44
- msg = format_error_message e.message
45
- @logger.error "#{e.class} raised #{msg}"
46
- binding.pry if @pry_on_img_error # rubocop:disable Lint/Debugger
47
- raise e if @die_on_href_error
43
+ @logger.error { e.logger_message }
44
+ exit! 1 if @die_on_demo_block_error
48
45
 
49
- "<div class='href_error'>#{e.class} raised in #{self.class};\n#{msg}</div>"
46
+ e.html_message
50
47
  end
51
48
 
52
49
  def render_global_refs
data/lib/href_tag.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'ipaddress'
2
+ require 'jekyll_draft'
2
3
  require 'jekyll_all_collections'
3
4
  require 'jekyll_plugin_logger'
4
5
  require 'jekyll_plugin_support'
@@ -46,29 +47,55 @@ module JekyllSupport
46
47
 
47
48
  @helper_save = @helper.clone
48
49
  globals_update(@helper.argv, linkk) # Sets @link and @text, might clear @follow and @target
49
- handle_match(@link) if @match
50
+ handle_match(linkk) if @match # Sets @text if not set by now, also @link_type, etc.
50
51
  raise HrefError, '@link_type was not set' if @link_type == LinkType::UNKNOWN
51
52
 
52
53
  save_summary
53
54
  klass = " class='#{@klass}'" if @klass
54
55
  style = " style='#{@style}'" if @style
56
+ if @link_type == LinkType::LOCAL && local_page_draft?(@link)
57
+ klass = "draft_link #{klass}".strip
58
+ return "<span #{klass}#{style} title='This page is not available yet.'>#{@text}</span>" if @mode == 'production'
59
+ end
60
+
55
61
  "<a href='#{@link}'#{klass}#{style}#{@target}#{@follow}>#{@text}</a>"
56
62
  rescue HRefError => e # jekyll_plugin_support handles StandardError
57
- msg = format_error_message e.message
58
- msg = "#{msg}\n<pre> {% href #{@argument_string.strip} %}</pre>"
59
- @text = "<div class='href_error'>#{msg}</div>"
60
- e.shorten_backtrace
61
- @logger.error "#{e.class} raised #{msg}"
62
- binding.pry if @pry_on_img_error # rubocop:disable Lint/Debugger
63
- raise e if @die_on_href_error
64
-
65
- "<div class='href_error'>#{e.class} raised in #{self.class};\n#{msg}</div>"
63
+ @logger.error { e.logger_message }
64
+ exit 1 if @die_on_demo_tag_error
65
+
66
+ e.html_message
66
67
  end
67
68
 
68
69
  def to_s
69
70
  "On line #{line_number} of #{path}: #{follow} #{match} #{target} #{link} => '#{text}'"
70
71
  end
71
72
 
73
+ def local_page_draft?(url)
74
+ filetype = File.extname url
75
+ page_matches = @site.all_collections.map.select { |page| page.url == url }
76
+ case page_matches.length
77
+ when 0
78
+ return false unless %w[htm html md].include? filetype
79
+
80
+ msg = "HRef error: No url matches '#{url}', found on line #{@line_number} (after front matter)"
81
+ @logger.error { msg }
82
+ abort msg if @die_if_nomatch
83
+
84
+ @text = "<i class='h_ref_error'>#{url} is not a valid local page</i>"
85
+ @link_save = @link = '#'
86
+ true
87
+ when 1
88
+ @link = page_matches.first.url
89
+ @link = "#{@link}##{@fragment}" if @fragment
90
+ @link_save = @link
91
+ @text = page_matches.first.title unless @label
92
+ Jekyll::Draft.draft? page_matches.first
93
+ else
94
+ logger.error { "Error: More than one url matched '#{url}'. Collections are: #{page_matches.join(', ')}" }
95
+ exit! 2
96
+ end
97
+ end
98
+
72
99
  JekyllSupport::JekyllPluginHelper.register(self, 'href')
73
100
  end
74
101
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllHrefVersion
2
- VERSION = '1.2.11'.freeze
2
+ VERSION = '1.2.13'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_href
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.11
4
+ version: 1.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-07-27 00:00:00.000000000 Z
10
+ date: 2024-12-23 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: ipaddress
@@ -58,14 +57,14 @@ dependencies:
58
57
  requirements:
59
58
  - - ">="
60
59
  - !ruby/object:Gem::Version
61
- version: 1.0.0
60
+ version: 1.0.3
62
61
  type: :runtime
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - ">="
67
66
  - !ruby/object:Gem::Version
68
- version: 1.0.0
67
+ version: 1.0.3
69
68
  - !ruby/object:Gem::Dependency
70
69
  name: typesafe_enum
71
70
  requirement: !ruby/object:Gem::Requirement
@@ -136,8 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
135
  - !ruby/object:Gem::Version
137
136
  version: '0'
138
137
  requirements: []
139
- rubygems_version: 3.5.16
140
- signing_key:
138
+ rubygems_version: 3.6.0
141
139
  specification_version: 4
142
140
  summary: Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'.
143
141
  test_files: []