jekyll_href 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/jekyll_href.gemspec +1 -0
- data/lib/enums.rb +21 -0
- data/lib/hash_array.rb +5 -1
- data/lib/href_match.rb +2 -7
- data/lib/href_page_title.rb +5 -20
- data/lib/href_private.rb +76 -64
- data/lib/href_summary.rb +2 -2
- data/lib/href_tag.rb +6 -2
- data/lib/jekyll_href/version.rb +1 -1
- data/lib/jekyll_href.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57a2b255f64c147c2b16d784a3ff1045643164f980bd997e7c2ee7a832e42016
|
4
|
+
data.tar.gz: 4d484a1e4ec6548b0c913847fe4b179406bd5b76865cb2a5cb7a6de36c8624c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ab2372473793d3df613028f89533ebba7951b75ba54c8fd6da78fd70368d68cc969bcd11d1b1cd3ca5b88ef381001dcab15b85c65336481fe288372cf7dc370
|
7
|
+
data.tar.gz: 8cf2cf1a53f87197dea0dcabacf60766953f368d4d6c4a3e786bd29a0c128fb577c96b3a246f559ee26a2dd5e5952a7def825234af2375113f909c8a318fa956
|
data/CHANGELOG.md
CHANGED
data/jekyll_href.gemspec
CHANGED
data/lib/enums.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'typesafe_enum'
|
2
|
+
|
3
|
+
class LinkType < TypesafeEnum::Base
|
4
|
+
new :EXTERNAL
|
5
|
+
new :FRAGMENT
|
6
|
+
new :LOCAL
|
7
|
+
new :MAILTO
|
8
|
+
new :UNKNOWN
|
9
|
+
end
|
10
|
+
|
11
|
+
class LabelSource < TypesafeEnum::Base
|
12
|
+
new :FROM_PAGE_TITLE
|
13
|
+
new :FROM_EXPLICIT_LABEL
|
14
|
+
new :FROM_IMPLICIT_LABEL
|
15
|
+
end
|
16
|
+
|
17
|
+
class Hyphenation < TypesafeEnum::Base
|
18
|
+
new :NONE
|
19
|
+
new :SHY
|
20
|
+
new :WBR
|
21
|
+
end
|
data/lib/hash_array.rb
CHANGED
@@ -10,7 +10,11 @@ module HashArray
|
|
10
10
|
pre_existing = hash[enclosing_page].find { |h| h.link_save == href.link_save }
|
11
11
|
if pre_existing
|
12
12
|
if pre_existing.follow != href.follow
|
13
|
-
@logger.warn
|
13
|
+
@logger.warn <<~END_WARN
|
14
|
+
HRef tags for '#{href.link}' have inconsistent 'follow' keyword options on line #{href.line_number} of #{enclosing_page}:
|
15
|
+
Previous value: #{pre_existing.follow}
|
16
|
+
Current value: #{href.follow}
|
17
|
+
END_WARN
|
14
18
|
end
|
15
19
|
else
|
16
20
|
hash[enclosing_page] << href unless href.summary_exclude
|
data/lib/href_match.rb
CHANGED
@@ -18,15 +18,10 @@ module MSlinn
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def handle_match
|
22
|
-
match_post
|
21
|
+
def handle_match(link)
|
23
22
|
@follow = ''
|
24
23
|
@target = '' unless @blank
|
25
|
-
|
26
|
-
|
27
|
-
# Might set @link and @text
|
28
|
-
def match_post
|
29
|
-
@path, @fragment = @link.split('#')
|
24
|
+
@path, @fragment = link.split('#')
|
30
25
|
|
31
26
|
@logger.debug do
|
32
27
|
<<~END_DEBUG
|
data/lib/href_page_title.rb
CHANGED
@@ -8,17 +8,17 @@ module MSlinn
|
|
8
8
|
all_pages = @site.all_collections + @site.pages
|
9
9
|
pages = if @match
|
10
10
|
all_pages.select { |page| page.url&.include? path }
|
11
|
-
elsif @label_source ==
|
11
|
+
elsif @label_source == LabelSource::FROM_PAGE_TITLE
|
12
12
|
all_pages.select { |page| page.url == path }
|
13
13
|
end
|
14
14
|
pages&.first
|
15
15
|
end
|
16
16
|
|
17
|
+
# Handles links to Jekyll pages
|
18
|
+
# Uses the linked page title as the link text
|
17
19
|
def handle_page_title(linkk)
|
18
20
|
@follow = @target = ''
|
19
|
-
|
20
|
-
@local_link = !@external_link
|
21
|
-
raise HRefError, 'href tags with page_title require local links.' unless @local_link
|
21
|
+
raise HRefError, 'href tags with page_title require local links.' unless @link_type == LinkType::LOCAL
|
22
22
|
|
23
23
|
page = find_page linkk
|
24
24
|
unless page
|
@@ -27,22 +27,7 @@ module MSlinn
|
|
27
27
|
raise HRefError, msg
|
28
28
|
end
|
29
29
|
@text = @label = page.title
|
30
|
-
|
31
|
-
msg = format_error_message "#{e.message}\n<pre> {% href #{@argument_string.strip} %}</pre>"
|
32
|
-
@text = "<div class='href_error'>#{msg}</div>"
|
33
|
-
@link = linkk
|
34
|
-
|
35
|
-
e.shorten_backtrace
|
36
|
-
@logger.error { "#{e.class} raised #{JekyllPluginHelper.remove_html_tags msg}" }
|
37
|
-
raise e if @die_on_href_error
|
38
|
-
|
39
|
-
"<div class='href_error'>HRefError raised in #{self.class};\n#{msg}</div>"
|
40
|
-
ensure
|
41
|
-
if @text.to_s.empty?
|
42
|
-
handle_empty_text linkk
|
43
|
-
else
|
44
|
-
handle_text linkk
|
45
|
-
end
|
30
|
+
handle_empty_text linkk if @text.to_s.empty?
|
46
31
|
@label
|
47
32
|
end
|
48
33
|
end
|
data/lib/href_private.rb
CHANGED
@@ -10,7 +10,7 @@ module MSlinn
|
|
10
10
|
if linkk.nil? || !linkk
|
11
11
|
linkk = @helper.argv&.shift
|
12
12
|
@helper.params&.shift
|
13
|
-
@helper.keys_values&.delete
|
13
|
+
@helper.keys_values&.delete linkk
|
14
14
|
return nil, error_no_uri if linkk.nil?
|
15
15
|
elsif @url.to_s.empty?
|
16
16
|
return nil, error_no_uri
|
@@ -29,32 +29,42 @@ module MSlinn
|
|
29
29
|
"<div class='href_error'>HRefError: #{msg}</div>"
|
30
30
|
end
|
31
31
|
|
32
|
-
# Sets @follow, @helper, @match, @path, @
|
32
|
+
# Sets @follow, @helper, @match, @path, @target, @url, @hyphenation
|
33
33
|
def globals_initial
|
34
34
|
@path = @page['path']
|
35
|
-
AllCollectionsHooks.compute
|
36
|
-
|
37
|
-
|
38
|
-
@
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
44
|
-
@
|
45
|
-
@
|
46
|
-
@
|
47
|
-
@
|
48
|
-
@
|
49
|
-
@
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
35
|
+
AllCollectionsHooks.compute @site
|
36
|
+
@hyphenation = Hyphenation::NONE
|
37
|
+
|
38
|
+
@blank = @helper.parameter_specified? 'blank'
|
39
|
+
@klass = @helper.parameter_specified? 'class'
|
40
|
+
@follow_specified = @helper.parameter_specified?('follow')
|
41
|
+
@follow = @follow_specified ? '' : ' rel="nofollow"'
|
42
|
+
@label = @helper.parameter_specified? 'label'
|
43
|
+
@match = @helper.parameter_specified? 'match'
|
44
|
+
@hyphenation = Hyphenation::SHY if @helper.parameter_specified? 'shy'
|
45
|
+
@style = @helper.parameter_specified? 'style'
|
46
|
+
@summary = @helper.parameter_specified? 'summary'
|
47
|
+
@summary_exclude = @helper.parameter_specified? 'summary_exclude'
|
48
|
+
@target = @blank ? " target='_blank'" : nil
|
49
|
+
@target ||= @helper.parameter_specified?('notarget') ? '' : " target='_blank'"
|
50
|
+
@url = @helper.parameter_specified? 'url'
|
51
|
+
|
52
|
+
if @helper.parameter_specified? 'wbr' # <wbr> has precedence over ­
|
53
|
+
if @hyphenation == Hyphenation::SHY
|
54
|
+
@logger.info do
|
55
|
+
"Warning: wbr and shy were both specified for the href tag on line #{@line_number} (after front matter) of #{@page['path']}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
@hyphenation = Hyphenation::WBR
|
59
|
+
end
|
60
|
+
|
61
|
+
@label_source = if @helper.parameter_specified? 'page_title'
|
62
|
+
LabelSource::FROM_PAGE_TITLE
|
63
|
+
elsif @label
|
64
|
+
LabelSource::FROM_EXPLICIT_LABEL
|
65
|
+
else
|
66
|
+
LabelSource::FROM_IMPLICIT_LABEL
|
67
|
+
end
|
58
68
|
|
59
69
|
return unless @tag_config
|
60
70
|
|
@@ -63,42 +73,45 @@ module MSlinn
|
|
63
73
|
@pry_on_href_error = @tag_config['pry_on_href_error'] == true
|
64
74
|
end
|
65
75
|
|
66
|
-
#
|
76
|
+
# Sets @link_type
|
77
|
+
# Might set @follow, @link, @link_save and @text
|
67
78
|
def globals_update(tokens, linkk)
|
79
|
+
@link_type = LinkType::UNKNOWN
|
80
|
+
|
68
81
|
if linkk.start_with? 'mailto:'
|
69
82
|
handle_mailto linkk
|
70
83
|
return
|
71
|
-
else
|
72
|
-
if @label_source == :from_page_title
|
73
|
-
handle_page_title linkk
|
74
|
-
return
|
75
|
-
end
|
76
|
-
@text = @label || tokens.join(' ').strip
|
77
|
-
if @text.to_s.empty?
|
78
|
-
handle_empty_text linkk
|
79
|
-
else
|
80
|
-
handle_text linkk
|
81
|
-
end
|
82
|
-
@link_save = @link
|
83
84
|
end
|
84
85
|
|
85
|
-
if
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
@link_type = if linkk.start_with? 'http'
|
87
|
+
LinkType::EXTERNAL
|
88
|
+
elsif linkk.start_with? '#'
|
89
|
+
LinkType::FRAGMENT
|
90
|
+
else
|
91
|
+
LinkType::LOCAL
|
92
|
+
end
|
93
|
+
|
94
|
+
@follow = !@follow_specified && @link_type == LinkType::EXTERNAL ? ' rel="nofollow"' : ''
|
95
|
+
|
96
|
+
handle_page_title linkk if @label_source == LabelSource::FROM_PAGE_TITLE
|
97
|
+
@text = @label || tokens.join(' ').strip
|
98
|
+
@link = if @text.to_s.empty?
|
99
|
+
handle_empty_text linkk
|
100
|
+
else
|
101
|
+
linkk
|
102
|
+
end
|
103
|
+
@link_save = @link
|
104
|
+
return if @link_type == LinkType::EXTERNAL
|
105
|
+
|
106
|
+
@follow = @target = ''
|
107
|
+
nil
|
91
108
|
end
|
92
109
|
|
110
|
+
# Sets @text and @link
|
93
111
|
def handle_empty_text(linkk)
|
94
|
-
text = linkk
|
95
|
-
text = linkk&.gsub('/', '/­') if @shy
|
96
|
-
text = linkk&.gsub('/', '/<wbr>') if @wbr
|
112
|
+
text = hyphenate linkk
|
97
113
|
@text = "<code>#{text}</code>"
|
98
|
-
@
|
99
|
-
@local_link = !@external_link
|
100
|
-
@mailto_link = false
|
101
|
-
@link = if @external_link
|
114
|
+
@link = if linkk.start_with? '#'
|
102
115
|
linkk
|
103
116
|
elsif insecure_ip_address linkk
|
104
117
|
"http://#{linkk}"
|
@@ -108,29 +121,28 @@ module MSlinn
|
|
108
121
|
end
|
109
122
|
|
110
123
|
def handle_mailto(linkk)
|
111
|
-
@
|
112
|
-
@local_link = @external_link = false
|
124
|
+
@link_type = LinkType::MAILTO
|
113
125
|
@link = linkk
|
114
126
|
@target = @follow = ''
|
115
|
-
@text = @helper.argv.join(' ')
|
127
|
+
@text = @label || @helper.argv.join(' ')
|
116
128
|
return unless @text.empty?
|
117
129
|
|
118
|
-
text = linkk.delete_prefix('mailto:')
|
130
|
+
text = hyphenate(linkk.delete_prefix('mailto:'))
|
119
131
|
@text = "<code>#{text}</code>"
|
120
132
|
end
|
121
133
|
|
122
|
-
def
|
123
|
-
@
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
134
|
+
def hyphenate(linkk)
|
135
|
+
if @hyphenation == Hyphenation::WBR
|
136
|
+
linkk&.gsub('/', '/<wbr>')
|
137
|
+
elsif @hyphenation == Hyphenation::SHY
|
138
|
+
linkk&.gsub('/', '/­')
|
139
|
+
else
|
140
|
+
linkk
|
141
|
+
end
|
130
142
|
end
|
131
143
|
|
132
144
|
def insecure_ip_address(string)
|
133
|
-
return true if string.start_with? 'localhost'
|
145
|
+
return true if string.start_with?('localhost', 'http://localhost')
|
134
146
|
|
135
147
|
return false unless IPAddress.valid? string
|
136
148
|
|
data/lib/href_summary.rb
CHANGED
@@ -6,9 +6,9 @@ module MSlinn
|
|
6
6
|
return if @summary_exclude || @link_save.start_with?('mailto:') || @link_save.start_with?('#')
|
7
7
|
|
8
8
|
@summary = @summary.to_s.empty? ? @text : @summary.to_s
|
9
|
-
if @summary == true
|
9
|
+
if @summary.to_s == 'true'
|
10
10
|
warning = <<~END_WARNING
|
11
|
-
Warning:
|
11
|
+
Warning: The 'summary' href plugin keyword option was detected in the link text for #{@path} on line #{line_number}.
|
12
12
|
The href tag will not be included in the summary, and the link text will not have the word summary included.
|
13
13
|
This is probably unintentional. Consider using the label option to correct this problem."
|
14
14
|
END_WARNING
|
data/lib/href_tag.rb
CHANGED
@@ -3,6 +3,7 @@ require 'jekyll_all_collections'
|
|
3
3
|
require 'jekyll_plugin_logger'
|
4
4
|
require 'jekyll_plugin_support'
|
5
5
|
require 'liquid'
|
6
|
+
require_relative 'enums'
|
6
7
|
require_relative 'jekyll_href/version'
|
7
8
|
require_relative 'hash_array'
|
8
9
|
|
@@ -45,14 +46,17 @@ module MSlinn
|
|
45
46
|
|
46
47
|
@helper_save = @helper.clone
|
47
48
|
globals_update(@helper.argv, linkk) # Sets @link and @text, might clear @follow and @target
|
48
|
-
handle_match if @match
|
49
|
+
handle_match(@link) if @match
|
50
|
+
raise HrefError, "@link_type was not set" if @link_type == LinkType::UNKNOWN
|
51
|
+
|
49
52
|
save_summary
|
50
53
|
klass = " class='#{@klass}'" if @klass
|
51
54
|
style = " style='#{@style}'" if @style
|
52
55
|
"<a href='#{@link}'#{klass}#{style}#{@target}#{@follow}>#{@text}</a>"
|
53
56
|
rescue HRefError => e # jekyll_plugin_support handles StandardError
|
57
|
+
msg = format_error_message "#{e.message}\n<pre> {% href #{@argument_string.strip} %}</pre>"
|
58
|
+
@text = "<div class='href_error'>#{msg}</div>"
|
54
59
|
e.shorten_backtrace
|
55
|
-
msg = format_error_message e.message
|
56
60
|
@logger.error "#{e.class} raised #{msg}"
|
57
61
|
binding.pry if @pry_on_img_error # rubocop:disable Lint/Debugger
|
58
62
|
raise e if @die_on_href_error
|
data/lib/jekyll_href/version.rb
CHANGED
data/lib/jekyll_href.rb
CHANGED
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.2.
|
4
|
+
version: 1.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ipaddress
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.8.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: typesafe_enum
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: 'Generates an ''a href'' tag, possibly with target=''_blank'' and rel=''nofollow''.
|
70
84
|
|
71
85
|
'
|
@@ -81,6 +95,7 @@ files:
|
|
81
95
|
- README.md
|
82
96
|
- Rakefile
|
83
97
|
- jekyll_href.gemspec
|
98
|
+
- lib/enums.rb
|
84
99
|
- lib/hash_array.rb
|
85
100
|
- lib/href_match.rb
|
86
101
|
- lib/href_page_title.rb
|