jekyll-relative-links 0.6.1 → 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 +51 -9
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,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
|
+
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
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
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'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: rspec
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,14 +64,14 @@ dependencies:
|
|
50
64
|
requirements:
|
51
65
|
- - "~>"
|
52
66
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0
|
67
|
+
version: '1.0'
|
54
68
|
type: :development
|
55
69
|
prerelease: false
|
56
70
|
version_requirements: !ruby/object:Gem::Requirement
|
57
71
|
requirements:
|
58
72
|
- - "~>"
|
59
73
|
- !ruby/object:Gem::Version
|
60
|
-
version: '0
|
74
|
+
version: '1.0'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: rubocop-jekyll
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,7 +86,35 @@ dependencies:
|
|
72
86
|
- - "~>"
|
73
87
|
- !ruby/object:Gem::Version
|
74
88
|
version: '0.10'
|
75
|
-
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rubocop-performance
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
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'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rubocop-rspec
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '2.0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
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.
|