jekyll_href 1.0.8 → 1.0.11

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: ad27b62f30c018e8bd18e64aff15c9db271b8c8052f76b96387711bcced86af7
4
- data.tar.gz: b0d7dc5ab8f04c8481762af18e1cc866680b7a24a4d3f87c0a0028e9e572e264
3
+ metadata.gz: 15480940e220781ca558c0f95d22688a87ea55f6b55f8bac9af6f93a1bbe5b33
4
+ data.tar.gz: 1314f1deb1e739899c5eb686bf9834d3f88bc46fe3df14bff72f44d737a3064c
5
5
  SHA512:
6
- metadata.gz: 0325a5472644d4343a5fbd148413b9bb21b75ad81f03967d4605a979d346788a82c85096dee54025091ce94596ad608197ff4a37fd431c25d4f881881aa44c5e
7
- data.tar.gz: f783aee2b38d287ce135db43ad92bc90c549cee2f2e5d60b94cb2e5c4636f642df464b5722f4e0094a758f0292e713ca8584c36223bebd061e2d29fedea9edc3
6
+ metadata.gz: d15df7a457f5da7181525240ee63ea5a21a404eb8c0fdaf20a6f687378ef4947ff7a32e769376e3825aa95cad2862d09746907635c2320d517f270e2cd1156de
7
+ data.tar.gz: 14c3ba6b074a3da884ff50f82519ee054625c5340afae444fddc93ec90414b962a1300ebac4fa3c8904d3bdeedc04f5c0aa26fdc520bafc23463f415f9d67c60
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 1.0.11 / 2022-04-27
2
+ * Suppresses target and rel=nofollow attributes for mailto: links.
3
+
4
+ ## 1.0.10 / 2022-04-27
5
+ * Works from pre-computed `site['all_collections']` provided by a new dependency called `jekyll_all_collections`.
6
+
7
+ ## 1.0.9 / 2022-04-25
8
+ * Match now looks at all collections, not just posts
9
+
1
10
  ## 1.0.8 / 2022-04-11
2
11
  * Fixed match text
3
12
 
data/README.md CHANGED
@@ -16,6 +16,9 @@ Also provides a convenient way to generate formatted and clickable URIs.
16
16
  Note that the url should not be enclosed in quotes.
17
17
  Also please note that the square brackets denote optional parameters, and should not be typed.
18
18
 
19
+ `match` will attempt to match the url fragment (specified as a regex) to a URL in any collection.
20
+ If multiple documents have matching URL an error is thrown.
21
+
19
22
 
20
23
  ### Additional Information
21
24
  More information is available on my web site about [my Jekyll plugins](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
data/jekyll_href.gemspec CHANGED
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.version = JekyllHrefVersion::VERSION
35
35
 
36
36
  spec.add_dependency 'jekyll', '>= 3.5.0'
37
+ spec.add_dependency 'jekyll_all_collections'
37
38
  spec.add_dependency 'jekyll_plugin_logger'
38
39
 
39
40
  spec.add_development_dependency 'debase'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllHrefVersion
4
- VERSION = "1.0.8"
4
+ VERSION = "1.0.11"
5
5
  end
data/lib/jekyll_href.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "jekyll_plugin_logger"
4
+ require "jekyll_all_collections"
4
5
  require "liquid"
5
6
  require_relative "jekyll_href/version"
6
7
 
@@ -51,6 +52,7 @@ require_relative "jekyll_href/version"
51
52
  # <code>django.core.management.execute_from_command_line</code> %}
52
53
 
53
54
  class ExternalHref < Liquid::Tag
55
+
54
56
  # @param tag_name [String] is the name of the tag, which we already know.
55
57
  # @param command_line [Hash, String, Liquid::Tag::Parser] the arguments from the web page.
56
58
  # @param _parse_context [Liquid::ParseContext] tokenized command line
@@ -76,10 +78,15 @@ class ExternalHref < Liquid::Tag
76
78
  end
77
79
 
78
80
  # Method prescribed by the Jekyll plugin lifecycle.
81
+ # @param liquid_context [Liquid::Context]
79
82
  # @return [String]
80
- def render(context)
81
- match(context) if @match
82
- link = replace_vars(context, @link)
83
+ def render(liquid_context)
84
+ @site = liquid_context.registers[:site]
85
+ JekyllAllCollections::maybe_compute_all_collections(@site)
86
+
87
+ match(liquid_context) if @match
88
+ link = replace_vars(liquid_context, @link)
89
+ @target = @follow = "" if link.start_with? "mailto:"
83
90
  @logger.debug { "@link=#{@link}; link=#{link}" }
84
91
  "<a href='#{link}'#{@target}#{@follow}>#{@text}</a>"
85
92
  end
@@ -111,9 +118,8 @@ class ExternalHref < Liquid::Tag
111
118
  value
112
119
  end
113
120
 
114
- def match(context) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
115
- site = context.registers[:site]
116
- config = site.config['href']
121
+ def match(liquid_context) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
122
+ config = @site.config['href']
117
123
  die_if_nomatch = !config.nil? && config['nomatch'] && config['nomatch']=='fatal'
118
124
 
119
125
  path, fragment = @link.split('#')
@@ -121,26 +127,28 @@ class ExternalHref < Liquid::Tag
121
127
  @logger.debug {
122
128
  <<~END_DEBUG
123
129
  @link=#{@link}
124
- site.posts[0].url = #{site.posts.docs[0].url}
125
- site.posts[0].path = #{site.posts.docs[0].path}
130
+ @site.posts.docs[0].url = #{@site.posts.docs[0].url}
131
+ @site.posts.docs[0].path = #{@site.posts.docs[0].path}
126
132
  END_DEBUG
127
133
  }
128
- posts = site.posts.docs.select { |x| x.url.include? path }
129
- case posts.length
134
+
135
+ all_urls = @site.all_collections.map(&:url)
136
+ url_matches = all_urls.select { |url| url.include? path }
137
+ case url_matches.length
130
138
  when 0
131
139
  abort "href error: No url matches '#{@link}'" if die_if_nomatch
132
140
  @link = "#"
133
141
  @text = "<i>#{@link} is not available</i>"
134
142
  when 1
135
- @link = posts.first.url
143
+ @link = url_matches.first
136
144
  @link = "#{@link}\##{fragment}" if fragment
137
145
  else
138
- abort "Error: More than one url matched: #{ posts.map(&:relative_path).join(", ")}"
146
+ abort "Error: More than one url matched '#{path}': #{ url_matches.join(", ")}"
139
147
  end
140
148
  end
141
149
 
142
- def replace_vars(context, link)
143
- variables = context.registers[:site].config['plugin-vars']
150
+ def replace_vars(liquid_context, link)
151
+ variables = @site.config['plugin-vars']
144
152
  variables.each do |name, value|
145
153
  link = link.gsub "{{#{name}}}", value
146
154
  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.0.8
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-11 00:00:00.000000000 Z
11
+ date: 2022-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll_all_collections
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: jekyll_plugin_logger
29
43
  requirement: !ruby/object:Gem::Requirement