jekyll-relative-links 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-relative-links.rb +2 -2
- data/lib/jekyll-relative-links/generator.rb +28 -9
- data/lib/jekyll-relative-links/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 351e7b664aa98021cf0c3f719ea7e2a0aaaf7895
|
4
|
+
data.tar.gz: 6ec9d3f4f76991b2ee7757ef2da9394fad71abee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5ff53c27eee911580d3b66f40da628b5df9ff0f494cc8d246b9c2c1b7bf3f944213df60345f52e755a1d4398d31d5d8985add045c22507c2abfc4feecea1401
|
7
|
+
data.tar.gz: 7de7fcbb5ad99a925f1254d3195e5ac812a654a35abc5e3b645ed9a94471c6ef418526f12c03469cb91ff8a683455a7e77b13c6c1278e1916c424060f0878805
|
@@ -8,9 +8,12 @@ module JekyllRelativeLinks
|
|
8
8
|
LINK_TEXT_REGEX = %r!([^\]]+)!
|
9
9
|
FRAGMENT_REGEX = %r!(#.+?)?!
|
10
10
|
INLINE_LINK_REGEX = %r!\[#{LINK_TEXT_REGEX}\]\(([^\)]+?)#{FRAGMENT_REGEX}\)!
|
11
|
-
REFERENCE_LINK_REGEX = %r!^\[#{LINK_TEXT_REGEX}\]: (.+?)#{FRAGMENT_REGEX}$!
|
11
|
+
REFERENCE_LINK_REGEX = %r!^\s*\[#{LINK_TEXT_REGEX}\]: (.+?)#{FRAGMENT_REGEX}$!
|
12
12
|
LINK_REGEX = %r!(#{INLINE_LINK_REGEX}|#{REFERENCE_LINK_REGEX})!
|
13
13
|
CONVERTER_CLASS = Jekyll::Converters::Markdown
|
14
|
+
CONFIG_KEY = "relative_links".freeze
|
15
|
+
ENABLED_KEY = "enabled".freeze
|
16
|
+
COLLECTIONS_KEY = "collections".freeze
|
14
17
|
|
15
18
|
safe true
|
16
19
|
priority :lowest
|
@@ -23,17 +26,21 @@ module JekyllRelativeLinks
|
|
23
26
|
def generate(site)
|
24
27
|
@site = site
|
25
28
|
@context = context
|
29
|
+
return if disabled?
|
26
30
|
|
27
|
-
site.pages
|
28
|
-
|
29
|
-
|
31
|
+
documents = site.pages
|
32
|
+
documents = site.pages + site.docs_to_write if collections?
|
33
|
+
|
34
|
+
documents.each do |document|
|
35
|
+
next unless markdown_extension?(document.extname)
|
36
|
+
replace_relative_links!(document)
|
30
37
|
end
|
31
38
|
end
|
32
39
|
|
33
|
-
def replace_relative_links!(
|
34
|
-
url_base = File.dirname(
|
40
|
+
def replace_relative_links!(document)
|
41
|
+
url_base = File.dirname(document.relative_path)
|
35
42
|
|
36
|
-
|
43
|
+
document.content.gsub!(LINK_REGEX) do |original|
|
37
44
|
link_type, link_text, relative_path, fragment = link_parts(Regexp.last_match)
|
38
45
|
next original if fragment?(relative_path) || absolute_url?(relative_path)
|
39
46
|
|
@@ -74,11 +81,11 @@ module JekyllRelativeLinks
|
|
74
81
|
|
75
82
|
def url_for_path(path)
|
76
83
|
target = potential_targets.find { |p| p.relative_path.sub(%r!\A/!, "") == path }
|
77
|
-
relative_url(target.url) if target
|
84
|
+
relative_url(target.url) if target && target.url
|
78
85
|
end
|
79
86
|
|
80
87
|
def potential_targets
|
81
|
-
@potential_targets ||=
|
88
|
+
@potential_targets ||= site.pages + site.static_files + site.docs_to_write
|
82
89
|
end
|
83
90
|
|
84
91
|
def path_from_root(relative_path, url_base)
|
@@ -107,5 +114,17 @@ module JekyllRelativeLinks
|
|
107
114
|
def fragment?(string)
|
108
115
|
string && string.start_with?("#")
|
109
116
|
end
|
117
|
+
|
118
|
+
def option(key)
|
119
|
+
site.config[CONFIG_KEY] && site.config[CONFIG_KEY][key]
|
120
|
+
end
|
121
|
+
|
122
|
+
def disabled?
|
123
|
+
option(ENABLED_KEY) == false
|
124
|
+
end
|
125
|
+
|
126
|
+
def collections?
|
127
|
+
option(COLLECTIONS_KEY) == true
|
128
|
+
end
|
110
129
|
end
|
111
130
|
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.
|
4
|
+
version: 0.5.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: 2017-
|
11
|
+
date: 2017-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|