jekyll-relative-links 0.4.1 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7225017d7223e594af331455293f27433870fc54
4
- data.tar.gz: 8a6d5675f95ef83bb8d57818c880269a7bf9a753
3
+ metadata.gz: 351e7b664aa98021cf0c3f719ea7e2a0aaaf7895
4
+ data.tar.gz: 6ec9d3f4f76991b2ee7757ef2da9394fad71abee
5
5
  SHA512:
6
- metadata.gz: 6fff043157a10b5d613f7c8530e1864ab9aab13cd74935e1b83add8a3eef9ae36d10d8d7003631377adc0b09e30b70cc0d06bf0a81304314bdb8a9ad9fe19255
7
- data.tar.gz: 97b4cea9c4a6c657765010bc1c9d66702fd150576f59aac025a7987ceb427483d412759c542f980751b1239ebdb18a7b89c919f6cc2bb20fc53a3eb4666c281b
6
+ metadata.gz: a5ff53c27eee911580d3b66f40da628b5df9ff0f494cc8d246b9c2c1b7bf3f944213df60345f52e755a1d4398d31d5d8985add045c22507c2abfc4feecea1401
7
+ data.tar.gz: 7de7fcbb5ad99a925f1254d3195e5ac812a654a35abc5e3b645ed9a94471c6ef418526f12c03469cb91ff8a683455a7e77b13c6c1278e1916c424060f0878805
@@ -1,6 +1,6 @@
1
1
  require "jekyll"
2
- require "jekyll-relative-links/generator"
3
- require "jekyll-relative-links/context"
2
+ require_relative "jekyll-relative-links/generator"
3
+ require_relative "jekyll-relative-links/context"
4
4
 
5
5
  module JekyllRelativeLinks
6
6
  end
@@ -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.each do |page|
28
- next unless markdown_extension?(page.extname)
29
- replace_relative_links!(page)
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!(page)
34
- url_base = File.dirname(page.path)
40
+ def replace_relative_links!(document)
41
+ url_base = File.dirname(document.relative_path)
35
42
 
36
- page.content.gsub!(LINK_REGEX) do |original|
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 ||= (site.pages + site.static_files)
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
@@ -1,3 +1,3 @@
1
1
  module JekyllRelativeLinks
2
- VERSION = "0.4.1".freeze
2
+ VERSION = "0.5.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.4.1
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-06-16 00:00:00.000000000 Z
11
+ date: 2017-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll