jekyll_href 1.0.7 → 1.0.10
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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +3 -0
- data/jekyll_href.gemspec +1 -0
- data/lib/jekyll_href/version.rb +1 -1
- data/lib/jekyll_href.rb +31 -24
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed7504969773757ecab66ef862c11968ec563622c07f3840f34aaa8bc86b34fd
|
4
|
+
data.tar.gz: 835d3f059cdc96f6095d2443a2ed19df5ffa79fc32a696f5fe7bdac76794c959
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: def5d5a884f5804461a656144fe2a87f13c07b34ec28d5577ddb8bbfcf4f04aa4773514d34d33bcbe6967da1a74bad60d501ecaa835e33a9441d0352f4460da0
|
7
|
+
data.tar.gz: efc68d1bfc4c072e2de8b0d33d723ff9d206996d1ff9fc1fdea5fd905707c5df54227b62ca20160359e8ab3c84a09c3582c1edccfc9a06c6f9b1d177fb8b4318
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
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
|
+
|
4
|
+
## 1.0.9 / 2022-04-25
|
5
|
+
* Match now looks at all collections, not just posts
|
6
|
+
|
7
|
+
## 1.0.8 / 2022-04-11
|
8
|
+
* Fixed match text
|
9
|
+
|
1
10
|
## 1.0.7 / 2022-04-11
|
2
11
|
* Fixed bad reference when more than one URL matches
|
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'
|
data/lib/jekyll_href/version.rb
CHANGED
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
|
@@ -58,11 +60,11 @@ class ExternalHref < Liquid::Tag
|
|
58
60
|
def initialize(tag_name, command_line, _parse_context)
|
59
61
|
super
|
60
62
|
|
63
|
+
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
61
64
|
@match = false
|
62
65
|
@tokens = command_line.strip.split
|
63
66
|
@follow = get_value("follow", " rel='nofollow'")
|
64
67
|
@target = get_value("notarget", " target='_blank'")
|
65
|
-
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
66
68
|
|
67
69
|
match_index = @tokens.index("match")
|
68
70
|
if match_index
|
@@ -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(
|
81
|
-
|
82
|
-
|
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,38 +117,39 @@ class ExternalHref < Liquid::Tag
|
|
111
117
|
value
|
112
118
|
end
|
113
119
|
|
114
|
-
def match(
|
115
|
-
|
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('#')
|
120
125
|
|
121
|
-
@logger.debug {
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
+
@logger.debug {
|
127
|
+
<<~END_DEBUG
|
128
|
+
@link=#{@link}
|
129
|
+
@site.posts.docs[0].url = #{@site.posts.docs[0].url}
|
130
|
+
@site.posts.docs[0].path = #{@site.posts.docs[0].path}
|
131
|
+
END_DEBUG
|
132
|
+
}
|
133
|
+
|
134
|
+
all_urls = @site.all_collections.map(&:url)
|
135
|
+
url_matches = all_urls.select { |url| url.include? path }
|
136
|
+
case url_matches.length
|
126
137
|
when 0
|
127
|
-
if die_if_nomatch
|
128
|
-
|
129
|
-
|
130
|
-
@link = "#"
|
131
|
-
@text = "<i>#{@link} is not available</i>"
|
132
|
-
end
|
138
|
+
abort "href error: No url matches '#{@link}'" if die_if_nomatch
|
139
|
+
@link = "#"
|
140
|
+
@text = "<i>#{@link} is not available</i>"
|
133
141
|
when 1
|
134
|
-
@link =
|
142
|
+
@link = url_matches.first
|
135
143
|
@link = "#{@link}\##{fragment}" if fragment
|
136
144
|
else
|
137
|
-
abort "Error: More than one url matched: #{
|
145
|
+
abort "Error: More than one url matched '#{path}': #{ url_matches.join(", ")}"
|
138
146
|
end
|
139
147
|
end
|
140
148
|
|
141
|
-
def replace_vars(
|
142
|
-
variables =
|
149
|
+
def replace_vars(liquid_context, link)
|
150
|
+
variables = @site.config['plugin-vars']
|
143
151
|
variables.each do |name, value|
|
144
|
-
|
145
|
-
link = link.gsub("{{#{name}}}", value)
|
152
|
+
link = link.gsub "{{#{name}}}", value
|
146
153
|
end
|
147
154
|
link
|
148
155
|
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.
|
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-
|
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
|