jekyll-relative-links 0.5.3 → 0.6.0

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: 76726e81607582ad28cfc9f754031b52bd77fdb384605eb47a85b9d15dc199fc
4
- data.tar.gz: ba1748034e9a65d36c42098226ea194b7d011bfa903aa2fa7faa8acbfb3ee853
3
+ metadata.gz: ebecb8d06a1ed741d58bb3eb520815f3f5d58ef4fa05aa38de5a8974798db59f
4
+ data.tar.gz: 24c147b3cdeb009e06de487ad126f26196f5d8b20a32e76123085fc7c7355610
5
5
  SHA512:
6
- metadata.gz: fcdc1d5f4dd5a4f70d747618a8fa0258204b268109c348d8bd6878121753a242c344cb96ff9af5f1d965350ce78ef9e59bfdb5af11d01653e1e1e9960e10ad2b
7
- data.tar.gz: 606bf27188ebfb358abb26387b40ca896e198eb6d75fba1c2b19c36a07f21c442bd848e40b913ff03181f0857f747a018e1d90bc234b00f26cc0bc379374baa2
6
+ metadata.gz: 927fda48316aa1da296cbf95c9c1f191aae160412369b72fb36eae9dcef7849d87c846f0327565adb30bb7cd3a606e48612bad0859a1d822c73fd17118b4cdfe
7
+ data.tar.gz: 6072633be060cde647b92f88672e57a9d7b584952a73b7b3dd0bf4aed3c8199cc53b9498fe30a6483c4225a250c1537e705a66acd938997d60ffa5355cbc4cff
@@ -2,33 +2,34 @@
2
2
 
3
3
  module JekyllRelativeLinks
4
4
  class Generator < Jekyll::Generator
5
- attr_accessor :site
5
+ attr_accessor :site, :config
6
6
 
7
7
  # Use Jekyll's native relative_url filter
8
8
  include Jekyll::Filters::URLFilters
9
9
 
10
- LINK_TEXT_REGEX = %r!([^\]]+)!
11
- FRAGMENT_REGEX = %r!(#.+?)?!
12
- INLINE_LINK_REGEX = %r!\[#{LINK_TEXT_REGEX}\]\(([^\)]+?)#{FRAGMENT_REGEX}\)!
13
- REFERENCE_LINK_REGEX = %r!^\s*?\[#{LINK_TEXT_REGEX}\]: (.+?)#{FRAGMENT_REGEX}\s*?$!
14
- LINK_REGEX = %r!(#{INLINE_LINK_REGEX}|#{REFERENCE_LINK_REGEX})!
10
+ LINK_TEXT_REGEX = %r!(.*?)!.freeze
11
+ FRAGMENT_REGEX = %r!(#.+?)?!.freeze
12
+ INLINE_LINK_REGEX = %r!\[#{LINK_TEXT_REGEX}\]\(([^\)]+?)#{FRAGMENT_REGEX}\)!.freeze
13
+ REFERENCE_LINK_REGEX = %r!^\s*?\[#{LINK_TEXT_REGEX}\]: (.+?)#{FRAGMENT_REGEX}\s*?$!.freeze
14
+ LINK_REGEX = %r!(#{INLINE_LINK_REGEX}|#{REFERENCE_LINK_REGEX})!.freeze
15
15
  CONVERTER_CLASS = Jekyll::Converters::Markdown
16
- CONFIG_KEY = "relative_links".freeze
17
- ENABLED_KEY = "enabled".freeze
18
- COLLECTIONS_KEY = "collections".freeze
16
+ CONFIG_KEY = "relative_links"
17
+ ENABLED_KEY = "enabled"
18
+ COLLECTIONS_KEY = "collections"
19
+ LOG_KEY = "Relative Links:"
19
20
 
20
21
  safe true
21
22
  priority :lowest
22
23
 
23
- def initialize(site)
24
- @site = site
25
- @context = context
24
+ def initialize(config)
25
+ @config = config
26
26
  end
27
27
 
28
28
  def generate(site)
29
+ return if disabled?
30
+
29
31
  @site = site
30
32
  @context = context
31
- return if disabled?
32
33
 
33
34
  documents = site.pages
34
35
  documents = site.pages + site.docs_to_write if collections?
@@ -36,6 +37,8 @@ module JekyllRelativeLinks
36
37
  documents.each do |document|
37
38
  next unless markdown_extension?(document.extname)
38
39
  next if document.is_a?(Jekyll::StaticFile)
40
+ next if excluded?(document)
41
+
39
42
  replace_relative_links!(document)
40
43
  end
41
44
  end
@@ -46,16 +49,13 @@ module JekyllRelativeLinks
46
49
 
47
50
  document.content = document.content.dup.gsub(LINK_REGEX) do |original|
48
51
  link_type, link_text, relative_path, fragment = link_parts(Regexp.last_match)
49
- next original if fragment?(relative_path) || absolute_url?(relative_path)
52
+ next original unless replaceable_link?(relative_path)
50
53
 
51
54
  path = path_from_root(relative_path, url_base)
52
55
  url = url_for_path(path)
56
+ next original unless url
53
57
 
54
- if url
55
- replacement_text(link_type, link_text, url, fragment)
56
- else
57
- original
58
- end
58
+ replacement_text(link_type, link_text, url, fragment)
59
59
  end
60
60
  rescue ArgumentError => e
61
61
  raise e unless e.to_s.start_with?("invalid byte sequence in UTF-8")
@@ -72,7 +72,7 @@ module JekyllRelativeLinks
72
72
  end
73
73
 
74
74
  def context
75
- JekyllRelativeLinks::Context.new(site)
75
+ @context ||= JekyllRelativeLinks::Context.new(site)
76
76
  end
77
77
 
78
78
  def markdown_extension?(extension)
@@ -85,7 +85,7 @@ module JekyllRelativeLinks
85
85
 
86
86
  def url_for_path(path)
87
87
  target = potential_targets.find { |p| p.relative_path.sub(%r!\A/!, "") == path }
88
- relative_url(target.url) if target && target.url
88
+ relative_url(target.url) if target&.url
89
89
  end
90
90
 
91
91
  def potential_targets
@@ -110,17 +110,22 @@ module JekyllRelativeLinks
110
110
 
111
111
  def absolute_url?(string)
112
112
  return unless string
113
+
113
114
  Addressable::URI.parse(string).absolute?
114
115
  rescue Addressable::URI::InvalidURIError
115
116
  nil
116
117
  end
117
118
 
118
119
  def fragment?(string)
119
- string && string.start_with?("#")
120
+ string&.start_with?("#")
121
+ end
122
+
123
+ def replaceable_link?(string)
124
+ !fragment?(string) && !absolute_url?(string)
120
125
  end
121
126
 
122
127
  def option(key)
123
- site.config[CONFIG_KEY] && site.config[CONFIG_KEY][key]
128
+ config[CONFIG_KEY] && config[CONFIG_KEY][key]
124
129
  end
125
130
 
126
131
  def disabled?
@@ -130,5 +135,23 @@ module JekyllRelativeLinks
130
135
  def collections?
131
136
  option(COLLECTIONS_KEY) == true
132
137
  end
138
+
139
+ def excluded?(document)
140
+ return false unless option("exclude")
141
+
142
+ entry_filter = if document.respond_to?(:collection)
143
+ document.collection.entry_filter
144
+ else
145
+ global_entry_filter
146
+ end
147
+
148
+ entry_filter.glob_include?(option("exclude"), document.relative_path).tap do |excluded|
149
+ Jekyll.logger.debug(LOG_KEY, "excluded #{document.relative_path}") if excluded
150
+ end
151
+ end
152
+
153
+ def global_entry_filter
154
+ @global_entry_filter ||= Jekyll::EntryFilter.new(site)
155
+ end
133
156
  end
134
157
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllRelativeLinks
4
- VERSION = "0.5.3".freeze
4
+ VERSION = "0.6.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-relative-links
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-16 00:00:00.000000000 Z
11
+ date: 2019-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -40,18 +40,38 @@ dependencies:
40
40
  version: '3.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.49.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 1.0.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 0.49.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.0.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rubocop-jekyll
43
63
  requirement: !ruby/object:Gem::Requirement
44
64
  requirements:
45
65
  - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '0.43'
67
+ version: 0.7.0
48
68
  type: :development
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '0.43'
74
+ version: 0.7.0
55
75
  description:
56
76
  email:
57
77
  - ben.balter@github.com
@@ -82,8 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
102
  - !ruby/object:Gem::Version
83
103
  version: '0'
84
104
  requirements: []
85
- rubyforge_project:
86
- rubygems_version: 2.7.6
105
+ rubygems_version: 3.0.2
87
106
  signing_key:
88
107
  specification_version: 4
89
108
  summary: A Jekyll plugin to convert relative links to markdown files to their rendered