jekyll-relative-links 0.4.0 → 0.4.1

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: 5ca1f80629950904c828211cc5c032e590eb02e7
4
- data.tar.gz: 0f699f5d6a7dbc1ad7227a03e327155bf58d51e5
3
+ metadata.gz: 7225017d7223e594af331455293f27433870fc54
4
+ data.tar.gz: 8a6d5675f95ef83bb8d57818c880269a7bf9a753
5
5
  SHA512:
6
- metadata.gz: 9167289dc30d083a23ff0a33d62f78a49e6406858fd82dc7b4e4bad9fadcd876e98ad6a7279b58a272d0833bae4f3c2d67b2ed075899a4f1f839adf377e387ad
7
- data.tar.gz: b154836fd6304a5696017183b024978e7e598a203b66d63cbd5f135d13a8d0e56a30149a27a43243d518a3d7afbc4945e1d64c7f90868cefb1534046b88a40fa
6
+ metadata.gz: 6fff043157a10b5d613f7c8530e1864ab9aab13cd74935e1b83add8a3eef9ae36d10d8d7003631377adc0b09e30b70cc0d06bf0a81304314bdb8a9ad9fe19255
7
+ data.tar.gz: 97b4cea9c4a6c657765010bc1c9d66702fd150576f59aac025a7987ceb427483d412759c542f980751b1239ebdb18a7b89c919f6cc2bb20fc53a3eb4666c281b
@@ -6,7 +6,7 @@ module JekyllRelativeLinks
6
6
  include Jekyll::Filters::URLFilters
7
7
 
8
8
  LINK_TEXT_REGEX = %r!([^\]]+)!
9
- FRAGMENT_REGEX = %r!(#.+)?!
9
+ FRAGMENT_REGEX = %r!(#.+?)?!
10
10
  INLINE_LINK_REGEX = %r!\[#{LINK_TEXT_REGEX}\]\(([^\)]+?)#{FRAGMENT_REGEX}\)!
11
11
  REFERENCE_LINK_REGEX = %r!^\[#{LINK_TEXT_REGEX}\]: (.+?)#{FRAGMENT_REGEX}$!
12
12
  LINK_REGEX = %r!(#{INLINE_LINK_REGEX}|#{REFERENCE_LINK_REGEX})!
@@ -35,6 +35,8 @@ module JekyllRelativeLinks
35
35
 
36
36
  page.content.gsub!(LINK_REGEX) do |original|
37
37
  link_type, link_text, relative_path, fragment = link_parts(Regexp.last_match)
38
+ next original if fragment?(relative_path) || absolute_url?(relative_path)
39
+
38
40
  path = path_from_root(relative_path, url_base)
39
41
  url = url_for_path(path)
40
42
 
@@ -82,7 +84,7 @@ module JekyllRelativeLinks
82
84
  def path_from_root(relative_path, url_base)
83
85
  relative_path.sub!(%r!\A/!, "")
84
86
  absolute_path = File.expand_path(relative_path, url_base)
85
- absolute_path.sub(%r!\A#{Dir.pwd}/!, "")
87
+ absolute_path.sub(%r!\A#{Regexp.escape(Dir.pwd)}/!, "")
86
88
  end
87
89
 
88
90
  def replacement_text(type, text, url, fragment = nil)
@@ -94,5 +96,16 @@ module JekyllRelativeLinks
94
96
  "[#{text}]: #{url}"
95
97
  end
96
98
  end
99
+
100
+ def absolute_url?(string)
101
+ return unless string
102
+ Addressable::URI.parse(string).absolute?
103
+ rescue Addressable::URI::InvalidURIError
104
+ nil
105
+ end
106
+
107
+ def fragment?(string)
108
+ string && string.start_with?("#")
109
+ end
97
110
  end
98
111
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllRelativeLinks
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.4.1".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.4.0
4
+ version: 0.4.1
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-03-28 00:00:00.000000000 Z
11
+ date: 2017-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll