jekyll-relative-links 0.3.0 → 0.4.0
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/lib/jekyll-relative-links/generator.rb +35 -22
- data/lib/jekyll-relative-links/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ca1f80629950904c828211cc5c032e590eb02e7
|
4
|
+
data.tar.gz: 0f699f5d6a7dbc1ad7227a03e327155bf58d51e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9167289dc30d083a23ff0a33d62f78a49e6406858fd82dc7b4e4bad9fadcd876e98ad6a7279b58a272d0833bae4f3c2d67b2ed075899a4f1f839adf377e387ad
|
7
|
+
data.tar.gz: b154836fd6304a5696017183b024978e7e598a203b66d63cbd5f135d13a8d0e56a30149a27a43243d518a3d7afbc4945e1d64c7f90868cefb1534046b88a40fa
|
@@ -26,29 +26,38 @@ module JekyllRelativeLinks
|
|
26
26
|
|
27
27
|
site.pages.each do |page|
|
28
28
|
next unless markdown_extension?(page.extname)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
29
|
+
replace_relative_links!(page)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def replace_relative_links!(page)
|
34
|
+
url_base = File.dirname(page.path)
|
35
|
+
|
36
|
+
page.content.gsub!(LINK_REGEX) do |original|
|
37
|
+
link_type, link_text, relative_path, fragment = link_parts(Regexp.last_match)
|
38
|
+
path = path_from_root(relative_path, url_base)
|
39
|
+
url = url_for_path(path)
|
40
|
+
|
41
|
+
if url
|
42
|
+
replacement_text(link_type, link_text, url, fragment)
|
43
|
+
else
|
44
|
+
original
|
46
45
|
end
|
47
46
|
end
|
47
|
+
rescue ArgumentError => e
|
48
|
+
raise e unless e.to_s.start_with?("invalid byte sequence in UTF-8")
|
48
49
|
end
|
49
50
|
|
50
51
|
private
|
51
52
|
|
53
|
+
def link_parts(matches)
|
54
|
+
link_type = matches[2] ? :inline : :reference
|
55
|
+
link_text = matches[link_type == :inline ? 2 : 5]
|
56
|
+
relative_path = matches[link_type == :inline ? 3 : 6]
|
57
|
+
fragment = matches[link_type == :inline ? 4 : 7]
|
58
|
+
[link_type, link_text, relative_path, fragment]
|
59
|
+
end
|
60
|
+
|
52
61
|
def context
|
53
62
|
JekyllRelativeLinks::Context.new(site)
|
54
63
|
end
|
@@ -62,19 +71,23 @@ module JekyllRelativeLinks
|
|
62
71
|
end
|
63
72
|
|
64
73
|
def url_for_path(path)
|
65
|
-
|
66
|
-
|
74
|
+
target = potential_targets.find { |p| p.relative_path.sub(%r!\A/!, "") == path }
|
75
|
+
relative_url(target.url) if target
|
76
|
+
end
|
67
77
|
|
68
|
-
|
69
|
-
|
78
|
+
def potential_targets
|
79
|
+
@potential_targets ||= (site.pages + site.static_files)
|
70
80
|
end
|
71
81
|
|
72
82
|
def path_from_root(relative_path, url_base)
|
83
|
+
relative_path.sub!(%r!\A/!, "")
|
73
84
|
absolute_path = File.expand_path(relative_path, url_base)
|
74
85
|
absolute_path.sub(%r!\A#{Dir.pwd}/!, "")
|
75
86
|
end
|
76
87
|
|
77
|
-
def replacement_text(type, text, url)
|
88
|
+
def replacement_text(type, text, url, fragment = nil)
|
89
|
+
url << fragment if fragment
|
90
|
+
|
78
91
|
if type == :inline
|
79
92
|
"[#{text}](#{url})"
|
80
93
|
else
|
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.4.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-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
85
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.6.11
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: A Jekyll plugin to convert relative links to markdown files to their rendered
|