jekyll_href 1.0.9 → 1.0.10

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: d98dd353e927f8df1cf3832b2afefebb7be6dda942346cfaefb4899ec4de2606
4
- data.tar.gz: 3bae16798938728a608f21161324d5843da1e0df1e210ac0e34cf894d5d29ed4
3
+ metadata.gz: ed7504969773757ecab66ef862c11968ec563622c07f3840f34aaa8bc86b34fd
4
+ data.tar.gz: 835d3f059cdc96f6095d2443a2ed19df5ffa79fc32a696f5fe7bdac76794c959
5
5
  SHA512:
6
- metadata.gz: 27cc832e73c2eaf4db34dcb6cb67c026702ed9e106aa965d61a572cb44c0c4edcc0ca08ad0039c24e074734ecbce6f71643f6e049e76d6830ba64a548a35ed04
7
- data.tar.gz: 819b74d3d7c6e1a6a6bc7d01797cccaa0c888dfcc7d3e8464b65c1d150bf5fa4dca349275e487163cf24ec38e7acaceae9d525a73f8eb5bf2676383cb85aa1a3
6
+ metadata.gz: def5d5a884f5804461a656144fe2a87f13c07b34ec28d5577ddb8bbfcf4f04aa4773514d34d33bcbe6967da1a74bad60d501ecaa835e33a9441d0352f4460da0
7
+ data.tar.gz: efc68d1bfc4c072e2de8b0d33d723ff9d206996d1ff9fc1fdea5fd905707c5df54227b62ca20160359e8ab3c84a09c3582c1edccfc9a06c6f9b1d177fb8b4318
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.0.10 / 2022-04-27
2
+ * Works from pre-computed `site['all_collections']` provided by a new dependency called `jekyll_all_collections`.
3
+
1
4
  ## 1.0.9 / 2022-04-25
2
5
  * Match now looks at all collections, not just posts
3
6
 
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.9"
4
+ VERSION = "1.0.10"
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,14 @@ 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)
83
89
  @logger.debug { "@link=#{@link}; link=#{link}" }
84
90
  "<a href='#{link}'#{@target}#{@follow}>#{@text}</a>"
85
91
  end
@@ -111,9 +117,8 @@ class ExternalHref < Liquid::Tag
111
117
  value
112
118
  end
113
119
 
114
- def match(context) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
115
- site = context.registers[:site]
116
- config = site.config['href']
120
+ def match(liquid_context) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
121
+ config = @site.config['href']
117
122
  die_if_nomatch = !config.nil? && config['nomatch'] && config['nomatch']=='fatal'
118
123
 
119
124
  path, fragment = @link.split('#')
@@ -121,16 +126,13 @@ class ExternalHref < Liquid::Tag
121
126
  @logger.debug {
122
127
  <<~END_DEBUG
123
128
  @link=#{@link}
124
- site.posts[0].url = #{site.posts.docs[0].url}
125
- site.posts[0].path = #{site.posts.docs[0].path}
129
+ @site.posts.docs[0].url = #{@site.posts.docs[0].url}
130
+ @site.posts.docs[0].path = #{@site.posts.docs[0].path}
126
131
  END_DEBUG
127
132
  }
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 }
133
+
134
+ all_urls = @site.all_collections.map(&:url)
135
+ url_matches = all_urls.select { |url| url.include? path }
134
136
  case url_matches.length
135
137
  when 0
136
138
  abort "href error: No url matches '#{@link}'" if die_if_nomatch
@@ -144,8 +146,8 @@ class ExternalHref < Liquid::Tag
144
146
  end
145
147
  end
146
148
 
147
- def replace_vars(context, link)
148
- variables = context.registers[:site].config['plugin-vars']
149
+ def replace_vars(liquid_context, link)
150
+ variables = @site.config['plugin-vars']
149
151
  variables.each do |name, value|
150
152
  link = link.gsub "{{#{name}}}", value
151
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.9
4
+ version: 1.0.10
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-25 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