jekyll-absolute-links 0.1.0 → 0.1.1
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 +4 -4
- data/.gitignore +0 -1
- data/README.md +5 -3
- data/lib/jekyll-absolute-links/crawler.rb +3 -2
- data/lib/jekyll-absolute-links/version.rb +1 -1
- data/spec/crawler_spec.rb +102 -43
- data/spec/fixtures/absolute-links/_includes/sitemap-entry.xml +7 -0
- data/spec/fixtures/absolute-links/{feed.xml → _layouts/feed.xml} +0 -4
- data/spec/fixtures/absolute-links/_layouts/sitemap.xml +13 -0
- data/spec/fixtures/absolute-links/_posts/2001-01-01-lorem-ipsum-dolor-sit-amet.md +14 -1
- data/spec/fixtures/absolute-links/_posts/2001-01-02-curabitur-sed-condimentum-enim.md +1 -1
- data/spec/fixtures/absolute-links/feed.md +4 -0
- data/spec/fixtures/absolute-links/morbi-ultrices-nulla.md +1 -2
- data/spec/fixtures/absolute-links/sitemap.md +4 -0
- metadata +12 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8953fcf8fed5a4afe3558f5c59fef7a0454bc943
|
4
|
+
data.tar.gz: 69a20c42d22cc0432071884c0685133495f5cd09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e94a663c8b3a9293f5c043e9a383f012f2ed01d0e6888e98827d33c1a264dda5419fafa3b888aed061547901e0beabd4f62e6407196c26e5a584eadac6304546
|
7
|
+
data.tar.gz: 5b96bbd373164729583152f39b571bede91203d785cf7dfd12302316876c5142608408206c0ff482f421271ba9cbdd8f4681637fb7da151512202cd95ab35197
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Jekyll Absolute Links
|
2
2
|
|
3
|
+
[](https://travis-ci.org/rukbotto/jekyll-absolute-links)
|
4
|
+
|
3
5
|
Absolute link converter for Jekyll sites. Crawls the generated HTML and XML
|
4
6
|
files in search of relative links and transform them to absolute links by
|
5
7
|
prepending the site domain.
|
@@ -38,9 +40,9 @@ production site only.
|
|
38
40
|
|
39
41
|
## Development
|
40
42
|
|
41
|
-
After checking out the repo, run `
|
42
|
-
`rake spec` to run the tests. You can also run `
|
43
|
-
prompt that will allow you to experiment.
|
43
|
+
After checking out the repo, run `script/setup` to install dependencies. Then,
|
44
|
+
run `rake spec` to run the tests. You can also run `script/console` for an
|
45
|
+
interactive prompt that will allow you to experiment.
|
44
46
|
|
45
47
|
To install this gem onto your local machine, run `bundle exec rake install`. To
|
46
48
|
release a new version, update the version number in `version.rb`, and then run
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module JekyllAbsoluteLinks
|
2
2
|
class Crawler
|
3
|
-
@regexp = %r{("
|
3
|
+
@regexp = %r{<(?!code)[^<>]*((href|src)=("|')|>)(([^<>]*(?<="))?(?<url>/[^<> ]*)((?=")[^<>]*)?)("|'|<(?!/code))[^<>]*>}
|
4
4
|
|
5
5
|
Jekyll::Hooks.register :posts, :post_render do |post|
|
6
6
|
next if Jekyll::env == "development"
|
@@ -16,7 +16,8 @@ module JekyllAbsoluteLinks
|
|
16
16
|
private
|
17
17
|
def transform(output, regexp, site_url)
|
18
18
|
output.gsub!(regexp) do |match|
|
19
|
-
|
19
|
+
url = Regexp.last_match[:url]
|
20
|
+
match.gsub(url, "#{site_url}#{url}".sub(%r{(\w)/+}, "\\1/"))
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
data/spec/crawler_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe JekyllAbsoluteLinks::Crawler do
|
4
4
|
let(:overrides) { Hash.new }
|
5
5
|
let(:site_config) do
|
6
6
|
Jekyll.configuration(Jekyll::Utils.deep_merge_hashes({
|
@@ -14,84 +14,143 @@ describe(JekyllAbsoluteLinks::Crawler) do
|
|
14
14
|
site.process
|
15
15
|
end
|
16
16
|
|
17
|
-
context
|
18
|
-
describe
|
19
|
-
it
|
20
|
-
|
21
|
-
expect(site.posts[0].output).to include(
|
17
|
+
context "When development environment is active" do
|
18
|
+
describe "Crawler" do
|
19
|
+
it "performs no link transformation on posts" do
|
20
|
+
a = "<a href=\"/posts/curabitur-sed-condimentum-enim/\">"
|
21
|
+
expect(site.posts[0].output).to include(a)
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
|
26
|
-
expect(site.pages[1].output).to include(
|
24
|
+
it "performs no link transformation on pages" do
|
25
|
+
a = "<a href=\"/posts/lorem-ipsum-dolor-sit-amet/\">"
|
26
|
+
expect(site.pages[1].output).to include(a)
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
|
31
|
-
expect(site.pages[
|
29
|
+
it "performs no link transformation on sitemaps" do
|
30
|
+
loc = "<loc>/posts/lorem-ipsum-dolor-sit-amet/</loc>"
|
31
|
+
expect(site.pages[2].output).to include(loc)
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
|
36
|
-
expect(site.pages[0].output).to include(
|
34
|
+
it "performs no link transformation on feeds" do
|
35
|
+
atom_link = "<atom:link href=\"/feed.xml\" rel=\"self\" type=\"application/rss+xml\"/>"
|
36
|
+
expect(site.pages[0].output).to include(atom_link)
|
37
|
+
|
38
|
+
link = "<link>/posts/lorem-ipsum-dolor-sit-amet/</link>"
|
39
|
+
expect(site.pages[0].output).to include(link)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "performs no encoded link transformation on feeds" do
|
43
|
+
a = <<-eos
|
44
|
+
<description><p>Curabitur sed condimentum enim. Integer ut velit vitae ante facilisis
|
45
|
+
consequat. Nullam egestas ipsum sit amet nibh ornare, non consequat massa
|
46
|
+
dictum. Fusce porttitor iaculis velit elementum feugiat. Lorem ipsum dolor sit
|
47
|
+
amet, consectetur adipiscing elit. Morbi nisi tortor, aliquet et eros id,
|
48
|
+
cursus tincidunt sapien. <a href="/posts/lorem-ipsum-dolor-sit-amet/">Lorem ipsum dolor sit amet</a>.</p>
|
49
|
+
|
50
|
+
</description>
|
51
|
+
eos
|
52
|
+
expect(site.pages[0].output).to include(a)
|
37
53
|
end
|
38
54
|
end
|
39
55
|
end
|
40
56
|
|
41
|
-
context
|
57
|
+
context "When production environment is active" do
|
42
58
|
around(:each) do |example|
|
43
59
|
ENV["JEKYLL_ENV"] = "production"
|
44
60
|
example.run
|
45
61
|
end
|
46
62
|
|
47
|
-
describe
|
48
|
-
it
|
49
|
-
|
50
|
-
expect(site.posts[0].output).to include(
|
63
|
+
describe "Crawler" do
|
64
|
+
it "transforms relative urls to absolute urls on posts" do
|
65
|
+
a = "<a href=\"http://example.com/posts/curabitur-sed-condimentum-enim/\">"
|
66
|
+
expect(site.posts[0].output).to include(a)
|
51
67
|
end
|
52
68
|
|
53
|
-
it
|
54
|
-
|
55
|
-
expect(site.
|
69
|
+
it "performs no link transformation inside code snippets" do
|
70
|
+
code = "<code class=\"highlighter-rouge\">/</code>"
|
71
|
+
expect(site.posts[0].output).to include(code)
|
72
|
+
|
73
|
+
code = "<code><span class=\"nt\"><a</span> <span class=\"na\">href=</span><span class=\"s\">\"/\"</span><span class=\"nt\">></span>Hello<span class=\"nt\"></a></span>\n</code>"
|
74
|
+
expect(site.posts[0].output).to include(code)
|
75
|
+
|
76
|
+
code = "<code><a href=\"/\">Hello</a>\n</code>"
|
77
|
+
expect(site.posts[0].output).to include(code)
|
56
78
|
end
|
57
79
|
|
58
|
-
it
|
59
|
-
|
60
|
-
expect(site.pages[
|
80
|
+
it "transforms relative urls to absolute urls on pages" do
|
81
|
+
a = "<a href=\"http://example.com/posts/lorem-ipsum-dolor-sit-amet/\">"
|
82
|
+
expect(site.pages[1].output).to include(a)
|
61
83
|
end
|
62
84
|
|
63
|
-
it
|
64
|
-
|
65
|
-
expect(site.pages[
|
85
|
+
it "transforms relative urls to absolute urls on sitemaps" do
|
86
|
+
loc = "<loc>http://example.com/posts/lorem-ipsum-dolor-sit-amet/</loc>"
|
87
|
+
expect(site.pages[2].output).to include(loc)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "transforms relative urls to absolute urls on feeds" do
|
91
|
+
atom_link = "<atom:link href=\"http://example.com/feed.xml\" rel=\"self\" type=\"application/rss+xml\"/>"
|
92
|
+
expect(site.pages[0].output).to include(atom_link)
|
93
|
+
|
94
|
+
link = "<link>http://example.com/posts/lorem-ipsum-dolor-sit-amet/</link>"
|
95
|
+
expect(site.pages[0].output).to include(link)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "transforms relative encoded urls to absolute urls on feeds" do
|
99
|
+
a = <<-eos
|
100
|
+
<description><p>Curabitur sed condimentum enim. Integer ut velit vitae ante facilisis
|
101
|
+
consequat. Nullam egestas ipsum sit amet nibh ornare, non consequat massa
|
102
|
+
dictum. Fusce porttitor iaculis velit elementum feugiat. Lorem ipsum dolor sit
|
103
|
+
amet, consectetur adipiscing elit. Morbi nisi tortor, aliquet et eros id,
|
104
|
+
cursus tincidunt sapien. <a href="http://example.com/posts/lorem-ipsum-dolor-sit-amet/">Lorem ipsum dolor sit amet</a>.</p>
|
105
|
+
|
106
|
+
</description>
|
107
|
+
eos
|
108
|
+
expect(site.pages[0].output).to include(a)
|
66
109
|
end
|
67
110
|
end
|
68
111
|
|
69
|
-
context
|
112
|
+
context "And site domain has a trailing slash" do
|
70
113
|
let(:overrides) do
|
71
114
|
{
|
72
115
|
"url" => "http://example.com/"
|
73
116
|
}
|
74
117
|
end
|
75
118
|
|
76
|
-
describe
|
77
|
-
it
|
78
|
-
|
79
|
-
expect(site.posts[0].output).to include(
|
119
|
+
describe "Crawler" do
|
120
|
+
it "Removes duplicate slashes from urls on posts" do
|
121
|
+
a = "<a href=\"http://example.com/posts/curabitur-sed-condimentum-enim/\">"
|
122
|
+
expect(site.posts[0].output).to include(a)
|
80
123
|
end
|
81
124
|
|
82
|
-
it
|
83
|
-
|
84
|
-
expect(site.pages[1].output).to include(
|
125
|
+
it "Removes duplicate slashes from urls on pages" do
|
126
|
+
a = "<a href=\"http://example.com/posts/lorem-ipsum-dolor-sit-amet/\">"
|
127
|
+
expect(site.pages[1].output).to include(a)
|
85
128
|
end
|
86
129
|
|
87
|
-
it
|
88
|
-
|
89
|
-
expect(site.pages[
|
130
|
+
it "Removes duplicate slashes from urls on sitemaps" do
|
131
|
+
loc = "<loc>http://example.com/posts/lorem-ipsum-dolor-sit-amet/</loc>"
|
132
|
+
expect(site.pages[2].output).to include(loc)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "Removes duplicate slashes from urls on feeds" do
|
136
|
+
atom_link = "<atom:link href=\"http://example.com/feed.xml\" rel=\"self\" type=\"application/rss+xml\"/>"
|
137
|
+
expect(site.pages[0].output).to include(atom_link)
|
138
|
+
|
139
|
+
link = "<link>http://example.com/posts/lorem-ipsum-dolor-sit-amet/</link>"
|
140
|
+
expect(site.pages[0].output).to include(link)
|
90
141
|
end
|
91
142
|
|
92
|
-
it
|
93
|
-
|
94
|
-
|
143
|
+
it "Removes duplicate slashes from encoded urls on feeds" do
|
144
|
+
a = <<-eos
|
145
|
+
<description><p>Curabitur sed condimentum enim. Integer ut velit vitae ante facilisis
|
146
|
+
consequat. Nullam egestas ipsum sit amet nibh ornare, non consequat massa
|
147
|
+
dictum. Fusce porttitor iaculis velit elementum feugiat. Lorem ipsum dolor sit
|
148
|
+
amet, consectetur adipiscing elit. Morbi nisi tortor, aliquet et eros id,
|
149
|
+
cursus tincidunt sapien. <a href="http://example.com/posts/lorem-ipsum-dolor-sit-amet/">Lorem ipsum dolor sit amet</a>.</p>
|
150
|
+
|
151
|
+
</description>
|
152
|
+
eos
|
153
|
+
expect(site.pages[0].output).to include(a)
|
95
154
|
end
|
96
155
|
end
|
97
156
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
3
|
+
{% for post in site.posts %}
|
4
|
+
{% unless post.no_sitemap %}
|
5
|
+
{% include sitemap-entry.xml doc=post %}
|
6
|
+
{% endunless %}
|
7
|
+
{% endfor %}
|
8
|
+
{% for page in site.pages %}
|
9
|
+
{% unless page.no_sitemap %}
|
10
|
+
{% include sitemap-entry.xml doc=page %}
|
11
|
+
{% endunless %}
|
12
|
+
{% endfor %}
|
13
|
+
</urlset>
|
@@ -6,6 +6,19 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vitae imperdiet
|
|
6
6
|
magna. Maecenas suscipit quis nisi vel cursus. In hac habitasse platea
|
7
7
|
dictumst. Sed a mi eu magna semper porta. Donec mollis, leo sit amet elementum
|
8
8
|
egestas, est nibh euismod mauris, quis molestie libero ex in erat. [Curabitur
|
9
|
-
sed condimentum enim][link]
|
9
|
+
sed condimentum enim][link].
|
10
|
+
|
11
|
+
```html
|
12
|
+
<a href="/">Hello</a>
|
13
|
+
```
|
14
|
+
|
15
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vitae imperdiet
|
16
|
+
magna. Maecenas `/` suscipit quis nisi vel cursus. In hac habitasse platea
|
17
|
+
dictumst. Sed a mi eu magna semper porta. Donec mollis, leo sit amet elementum
|
18
|
+
egestas, est nibh euismod mauris, quis molestie libero ex in erat.
|
19
|
+
|
20
|
+
```
|
21
|
+
<a href="/">Hello</a>
|
22
|
+
```
|
10
23
|
|
11
24
|
[link]: /posts/curabitur-sed-condimentum-enim/
|
@@ -6,6 +6,6 @@ Curabitur sed condimentum enim. Integer ut velit vitae ante facilisis
|
|
6
6
|
consequat. Nullam egestas ipsum sit amet nibh ornare, non consequat massa
|
7
7
|
dictum. Fusce porttitor iaculis velit elementum feugiat. Lorem ipsum dolor sit
|
8
8
|
amet, consectetur adipiscing elit. Morbi nisi tortor, aliquet et eros id,
|
9
|
-
cursus tincidunt sapien. [Lorem ipsum dolor sit amet][link]
|
9
|
+
cursus tincidunt sapien. [Lorem ipsum dolor sit amet][link].
|
10
10
|
|
11
11
|
[link]: /posts/lorem-ipsum-dolor-sit-amet/
|
@@ -7,7 +7,6 @@ Morbi ultrices nulla et dolor auctor elementum. In lacinia, leo et dignissim
|
|
7
7
|
ornare, lectus odio lacinia nibh, nec vehicula nisi nulla a massa. Aliquam
|
8
8
|
vulputate, risus ut dapibus tristique, sem nibh posuere elit, id venenatis odio
|
9
9
|
dui non arcu. Duis ut justo consectetur, consequat odio vitae, vulputate urna.
|
10
|
-
|
11
|
-
[Lorem ipsum dolor sit amet][link]
|
10
|
+
[Lorem ipsum dolor sit amet][link].
|
12
11
|
|
13
12
|
[link]: /posts/lorem-ipsum-dolor-sit-amet/
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-absolute-links
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Miguel Venegas Mendoza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -91,11 +91,15 @@ files:
|
|
91
91
|
- script/setup
|
92
92
|
- spec/crawler_spec.rb
|
93
93
|
- spec/fixtures/absolute-links/_config.yml
|
94
|
+
- spec/fixtures/absolute-links/_includes/sitemap-entry.xml
|
94
95
|
- spec/fixtures/absolute-links/_layouts/default.html
|
96
|
+
- spec/fixtures/absolute-links/_layouts/feed.xml
|
97
|
+
- spec/fixtures/absolute-links/_layouts/sitemap.xml
|
95
98
|
- spec/fixtures/absolute-links/_posts/2001-01-01-lorem-ipsum-dolor-sit-amet.md
|
96
99
|
- spec/fixtures/absolute-links/_posts/2001-01-02-curabitur-sed-condimentum-enim.md
|
97
|
-
- spec/fixtures/absolute-links/feed.
|
100
|
+
- spec/fixtures/absolute-links/feed.md
|
98
101
|
- spec/fixtures/absolute-links/morbi-ultrices-nulla.md
|
102
|
+
- spec/fixtures/absolute-links/sitemap.md
|
99
103
|
- spec/spec_helper.rb
|
100
104
|
homepage: https://github.com/rukbotto/jekyll-absolute-links
|
101
105
|
licenses:
|
@@ -124,9 +128,13 @@ summary: Absolute link converter for Jekyll sites.
|
|
124
128
|
test_files:
|
125
129
|
- spec/crawler_spec.rb
|
126
130
|
- spec/fixtures/absolute-links/_config.yml
|
131
|
+
- spec/fixtures/absolute-links/_includes/sitemap-entry.xml
|
127
132
|
- spec/fixtures/absolute-links/_layouts/default.html
|
133
|
+
- spec/fixtures/absolute-links/_layouts/feed.xml
|
134
|
+
- spec/fixtures/absolute-links/_layouts/sitemap.xml
|
128
135
|
- spec/fixtures/absolute-links/_posts/2001-01-01-lorem-ipsum-dolor-sit-amet.md
|
129
136
|
- spec/fixtures/absolute-links/_posts/2001-01-02-curabitur-sed-condimentum-enim.md
|
130
|
-
- spec/fixtures/absolute-links/feed.
|
137
|
+
- spec/fixtures/absolute-links/feed.md
|
131
138
|
- spec/fixtures/absolute-links/morbi-ultrices-nulla.md
|
139
|
+
- spec/fixtures/absolute-links/sitemap.md
|
132
140
|
- spec/spec_helper.rb
|