jekyll_href 1.0.6 → 1.0.9

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: 1b645b13bded894df1a6c5d7f171cc0a9b9830b62ee8d7b86f9195d00ced75f2
4
- data.tar.gz: 5c87ad30bd506bbda270b5dd3d70d19b960cfcd66ec0c59abe8e86cef0f40dd2
3
+ metadata.gz: d98dd353e927f8df1cf3832b2afefebb7be6dda942346cfaefb4899ec4de2606
4
+ data.tar.gz: 3bae16798938728a608f21161324d5843da1e0df1e210ac0e34cf894d5d29ed4
5
5
  SHA512:
6
- metadata.gz: 04d04877c7bafdf0c2185efb20800d6ec0faeced8c1ddaef22dac34336da4c48ab220bca831d4711535e462021ce851a7b1e5e4be3d272d719b93c66442603cc
7
- data.tar.gz: 85b4d3753ddf997139dab7fde06e39c8361f796a5cf4a7d0eb7ad16a369ea7865656a3749232f41e8356899c59f7406c165747915db594c9204161685090597c
6
+ metadata.gz: 27cc832e73c2eaf4db34dcb6cb67c026702ed9e106aa965d61a572cb44c0c4edcc0ca08ad0039c24e074734ecbce6f71643f6e049e76d6830ba64a548a35ed04
7
+ data.tar.gz: 819b74d3d7c6e1a6a6bc7d01797cccaa0c888dfcc7d3e8464b65c1d150bf5fa4dca349275e487163cf24ec38e7acaceae9d525a73f8eb5bf2676383cb85aa1a3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 1.0.9 / 2022-04-25
2
+ * Match now looks at all collections, not just posts
3
+
4
+ ## 1.0.8 / 2022-04-11
5
+ * Fixed match text
6
+
7
+ ## 1.0.7 / 2022-04-11
8
+ * Fixed bad reference when more than one URL matches
9
+
1
10
  ## 1.0.6 / 2022-04-05
2
11
  * Updated to `jekyll_plugin_logger` v2.1.0
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).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllHrefVersion
4
- VERSION = "1.0.6"
4
+ VERSION = "1.0.9"
5
5
  end
data/lib/jekyll_href.rb CHANGED
@@ -58,11 +58,11 @@ class ExternalHref < Liquid::Tag
58
58
  def initialize(tag_name, command_line, _parse_context)
59
59
  super
60
60
 
61
+ @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
61
62
  @match = false
62
63
  @tokens = command_line.strip.split
63
64
  @follow = get_value("follow", " rel='nofollow'")
64
65
  @target = get_value("notarget", " target='_blank'")
65
- @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
66
66
 
67
67
  match_index = @tokens.index("match")
68
68
  if match_index
@@ -118,31 +118,36 @@ class ExternalHref < Liquid::Tag
118
118
 
119
119
  path, fragment = @link.split('#')
120
120
 
121
- @logger.debug { "@link=#{@link}" }
122
- @logger.debug { "site.posts[0].url = #{site.posts.docs[0].url}" }
123
- @logger.debug { "site.posts[0].path = #{site.posts.docs[0].path}" }
124
- posts = site.posts.docs.select { |x| x.url.include?(path) }
125
- case posts.length
121
+ @logger.debug {
122
+ <<~END_DEBUG
123
+ @link=#{@link}
124
+ site.posts[0].url = #{site.posts.docs[0].url}
125
+ site.posts[0].path = #{site.posts.docs[0].path}
126
+ END_DEBUG
127
+ }
128
+ urls = site.collections
129
+ .values
130
+ .map { |x| x.class.method_defined?(:docs) ? x.docs : x }
131
+ .flatten
132
+ .map(&:url) # TODO Optimize this by caching the result
133
+ url_matches = urls.select { |url| url.include? path }
134
+ case url_matches.length
126
135
  when 0
127
- if die_if_nomatch
128
- abort "href error: No url matches '#{@link}'"
129
- else
130
- @link = "#"
131
- @text = "<i>#{@link} is not available</i>"
132
- end
136
+ abort "href error: No url matches '#{@link}'" if die_if_nomatch
137
+ @link = "#"
138
+ @text = "<i>#{@link} is not available</i>"
133
139
  when 1
134
- @link = posts.first.url
140
+ @link = url_matches.first
135
141
  @link = "#{@link}\##{fragment}" if fragment
136
142
  else
137
- abort "Error: More than one url matched: #{ matches.join(", ")}"
143
+ abort "Error: More than one url matched '#{path}': #{ url_matches.join(", ")}"
138
144
  end
139
145
  end
140
146
 
141
147
  def replace_vars(context, link)
142
148
  variables = context.registers[:site].config['plugin-vars']
143
149
  variables.each do |name, value|
144
- # puts "#{name}=#{value}"
145
- link = link.gsub("{{#{name}}}", value)
150
+ link = link.gsub "{{#{name}}}", value
146
151
  end
147
152
  link
148
153
  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.6
4
+ version: 1.0.9
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-06 00:00:00.000000000 Z
11
+ date: 2022-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll