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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c000bb6ebfda72f6f406bdab3e42dbbe497fd206
4
- data.tar.gz: 86628c8c052b43529a1cdafad189d8510c9a49fb
3
+ metadata.gz: 23c2417c6ad14151b5f65eb0c6246068c9357116
4
+ data.tar.gz: a57d76d65678c8894ef619c0295923febd955fbe
5
5
  SHA512:
6
- metadata.gz: 104d65622591677c318a44ce61d5324a0643d666ffff39e1172a9927f7ebcc381e3b6a961df136dbcab2aad947e668663a80fbc85052a5509a5eab09e54b5128
7
- data.tar.gz: 178b03c4159090d6bfb4c8c7a7d2bdb1aff1a266631739dfd424b1d325ad03f5e69f6c821adae92bef95a6971528a7970175f0808d090e9b6aa94085acc6b560
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
- LINK_REGEX = %r!\[([^\]]+)\]\(([^\)]+)\)!
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
- link_text = Regexp.last_match(1)
29
- relative_path = Regexp.last_match(2).sub(%r!\A/!, "")
30
- absolute_path = File.expand_path(relative_path, url_base)
31
- path_from_root = absolute_path.sub(%r!\A#{Dir.pwd}/!, "")
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 (url = url_for_path(path_from_root))
34
- "[#{link_text}](#{url})"
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
@@ -1,3 +1,3 @@
1
1
  module JekyllRelativeLinks
2
- VERSION = "0.1.2".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  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.1.2
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-18 00:00:00.000000000 Z
11
+ date: 2016-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll