jekyll-relative-links 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-relative-links/generator.rb +37 -18
- data/lib/jekyll-relative-links/version.rb +1 -1
- metadata +62 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc58c9b968be5f460493796546b5da7dcb3ec9dc70521790e7475945eb7808ff
|
4
|
+
data.tar.gz: ff9390b8df13ac3cbdd9034a2bfdac93b14e8f0d3a9396a07839f2be791b87ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67c213b7308561caee8f28bb8132667d0f5fc8d9001c74eb65cbde328a81265a4183863762f5934f262ffa676504f19b9011eac679e2f5abc9583e1d019c46cb
|
7
|
+
data.tar.gz: '012508fa52c056fcd891c15bb2d75e636e97053e3e53b244f5a63fa66edde0aa68ff760fbb0816fe07f149105770803f6be604da7e1029647a4af7d4120c3340'
|
@@ -8,9 +8,11 @@ module JekyllRelativeLinks
|
|
8
8
|
include Jekyll::Filters::URLFilters
|
9
9
|
|
10
10
|
LINK_TEXT_REGEX = %r!(.*?)!.freeze
|
11
|
-
FRAGMENT_REGEX = %r!(
|
12
|
-
|
13
|
-
|
11
|
+
FRAGMENT_REGEX = %r!(#.+?|)?!.freeze
|
12
|
+
TITLE_REGEX = %r{(\s+"(?:\\"|[^"])*(?<!\\)"|\s+"(?:\\'|[^'])*(?<!\\)')?}.freeze
|
13
|
+
FRAG_AND_TITLE_REGEX = %r!#{FRAGMENT_REGEX}#{TITLE_REGEX}!.freeze
|
14
|
+
INLINE_LINK_REGEX = %r!\[#{LINK_TEXT_REGEX}\]\(([^)]+?)#{FRAG_AND_TITLE_REGEX}\)!.freeze
|
15
|
+
REFERENCE_LINK_REGEX = %r!^\s*?\[#{LINK_TEXT_REGEX}\]: (.+?)#{FRAG_AND_TITLE_REGEX}\s*?$!.freeze
|
14
16
|
LINK_REGEX = %r!(#{INLINE_LINK_REGEX}|#{REFERENCE_LINK_REGEX})!.freeze
|
15
17
|
CONVERTER_CLASS = Jekyll::Converters::Markdown
|
16
18
|
CONFIG_KEY = "relative_links"
|
@@ -48,27 +50,35 @@ module JekyllRelativeLinks
|
|
48
50
|
return document if document.content.nil?
|
49
51
|
|
50
52
|
document.content = document.content.dup.gsub(LINK_REGEX) do |original|
|
51
|
-
|
52
|
-
next original unless replaceable_link?(
|
53
|
+
link = link_parts(Regexp.last_match)
|
54
|
+
next original unless replaceable_link?(link.path)
|
53
55
|
|
54
|
-
path = path_from_root(
|
56
|
+
path = path_from_root(link.path, url_base)
|
55
57
|
url = url_for_path(path)
|
56
58
|
next original unless url
|
57
59
|
|
58
|
-
|
60
|
+
link.path = url
|
61
|
+
replacement_text(link)
|
59
62
|
end
|
63
|
+
|
64
|
+
replace_relative_links_excerpt!(document)
|
60
65
|
rescue ArgumentError => e
|
61
66
|
raise e unless e.to_s.start_with?("invalid byte sequence in UTF-8")
|
62
67
|
end
|
63
68
|
|
64
69
|
private
|
65
70
|
|
71
|
+
# Stores info on a Markdown Link (avoid rubocop's Metrics/ParameterLists warning)
|
72
|
+
Link = Struct.new(:link_type, :text, :path, :fragment, :title)
|
73
|
+
|
66
74
|
def link_parts(matches)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
[link_type
|
75
|
+
last_inline = 5
|
76
|
+
link_type = matches[2] ? :inline : :reference
|
77
|
+
link_text = matches[link_type == :inline ? 2 : last_inline + 1]
|
78
|
+
relative_path = matches[link_type == :inline ? 3 : last_inline + 2]
|
79
|
+
fragment = matches[link_type == :inline ? 4 : last_inline + 3]
|
80
|
+
title = matches[link_type == :inline ? 5 : last_inline + 4]
|
81
|
+
Link.new(link_type, link_text, relative_path, fragment, title)
|
72
82
|
end
|
73
83
|
|
74
84
|
def context
|
@@ -84,6 +94,7 @@ module JekyllRelativeLinks
|
|
84
94
|
end
|
85
95
|
|
86
96
|
def url_for_path(path)
|
97
|
+
path = CGI.unescape(path)
|
87
98
|
target = potential_targets.find { |p| p.relative_path.sub(%r!\A/!, "") == path }
|
88
99
|
relative_url(target.url) if target&.url
|
89
100
|
end
|
@@ -93,18 +104,22 @@ module JekyllRelativeLinks
|
|
93
104
|
end
|
94
105
|
|
95
106
|
def path_from_root(relative_path, url_base)
|
107
|
+
is_absolute = relative_path.start_with? "/"
|
108
|
+
|
96
109
|
relative_path.sub!(%r!\A/!, "")
|
97
|
-
|
110
|
+
base = is_absolute ? "" : url_base
|
111
|
+
absolute_path = File.expand_path(relative_path, base)
|
98
112
|
absolute_path.sub(%r!\A#{Regexp.escape(Dir.pwd)}/!, "")
|
99
113
|
end
|
100
114
|
|
101
|
-
|
102
|
-
|
115
|
+
# @param link [Link] A Link object describing the markdown link to make
|
116
|
+
def replacement_text(link)
|
117
|
+
link.path << link.fragment if link.fragment
|
103
118
|
|
104
|
-
if
|
105
|
-
"[#{text}](#{
|
119
|
+
if link.link_type == :inline
|
120
|
+
"[#{link.text}](#{link.path}#{link.title})"
|
106
121
|
else
|
107
|
-
"\n[#{text}]: #{
|
122
|
+
"\n[#{link.text}]: #{link.path}#{link.title}"
|
108
123
|
end
|
109
124
|
end
|
110
125
|
|
@@ -153,5 +168,9 @@ module JekyllRelativeLinks
|
|
153
168
|
def global_entry_filter
|
154
169
|
@global_entry_filter ||= Jekyll::EntryFilter.new(site)
|
155
170
|
end
|
171
|
+
|
172
|
+
def replace_relative_links_excerpt!(document)
|
173
|
+
document.data["excerpt"] = Jekyll::Excerpt.new(document) if document.data["excerpt"]
|
174
|
+
end
|
156
175
|
end
|
157
176
|
end
|
metadata
CHANGED
@@ -1,29 +1,49 @@
|
|
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.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.3'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '3.3'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: kramdown-parser-gfm
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: rspec
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,37 +62,59 @@ dependencies:
|
|
42
62
|
name: rubocop
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
44
64
|
requirements:
|
45
|
-
- - "
|
65
|
+
- - "~>"
|
46
66
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
|
67
|
+
version: '1.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rubocop-jekyll
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
49
80
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
81
|
+
version: '0.10'
|
51
82
|
type: :development
|
52
83
|
prerelease: false
|
53
84
|
version_requirements: !ruby/object:Gem::Requirement
|
54
85
|
requirements:
|
55
|
-
- - "
|
86
|
+
- - "~>"
|
56
87
|
- !ruby/object:Gem::Version
|
57
|
-
version: 0.
|
58
|
-
|
88
|
+
version: '0.10'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rubocop-performance
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
59
94
|
- !ruby/object:Gem::Version
|
60
|
-
version: 1.
|
95
|
+
version: '1.5'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.5'
|
61
103
|
- !ruby/object:Gem::Dependency
|
62
|
-
name: rubocop-
|
104
|
+
name: rubocop-rspec
|
63
105
|
requirement: !ruby/object:Gem::Requirement
|
64
106
|
requirements:
|
65
107
|
- - "~>"
|
66
108
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
109
|
+
version: '2.0'
|
68
110
|
type: :development
|
69
111
|
prerelease: false
|
70
112
|
version_requirements: !ruby/object:Gem::Requirement
|
71
113
|
requirements:
|
72
114
|
- - "~>"
|
73
115
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
75
|
-
description:
|
116
|
+
version: '2.0'
|
117
|
+
description:
|
76
118
|
email:
|
77
119
|
- ben.balter@github.com
|
78
120
|
executables: []
|
@@ -87,7 +129,7 @@ homepage: https://github.com/benbalter/jekyll-relative-links
|
|
87
129
|
licenses:
|
88
130
|
- MIT
|
89
131
|
metadata: {}
|
90
|
-
post_install_message:
|
132
|
+
post_install_message:
|
91
133
|
rdoc_options: []
|
92
134
|
require_paths:
|
93
135
|
- lib
|
@@ -102,8 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
144
|
- !ruby/object:Gem::Version
|
103
145
|
version: '0'
|
104
146
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
106
|
-
signing_key:
|
147
|
+
rubygems_version: 3.2.33
|
148
|
+
signing_key:
|
107
149
|
specification_version: 4
|
108
150
|
summary: A Jekyll plugin to convert relative links to markdown files to their rendered
|
109
151
|
equivalents.
|