jekyll-redirect-from 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.rubocop.yml +14 -0
- data/.travis.yml +1 -8
- data/Gemfile +0 -2
- data/History.markdown +20 -0
- data/README.md +12 -3
- data/jekyll-redirect-from.gemspec +2 -1
- data/lib/jekyll-redirect-from.rb +12 -6
- data/lib/jekyll-redirect-from/context.rb +14 -0
- data/lib/jekyll-redirect-from/generator.rb +38 -0
- data/lib/jekyll-redirect-from/layout.rb +17 -0
- data/lib/jekyll-redirect-from/redirect.html +10 -0
- data/lib/jekyll-redirect-from/redirect_page.rb +52 -33
- data/lib/jekyll-redirect-from/redirectable.rb +25 -0
- data/lib/jekyll-redirect-from/version.rb +1 -1
- data/script/cibuild +2 -0
- data/spec/fixtures/{multiple_redirect_urls.md → multiple_redirect_froms.md} +0 -0
- data/spec/fixtures/one_redirect_from.md +6 -0
- data/spec/fixtures/one_redirect_to_path.md +6 -0
- data/spec/fixtures/{one_redirect_to.md → one_redirect_to_url.md} +1 -1
- data/spec/integrations_spec.rb +81 -8
- data/spec/jekyll_redirect_from/context_spec.rb +12 -0
- data/spec/jekyll_redirect_from/generator_spec.rb +87 -0
- data/spec/jekyll_redirect_from/layout_spec.rb +32 -0
- data/spec/jekyll_redirect_from/redirect_page_spec.rb +173 -42
- data/spec/jekyll_redirect_from/redirectable_spec.rb +61 -0
- data/spec/spec_helper.rb +29 -60
- metadata +43 -18
- data/lib/jekyll-redirect-from/redirector.rb +0 -91
- data/spec/fixtures/_config.yml +0 -7
- data/spec/fixtures/one_redirect_url.md +0 -6
- data/spec/jekyll_redirect_from/redirector_spec.rb +0 -149
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-redirect-from
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-02 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
|
-
version: '
|
19
|
+
version: '3.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.8.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.43'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.43'
|
83
97
|
description: Seamlessly specify multiple redirection URLs for your pages and posts
|
84
98
|
email:
|
85
99
|
- parkrmoore@gmail.com
|
@@ -89,6 +103,7 @@ extra_rdoc_files: []
|
|
89
103
|
files:
|
90
104
|
- ".gitignore"
|
91
105
|
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
92
107
|
- ".travis.yml"
|
93
108
|
- Gemfile
|
94
109
|
- History.markdown
|
@@ -97,8 +112,12 @@ files:
|
|
97
112
|
- Rakefile
|
98
113
|
- jekyll-redirect-from.gemspec
|
99
114
|
- lib/jekyll-redirect-from.rb
|
115
|
+
- lib/jekyll-redirect-from/context.rb
|
116
|
+
- lib/jekyll-redirect-from/generator.rb
|
117
|
+
- lib/jekyll-redirect-from/layout.rb
|
118
|
+
- lib/jekyll-redirect-from/redirect.html
|
100
119
|
- lib/jekyll-redirect-from/redirect_page.rb
|
101
|
-
- lib/jekyll-redirect-from/
|
120
|
+
- lib/jekyll-redirect-from/redirectable.rb
|
102
121
|
- lib/jekyll-redirect-from/version.rb
|
103
122
|
- script/bootstrap
|
104
123
|
- script/cibuild
|
@@ -108,17 +127,20 @@ files:
|
|
108
127
|
- spec/fixtures/_articles/redirect-somewhere-else-im-a-permalink.html
|
109
128
|
- spec/fixtures/_articles/redirect-somewhere-else-plz.html
|
110
129
|
- spec/fixtures/_authors/kansaichris.md
|
111
|
-
- spec/fixtures/_config.yml
|
112
130
|
- spec/fixtures/_layouts/layout.html
|
113
131
|
- spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
|
132
|
+
- spec/fixtures/multiple_redirect_froms.md
|
114
133
|
- spec/fixtures/multiple_redirect_tos.md
|
115
|
-
- spec/fixtures/
|
116
|
-
- spec/fixtures/
|
117
|
-
- spec/fixtures/
|
134
|
+
- spec/fixtures/one_redirect_from.md
|
135
|
+
- spec/fixtures/one_redirect_to_path.md
|
136
|
+
- spec/fixtures/one_redirect_to_url.md
|
118
137
|
- spec/fixtures/tags/how we work.md
|
119
138
|
- spec/integrations_spec.rb
|
139
|
+
- spec/jekyll_redirect_from/context_spec.rb
|
140
|
+
- spec/jekyll_redirect_from/generator_spec.rb
|
141
|
+
- spec/jekyll_redirect_from/layout_spec.rb
|
120
142
|
- spec/jekyll_redirect_from/redirect_page_spec.rb
|
121
|
-
- spec/jekyll_redirect_from/
|
143
|
+
- spec/jekyll_redirect_from/redirectable_spec.rb
|
122
144
|
- spec/spec_helper.rb
|
123
145
|
homepage: https://github.com/jekyll/jekyll-redirect-from
|
124
146
|
licenses:
|
@@ -140,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
162
|
version: '0'
|
141
163
|
requirements: []
|
142
164
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
165
|
+
rubygems_version: 2.5.2
|
144
166
|
signing_key:
|
145
167
|
specification_version: 4
|
146
168
|
summary: Seamlessly specify multiple redirection URLs for your pages and posts
|
@@ -149,15 +171,18 @@ test_files:
|
|
149
171
|
- spec/fixtures/_articles/redirect-somewhere-else-im-a-permalink.html
|
150
172
|
- spec/fixtures/_articles/redirect-somewhere-else-plz.html
|
151
173
|
- spec/fixtures/_authors/kansaichris.md
|
152
|
-
- spec/fixtures/_config.yml
|
153
174
|
- spec/fixtures/_layouts/layout.html
|
154
175
|
- spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
|
176
|
+
- spec/fixtures/multiple_redirect_froms.md
|
155
177
|
- spec/fixtures/multiple_redirect_tos.md
|
156
|
-
- spec/fixtures/
|
157
|
-
- spec/fixtures/
|
158
|
-
- spec/fixtures/
|
178
|
+
- spec/fixtures/one_redirect_from.md
|
179
|
+
- spec/fixtures/one_redirect_to_path.md
|
180
|
+
- spec/fixtures/one_redirect_to_url.md
|
159
181
|
- spec/fixtures/tags/how we work.md
|
160
182
|
- spec/integrations_spec.rb
|
183
|
+
- spec/jekyll_redirect_from/context_spec.rb
|
184
|
+
- spec/jekyll_redirect_from/generator_spec.rb
|
185
|
+
- spec/jekyll_redirect_from/layout_spec.rb
|
161
186
|
- spec/jekyll_redirect_from/redirect_page_spec.rb
|
162
|
-
- spec/jekyll_redirect_from/
|
187
|
+
- spec/jekyll_redirect_from/redirectable_spec.rb
|
163
188
|
- spec/spec_helper.rb
|
@@ -1,91 +0,0 @@
|
|
1
|
-
module JekyllRedirectFrom
|
2
|
-
class Redirector < Jekyll::Generator
|
3
|
-
safe true
|
4
|
-
|
5
|
-
def generate(site)
|
6
|
-
original_pages = site.pages.dup
|
7
|
-
generate_alt_urls(site, site.posts) if Jekyll::VERSION < '3.0.0'
|
8
|
-
generate_alt_urls(site, original_pages)
|
9
|
-
generate_alt_urls(site, site.docs_to_write)
|
10
|
-
end
|
11
|
-
|
12
|
-
def generate_alt_urls(site, list)
|
13
|
-
list.each do |item|
|
14
|
-
if has_alt_urls?(item)
|
15
|
-
alt_urls(item).each do |alt_url|
|
16
|
-
redirect_page = RedirectPage.new(site, site.source, "", "redirect.html")
|
17
|
-
redirect_page.data['permalink'] = alt_url
|
18
|
-
redirect_page.data['sitemap'] = false
|
19
|
-
redirect_page.generate_redirect_content(redirect_url(site, item))
|
20
|
-
site.pages << redirect_page
|
21
|
-
end
|
22
|
-
end
|
23
|
-
if has_redirect_to_url?(item)
|
24
|
-
redirect_to_url(item).flatten.each do |alt_url|
|
25
|
-
item.data['sitemap'] = false
|
26
|
-
|
27
|
-
item.url << "index.html" if item.url.end_with?("/")
|
28
|
-
redirect_page = RedirectPage.new(site, site.source, File.dirname(item.url), File.basename(item.url))
|
29
|
-
|
30
|
-
redirect_page.data['permalink'] = item.url
|
31
|
-
redirect_page.data['sitemap'] = false
|
32
|
-
redirect_page.generate_redirect_content(alt_url)
|
33
|
-
if item.is_a?(Jekyll::Document)
|
34
|
-
item.content = item.output = redirect_page.content
|
35
|
-
else
|
36
|
-
site.pages << redirect_page
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def is_dynamic_document?(page_or_post)
|
44
|
-
page_or_post.is_a?(Jekyll::Page) ||
|
45
|
-
page_or_post.is_a?(Jekyll::Document) ||
|
46
|
-
(Jekyll::VERSION < '3.0.0' &&
|
47
|
-
page_or_post.is_a?(Jekyll::Post))
|
48
|
-
end
|
49
|
-
|
50
|
-
def has_alt_urls?(page_or_post)
|
51
|
-
is_dynamic_document?(page_or_post) &&
|
52
|
-
page_or_post.data.has_key?('redirect_from') &&
|
53
|
-
!alt_urls(page_or_post).empty?
|
54
|
-
end
|
55
|
-
|
56
|
-
def alt_urls(page_or_post)
|
57
|
-
Array[page_or_post.data['redirect_from']].flatten.compact
|
58
|
-
end
|
59
|
-
|
60
|
-
def has_redirect_to_url?(page_or_post)
|
61
|
-
is_dynamic_document?(page_or_post) &&
|
62
|
-
page_or_post.data.has_key?('redirect_to') &&
|
63
|
-
!redirect_to_url(page_or_post).empty?
|
64
|
-
end
|
65
|
-
|
66
|
-
def redirect_to_url(page_or_post)
|
67
|
-
[Array[page_or_post.data['redirect_to']].flatten.first].compact
|
68
|
-
end
|
69
|
-
|
70
|
-
def redirect_url(site, item)
|
71
|
-
File.join redirect_prefix(site), item.url
|
72
|
-
end
|
73
|
-
|
74
|
-
def redirect_prefix(site)
|
75
|
-
config_github_url(site) || config_url(site)
|
76
|
-
end
|
77
|
-
|
78
|
-
def config_github_url(site)
|
79
|
-
github_config = site.config['github']
|
80
|
-
if github_config.is_a?(Hash) && github_config['url']
|
81
|
-
github_config['url'].to_s
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def config_url(site)
|
86
|
-
url = site.config.fetch('url', nil) || ""
|
87
|
-
baseurl = site.config.fetch('baseurl', nil) || ""
|
88
|
-
File.join url, baseurl
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
data/spec/fixtures/_config.yml
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe JekyllRedirectFrom::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 JekyllRedirectFrom.jekyll_3?
|
17
|
-
skip "Don't need to test posts in Jekyll 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.jekyllrb.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.jekyllrb.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://jekyllrb.com/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
|