jekyll-relative-links 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/jekyll-relative-links.rb +5 -0
- data/lib/jekyll-relative-links/generator.rb +53 -0
- data/lib/jekyll-relative-links/version.rb +3 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f45852192eb95134507fc570ebe481c41cfc7a88
|
4
|
+
data.tar.gz: a60354c871e85d9b4b064398536a7f8cc975f7d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '082150b47db3d14a1897215f4b06372354c88bcd931897dbb0daf592d69108f98d2a04987c4df07cc33823f80c41189a8a93d48654e712c39ae7e1277ffd5efe'
|
7
|
+
data.tar.gz: dfa5b4c7dfbe0561dd9e5a22935be29a436c558fc7b14f7162946b83c2174554e860b053aa87e8a2351b3794b1d4a7e8a89dbae6d7fa1a5d750edaeba78f360e
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module JekyllRelativeLinks
|
2
|
+
class Generator < Jekyll::Generator
|
3
|
+
attr_accessor :site
|
4
|
+
|
5
|
+
LINK_REGEX = %r!\[([^\]]+)\]\(([^\)]+)\)!
|
6
|
+
CONVERTER_CLASS = Jekyll::Converters::Markdown
|
7
|
+
|
8
|
+
safe true
|
9
|
+
priority :lowest
|
10
|
+
|
11
|
+
def initialize(site)
|
12
|
+
@site = site
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate(site)
|
16
|
+
site.pages.each do |page|
|
17
|
+
next unless markdown_extension?(page.extname)
|
18
|
+
url_base = File.dirname(page.path)
|
19
|
+
|
20
|
+
page.content.gsub!(LINK_REGEX) do |original|
|
21
|
+
link_text = Regexp.last_match(1)
|
22
|
+
relative_path = Regexp.last_match(2).sub(%r!\A/!, "")
|
23
|
+
absolute_path = File.expand_path(relative_path, url_base)
|
24
|
+
path_from_root = absolute_path.sub(%r!\A#{Dir.pwd}/!, "")
|
25
|
+
|
26
|
+
if (url = url_for_path(path_from_root))
|
27
|
+
"[#{link_text}](#{site.baseurl}#{url})"
|
28
|
+
else
|
29
|
+
original
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def markdown_extension?(extension)
|
38
|
+
markdown_converter.matches(extension)
|
39
|
+
end
|
40
|
+
|
41
|
+
def markdown_converter
|
42
|
+
@markdown_converter ||= site.find_converter_instance(CONVERTER_CLASS)
|
43
|
+
end
|
44
|
+
|
45
|
+
def url_for_path(path)
|
46
|
+
extension = File.extname(path)
|
47
|
+
return unless markdown_extension?(extension)
|
48
|
+
|
49
|
+
page = site.pages.find { |p| p.path == path }
|
50
|
+
page.url if page
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-relative-links
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Balter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.43'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.43'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- ben.balter@github.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/jekyll-relative-links.rb
|
63
|
+
- lib/jekyll-relative-links/generator.rb
|
64
|
+
- lib/jekyll-relative-links/version.rb
|
65
|
+
homepage: https://github.com/benbalter/jekyll-relative-links
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.6.8
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: A Jekyll plugin to convert relative links to markdown files to their rendered
|
89
|
+
equivalents.
|
90
|
+
test_files: []
|