bunto-redirect-from 5.0.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +18 -18
- data/.rspec +2 -2
- data/.travis.yml +26 -26
- data/Gemfile +8 -8
- data/History.markdown +4 -3
- data/LICENSE.txt +22 -22
- data/README.md +129 -128
- data/Rakefile +6 -6
- data/bunto-redirect-from.gemspec +27 -27
- data/lib/bunto-redirect-from.rb +11 -4
- data/lib/bunto-redirect-from/redirect_page.rb +42 -34
- data/lib/bunto-redirect-from/redirector.rb +90 -86
- data/lib/bunto-redirect-from/version.rb +3 -3
- data/script/bootstrap +3 -3
- data/script/cibuild +4 -4
- data/script/release +3 -3
- data/script/test +2 -0
- data/spec/bunto_redirect_from/redirect_page_spec.rb +76 -72
- data/spec/bunto_redirect_from/redirector_spec.rb +149 -116
- data/spec/fixtures/_articles/redirect-me-plz.md +6 -6
- data/spec/fixtures/_articles/redirect-somewhere-else-im-a-permalink.html +7 -0
- data/spec/fixtures/_articles/redirect-somewhere-else-plz.html +6 -6
- data/spec/fixtures/_authors/kansaichris.md +5 -5
- data/spec/fixtures/_config.yml +7 -7
- data/spec/fixtures/_layouts/layout.html +6 -0
- data/spec/fixtures/_posts/2014-01-03-redirect-me-plz.md +6 -6
- data/spec/fixtures/multiple_redirect_tos.md +9 -9
- data/spec/fixtures/multiple_redirect_urls.md +10 -10
- data/spec/fixtures/one_redirect_to.md +6 -6
- data/spec/fixtures/one_redirect_url.md +6 -6
- data/spec/fixtures/tags/how we work.md +4 -0
- data/spec/integrations_spec.rb +13 -13
- data/spec/spec_helper.rb +88 -91
- metadata +18 -11
@@ -1,116 +1,149 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe BuntoRedirectFrom::Redirector do
|
4
|
-
let(:redirector) { described_class.new }
|
5
|
-
let(:post_to_redirect) { setup_post("2014-01-03-redirect-me-plz.md") }
|
6
|
-
let(:doc_to_redirect_from) { setup_doc("redirect-me-plz.md") }
|
7
|
-
let(:doc_to_redirect_to) { setup_doc("redirect-somewhere-else-plz.html") }
|
8
|
-
let(:
|
9
|
-
let(:
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
skip "Don't need to test posts in Bunto 3"
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
expect(
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
expect(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
expect(
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
expect(
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
it "
|
87
|
-
|
88
|
-
expect(
|
89
|
-
end
|
90
|
-
|
91
|
-
it "
|
92
|
-
|
93
|
-
expect(
|
94
|
-
end
|
95
|
-
|
96
|
-
it "
|
97
|
-
|
98
|
-
expect(
|
99
|
-
end
|
100
|
-
|
101
|
-
it "
|
102
|
-
|
103
|
-
|
104
|
-
expect(
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
@site.
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BuntoRedirectFrom::Redirector do
|
4
|
+
let(:redirector) { described_class.new }
|
5
|
+
let(:post_to_redirect) { setup_post("2014-01-03-redirect-me-plz.md") }
|
6
|
+
let(:doc_to_redirect_from) { setup_doc("redirect-me-plz.md") }
|
7
|
+
let(:doc_to_redirect_to) { setup_doc("redirect-somewhere-else-plz.html") }
|
8
|
+
let(:doc_to_redirect_to_permalnk) { setup_doc("redirect-somewhere-else-im-a-permalink.html") }
|
9
|
+
let(:page_with_one) { setup_page("one_redirect_url.md") }
|
10
|
+
let(:page_with_many) { setup_page("multiple_redirect_urls.md") }
|
11
|
+
let(:page_with_one_redirect_to) { setup_page("one_redirect_to.md") }
|
12
|
+
let(:page_with_many_redirect_to) { setup_page("multiple_redirect_tos.md") }
|
13
|
+
let(:page_to_redirect_to_permlnk) { setup_page("tags/how we work.md") }
|
14
|
+
|
15
|
+
it "knows if a page or post is requesting a redirect page" do
|
16
|
+
if BuntoRedirectFrom.bunto_3?
|
17
|
+
skip "Don't need to test posts in Bunto 3"
|
18
|
+
else
|
19
|
+
expect(redirector.has_alt_urls?(post_to_redirect)).to be_truthy
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "knows if a document is requesting a redirect page" do
|
24
|
+
expect(redirector.has_alt_urls?(doc_to_redirect_from)).to be_truthy
|
25
|
+
end
|
26
|
+
|
27
|
+
it "knows if a document is requesting a redirect away" do
|
28
|
+
expect(redirector.redirect_to_url(doc_to_redirect_to)).to eql(["http://www.zombo.com"])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "knows if a document is requesting a redirect away" do
|
32
|
+
expect(redirector.redirect_to_url(doc_to_redirect_to_permalnk)).to eql(["/tags/our-projects/"])
|
33
|
+
end
|
34
|
+
|
35
|
+
it "handles one redirect path" do
|
36
|
+
expect(redirector.alt_urls(page_with_one)).to eql(["mencius/was/my/father"])
|
37
|
+
end
|
38
|
+
|
39
|
+
it "handles many redirect paths" do
|
40
|
+
expect(redirector.alt_urls(page_with_many)).to eql(["help", "contact", "let-there/be/light-he-said", "/geepers/mccreepin"])
|
41
|
+
end
|
42
|
+
|
43
|
+
it "handles a single redirect_to url" do
|
44
|
+
expect(redirector.redirect_to_url(page_with_one_redirect_to)).to eql(["https://www.github.com"])
|
45
|
+
end
|
46
|
+
|
47
|
+
it "handles a many redirect_to urls" do
|
48
|
+
expect(redirector.redirect_to_url(page_with_many_redirect_to)).to eql(["https://www.buntorb.com"])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "does not include pages with a redirect in sitemap" do
|
52
|
+
expect(destination_sitemap).not_to include(%|one_redirect_to.html|)
|
53
|
+
end
|
54
|
+
|
55
|
+
context "refresh page generation" do
|
56
|
+
before(:each) do
|
57
|
+
described_class.new.generate(@site)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "generates the refresh page for the post properly" do
|
61
|
+
expect(dest_dir("posts/23128432159832/mary-had-a-little-lamb#{forced_output_ext}")).to exist
|
62
|
+
end
|
63
|
+
|
64
|
+
it "generates the refresh pages for the page with multiple redirect_from urls" do
|
65
|
+
expect(dest_dir("help")).to be_truthy
|
66
|
+
expect(dest_dir("contact")).to be_truthy
|
67
|
+
expect(dest_dir("let-there/be/light-he-said")).to be_truthy
|
68
|
+
expect(dest_dir("/geepers/mccreepin")).to be_truthy
|
69
|
+
end
|
70
|
+
|
71
|
+
it "generates the refresh page for the page with one redirect_from url" do
|
72
|
+
expect(dest_dir("mencius/was/my/father#{forced_output_ext}")).to exist
|
73
|
+
end
|
74
|
+
|
75
|
+
it "generates the refresh page for the collection with one redirect_to url" do
|
76
|
+
expect(dest_dir("articles", "redirect-somewhere-else-plz.html")).to exist
|
77
|
+
expect(dest_dir("articles", "redirect-somewhere-else-plz.html").read).to include(%|<meta http-equiv="refresh" content="0; url=http://www.zombo.com">|)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "generates the refresh page for the collection with one redirect_to url and a permalink" do
|
81
|
+
expect(dest_dir("tags", "our projects", "index")).not_to exist
|
82
|
+
expect(dest_dir("tags", "our projects", "index.html")).to exist
|
83
|
+
expect(dest_dir("tags", "our projects", "index.html").read).to include(%|<meta http-equiv="refresh" content="0; url=/tags/our-projects/">|)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "generates the refresh page for the page with one redirect_to url" do
|
87
|
+
expect(dest_dir("one_redirect_to.html")).to exist
|
88
|
+
expect(dest_dir("one_redirect_to.html").read).to include(%|<meta http-equiv="refresh" content="0; url=https://www.github.com">|)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "generates the refresh page for the page with multiple redirect_to urls" do
|
92
|
+
expect(dest_dir("multiple_redirect_tos.html")).to exist
|
93
|
+
expect(dest_dir("multiple_redirect_tos.html").read).to include(%|<meta http-equiv="refresh" content="0; url=https://www.buntorb.com">|)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "does not include any default layout" do
|
97
|
+
expect(dest_dir("multiple_redirect_tos.html")).to exist
|
98
|
+
expect(dest_dir("multiple_redirect_tos.html").read).not_to include('LAYOUT INCLUDED')
|
99
|
+
end
|
100
|
+
|
101
|
+
it "generates the refresh page for the page with one redirect_to url and a permalink" do
|
102
|
+
expect(dest_dir("tags", "how we work", "index")).not_to exist
|
103
|
+
expect(dest_dir("tags", "how we work", "index.html")).to exist
|
104
|
+
expect(dest_dir("tags", "how we work", "index.html").read).to include(%|<meta http-equiv="refresh" content="0; url=/tags/how-we-work/">|)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "prefix" do
|
109
|
+
it "uses site.url as the redirect prefix when site.github.url is not set" do
|
110
|
+
@site.config['url'] = "http://notgithub.io"
|
111
|
+
@site.config['baseurl'] = nil
|
112
|
+
expect(redirector.redirect_url(@site, page_with_one)).to eql("http://notgithub.io/one_redirect_url.html")
|
113
|
+
end
|
114
|
+
|
115
|
+
it "uses site.baseurl as the redirect prefix when site.github.url is not set" do
|
116
|
+
@site.config['url'] = nil
|
117
|
+
@site.config['baseurl'] = "/fancy/prefix"
|
118
|
+
expect(redirector.redirect_url(@site, page_with_one)).to eql("/fancy/prefix/one_redirect_url.html")
|
119
|
+
end
|
120
|
+
|
121
|
+
it "uses site.url + site.baseurl as the redirect prefix when site.github.url is not set" do
|
122
|
+
@site.config['url'] = "http://notgithub.io"
|
123
|
+
@site.config['baseurl'] = "/fancy/prefix"
|
124
|
+
expect(redirector.redirect_url(@site, page_with_one)).to eql("http://notgithub.io/fancy/prefix/one_redirect_url.html")
|
125
|
+
end
|
126
|
+
|
127
|
+
it "prefers site.github.url over site.url or site.baseurl" do
|
128
|
+
@site.config['url'] = "http://notgithub.io"
|
129
|
+
@site.config['baseurl'] = "/fancy/prefix"
|
130
|
+
@site.config['github'] = { "url" => "http://example.github.io/test" }
|
131
|
+
expect(redirector.redirect_url(@site, page_with_one)).to eql("http://example.github.io/test/one_redirect_url.html")
|
132
|
+
end
|
133
|
+
|
134
|
+
it "converts non-string values in site.github.url to strings" do
|
135
|
+
@site.config['github'] = { "url" => TestStringContainer.new("http://example.github.io/test") }
|
136
|
+
expect(redirector.redirect_url(@site, page_with_one)).to eql("http://example.github.io/test/one_redirect_url.html")
|
137
|
+
end
|
138
|
+
|
139
|
+
it "uses site.url when site.github is set but site.github.url is not" do
|
140
|
+
@site.config['github'] = "username"
|
141
|
+
expect(redirector.redirect_url(@site, page_with_one)).to eql("http://bunto.github.io/one_redirect_url.html")
|
142
|
+
end
|
143
|
+
|
144
|
+
it "no-ops when site.github.url and site.baseurl and site.url are not set" do
|
145
|
+
@site.config['url'] = nil
|
146
|
+
expect(redirector.redirect_url(@site, page_with_one)).to eql("/one_redirect_url.html")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
---
|
2
|
-
title: Please redirect me, sir.
|
3
|
-
redirect_from: /articles/23128432159832/mary-had-a-little-lamb
|
4
|
-
---
|
5
|
-
|
6
|
-
Yay.
|
1
|
+
---
|
2
|
+
title: Please redirect me, sir.
|
3
|
+
redirect_from: /articles/23128432159832/mary-had-a-little-lamb
|
4
|
+
---
|
5
|
+
|
6
|
+
Yay.
|
@@ -1,6 +1,6 @@
|
|
1
|
-
---
|
2
|
-
title: Please redirect away from me, sir.
|
3
|
-
redirect_to: "http://www.zombo.com"
|
4
|
-
---
|
5
|
-
|
6
|
-
Boo.
|
1
|
+
---
|
2
|
+
title: Please redirect away from me, sir.
|
3
|
+
redirect_to: "http://www.zombo.com"
|
4
|
+
---
|
5
|
+
|
6
|
+
Boo.
|
@@ -1,5 +1,5 @@
|
|
1
|
-
---
|
2
|
-
redirect_from: /kansaichris/
|
3
|
-
---
|
4
|
-
|
5
|
-
Hi.
|
1
|
+
---
|
2
|
+
redirect_from: /kansaichris/
|
3
|
+
---
|
4
|
+
|
5
|
+
Hi.
|
data/spec/fixtures/_config.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
url:
|
2
|
-
gems:
|
3
|
-
- bunto-redirect-from
|
4
|
-
- bunto-sitemap
|
5
|
-
collections:
|
6
|
-
articles:
|
7
|
-
output: true
|
1
|
+
url: https://bunto.github.io
|
2
|
+
gems:
|
3
|
+
- bunto-redirect-from
|
4
|
+
- bunto-sitemap
|
5
|
+
collections:
|
6
|
+
articles:
|
7
|
+
output: true
|
@@ -1,6 +1,6 @@
|
|
1
|
-
---
|
2
|
-
title: Please redirect me, sir.
|
3
|
-
redirect_from: /posts/23128432159832/mary-had-a-little-lamb
|
4
|
-
---
|
5
|
-
|
6
|
-
Yay.
|
1
|
+
---
|
2
|
+
title: Please redirect me, sir.
|
3
|
+
redirect_from: /posts/23128432159832/mary-had-a-little-lamb
|
4
|
+
---
|
5
|
+
|
6
|
+
Yay.
|
@@ -1,9 +1,9 @@
|
|
1
|
-
---
|
2
|
-
title: I have lots of redirect to urls
|
3
|
-
redirect_to:
|
4
|
-
- https://
|
5
|
-
- https://www.github.com
|
6
|
-
- https://www.twitter.com
|
7
|
-
---
|
8
|
-
|
9
|
-
Lots of redirect to urls.
|
1
|
+
---
|
2
|
+
title: I have lots of redirect to urls
|
3
|
+
redirect_to:
|
4
|
+
- https://bunto.github.io
|
5
|
+
- https://www.github.com
|
6
|
+
- https://www.twitter.com
|
7
|
+
---
|
8
|
+
|
9
|
+
Lots of redirect to urls.
|
@@ -1,10 +1,10 @@
|
|
1
|
-
---
|
2
|
-
title: I have lots of redirect urls
|
3
|
-
redirect_from:
|
4
|
-
- help
|
5
|
-
- contact
|
6
|
-
- let-there/be/light-he-said
|
7
|
-
- /geepers/mccreepin
|
8
|
-
---
|
9
|
-
|
10
|
-
Lots of redirect urls
|
1
|
+
---
|
2
|
+
title: I have lots of redirect urls
|
3
|
+
redirect_from:
|
4
|
+
- help
|
5
|
+
- contact
|
6
|
+
- let-there/be/light-he-said
|
7
|
+
- /geepers/mccreepin
|
8
|
+
---
|
9
|
+
|
10
|
+
Lots of redirect urls
|
@@ -1,6 +1,6 @@
|
|
1
|
-
---
|
2
|
-
title: I am going somewhere else.
|
3
|
-
redirect_to: https://www.github.com
|
4
|
-
---
|
5
|
-
|
6
|
-
Redirecting elsewhere.
|
1
|
+
---
|
2
|
+
title: I am going somewhere else.
|
3
|
+
redirect_to: https://www.github.com
|
4
|
+
---
|
5
|
+
|
6
|
+
Redirecting elsewhere.
|
@@ -1,6 +1,6 @@
|
|
1
|
-
---
|
2
|
-
title: I only have one redirect url.
|
3
|
-
redirect_from: mencius/was/my/father
|
4
|
-
---
|
5
|
-
|
6
|
-
One redirect url
|
1
|
+
---
|
2
|
+
title: I only have one redirect url.
|
3
|
+
redirect_from: mencius/was/my/father
|
4
|
+
---
|
5
|
+
|
6
|
+
One redirect url
|
data/spec/integrations_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe("Integration Tests") do
|
4
|
-
it "writes the redirect pages for collection items which are outputted" do
|
5
|
-
expect(
|
6
|
-
expect(
|
7
|
-
end
|
8
|
-
|
9
|
-
it "doesn't write redirect pages for collection items which are not outputted" do
|
10
|
-
expect(
|
11
|
-
expect(
|
12
|
-
end
|
13
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe("Integration Tests") do
|
4
|
+
it "writes the redirect pages for collection items which are outputted" do
|
5
|
+
expect(dest_dir("articles", "redirect-me-plz.html")).to exist
|
6
|
+
expect(dest_dir("articles", "23128432159832", "mary-had-a-little-lamb#{forced_output_ext}")).to exist
|
7
|
+
end
|
8
|
+
|
9
|
+
it "doesn't write redirect pages for collection items which are not outputted" do
|
10
|
+
expect(dest_dir("authors")).not_to exist
|
11
|
+
expect(dest_dir("kansaichris")).not_to exist
|
12
|
+
end
|
13
|
+
end
|