jekyll-relative-links 0.1.2 → 0.2.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/generator.rb +23 -7
- 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: 23c2417c6ad14151b5f65eb0c6246068c9357116
|
4
|
+
data.tar.gz: a57d76d65678c8894ef619c0295923febd955fbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cc734299ebba19e7a10beeb5ba3216cb569632ba641f24c5d0b1a3d03d79f49b5bc4a588db83138271beea27a887dbf6095cfe41814e923055989ce7fae0402
|
7
|
+
data.tar.gz: 9907270d8c5b61489cc7b30ed16993c6c38787ac069de9b42fa1cde0f275d1e99948ff69dbd3a3f9a9a6c0fbbcd23727aa5bb73c416c41e45f8f51deb7e402cd
|
@@ -5,7 +5,9 @@ module JekyllRelativeLinks
|
|
5
5
|
# Use Jekyll's native relative_url filter
|
6
6
|
include Jekyll::Filters::URLFilters
|
7
7
|
|
8
|
-
|
8
|
+
INLINE_LINK_REGEX = %r!\[([^\]]+)\]\(([^\)]+)\)!
|
9
|
+
REFERENCE_LINK_REGEX = %r!^\[([^\]]+)\]: (.*)$!
|
10
|
+
LINK_REGEX = %r!(#{INLINE_LINK_REGEX}|#{REFERENCE_LINK_REGEX})!
|
9
11
|
CONVERTER_CLASS = Jekyll::Converters::Markdown
|
10
12
|
|
11
13
|
safe true
|
@@ -25,13 +27,14 @@ module JekyllRelativeLinks
|
|
25
27
|
url_base = File.dirname(page.path)
|
26
28
|
|
27
29
|
page.content.gsub!(LINK_REGEX) do |original|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
link_type = Regexp.last_match(2) ? :inline : :reference
|
31
|
+
link_text = Regexp.last_match(link_type == :inline ? 2 : 4)
|
32
|
+
relative_path = Regexp.last_match(link_type == :inline ? 3 : 5)
|
33
|
+
relative_path.sub!(%r!\A/!, "")
|
34
|
+
url = url_for_path(path_from_root(relative_path, url_base))
|
32
35
|
|
33
|
-
if
|
34
|
-
|
36
|
+
if url
|
37
|
+
replacement_text(link_type, link_text, url)
|
35
38
|
else
|
36
39
|
original
|
37
40
|
end
|
@@ -60,5 +63,18 @@ module JekyllRelativeLinks
|
|
60
63
|
page = site.pages.find { |p| p.path == path }
|
61
64
|
relative_url(page.url) if page
|
62
65
|
end
|
66
|
+
|
67
|
+
def path_from_root(relative_path, url_base)
|
68
|
+
absolute_path = File.expand_path(relative_path, url_base)
|
69
|
+
absolute_path.sub(%r!\A#{Dir.pwd}/!, "")
|
70
|
+
end
|
71
|
+
|
72
|
+
def replacement_text(type, text, url)
|
73
|
+
if type == :inline
|
74
|
+
"[#{text}](#{url})"
|
75
|
+
else
|
76
|
+
"[#{text}]: #{url}"
|
77
|
+
end
|
78
|
+
end
|
63
79
|
end
|
64
80
|
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.2.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: 2016-11-
|
11
|
+
date: 2016-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|