jekyll-redirect-from 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fa3f92815ea1139cb6a777eec89fea9088c969a
4
- data.tar.gz: c2eacde6b4baf40005a2bcdfeabdad17583c3f87
3
+ metadata.gz: 2d791a13d885f60395b4ae51369248e46e4b049b
4
+ data.tar.gz: d4bb94fb82a1dca865b49d404ec035ce037b3e65
5
5
  SHA512:
6
- metadata.gz: 1fa268f45a18a89bc730731c3bf607cb83eaba4305b5e0d661675699179f791e818092b2b5b10a568bcc8120344dc96b07d82630ae748dbcecf8cdb7d56743e5
7
- data.tar.gz: 76bf75329d712007916612d41258a977e1ef3b7e48bb3408d3de734b3fa9ee181f7a65814e47dd8ef6d140f94092c53ec0ae4d6bbb187787f47e9a20e513a0fc
6
+ metadata.gz: d918ab960428cd3d81738dddf6c8b66a68560ea686db49d29c775d0c722ea5ea3cd5d4722e1ffa67f7ad6eaf6ab802a91332a9a30a5bd3c16a316d2afd82cc39
7
+ data.tar.gz: a9c2dd79f38008c59b9fca3314bea0a4d3c1b1a51bb218e60e4837bcf75f33ba7fcc3be67dd55a6aa4e2011c9f6c9eaf6074503e4318764485a75cded95e19c0
data/History.markdown CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.11.0 / 2016-07-06
2
+
3
+ * Redirect page should not have any layout (#106)
4
+ * Include absolute path in canonical url (#109)
5
+ * Add <html> tag and language (#100)
6
+ * Ensure redirect_to links produce an HTML file. (#111)
7
+
1
8
  ## 0.10.0 / 2016-03-16
2
9
 
3
10
  * Ensure output extension is assigned (#96)
data/README.md CHANGED
@@ -117,7 +117,8 @@ redirect_to:
117
117
 
118
118
  If you have multiple `redirect_to`s set, only the first one will be respected.
119
119
 
120
- **Note**: if using `redirect_to` with collections, your collection's extension **must** end in *.html* in order for `redirect_to` to properly process.
120
+
121
+ **Note**: Using `redirect_to` or `redirect_from` with collections will only work with files which are output to HTML, such as `.md`, `.textile`, `.html` etc.
121
122
 
122
123
  ## Contributing
123
124
 
@@ -15,7 +15,7 @@ module JekyllRedirectFrom
15
15
  @name = name
16
16
 
17
17
  self.process(name)
18
- self.data = {}
18
+ self.data = { "layout" => nil }
19
19
 
20
20
  data.default_proc = proc do |_, key|
21
21
  site.frontmatter_defaults.find(File.join(dir, name), type, key)
@@ -27,6 +27,7 @@ module JekyllRedirectFrom
27
27
  def generate_redirect_content(item_url)
28
28
  self.output = self.content = <<-EOF
29
29
  <!DOCTYPE html>
30
+ <html lang="en-US">
30
31
  <meta charset="utf-8">
31
32
  <title>Redirecting…</title>
32
33
  <link rel="canonical" href="#{item_url}">
@@ -34,6 +35,7 @@ module JekyllRedirectFrom
34
35
  <h1>Redirecting…</h1>
35
36
  <a href="#{item_url}">Click here if you are not redirected.</a>
36
37
  <script>location="#{item_url}"</script>
38
+ </html>
37
39
  EOF
38
40
  end
39
41
  end
@@ -23,7 +23,10 @@ module JekyllRedirectFrom
23
23
  if has_redirect_to_url?(item)
24
24
  redirect_to_url(item).flatten.each do |alt_url|
25
25
  item.data['sitemap'] = false
26
+
27
+ item.url << "index.html" if item.url.end_with?("/")
26
28
  redirect_page = RedirectPage.new(site, site.source, File.dirname(item.url), File.basename(item.url))
29
+
27
30
  redirect_page.data['permalink'] = item.url
28
31
  redirect_page.data['sitemap'] = false
29
32
  redirect_page.generate_redirect_content(alt_url)
@@ -69,7 +72,7 @@ module JekyllRedirectFrom
69
72
  end
70
73
 
71
74
  def redirect_prefix(site)
72
- config_github_url(site) || config_baseurl(site) || ""
75
+ config_github_url(site) || config_url(site)
73
76
  end
74
77
 
75
78
  def config_github_url(site)
@@ -79,8 +82,10 @@ module JekyllRedirectFrom
79
82
  end
80
83
  end
81
84
 
82
- def config_baseurl(site)
83
- site.config.fetch('baseurl', nil)
85
+ def config_url(site)
86
+ url = site.config.fetch('url', nil) || ""
87
+ baseurl = site.config.fetch('baseurl', nil) || ""
88
+ File.join url, baseurl
84
89
  end
85
90
  end
86
91
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllRedirectFrom
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: Please redirect away from me and my permalink.
3
+ permalink: /tags/our projects/
4
+ redirect_to: /tags/our-projects/
5
+ ---
6
+
7
+ Bye.
@@ -0,0 +1,6 @@
1
+ ---
2
+ ---
3
+
4
+ LAYOUT INCLUDED
5
+
6
+ {{ content }}
@@ -0,0 +1,4 @@
1
+ ---
2
+ redirect_to: "/tags/how-we-work/"
3
+ permalink: "/tags/how we work/"
4
+ ---
@@ -10,7 +10,7 @@ describe JekyllRedirectFrom::RedirectPage do
10
10
 
11
11
  context "#generate_redirect_content" do
12
12
  it "sets the #content to the generated refresh page" do
13
- expect(page_content).to eq("<!DOCTYPE html>\n<meta charset=\"utf-8\">\n<title>Redirecting…</title>\n<link rel=\"canonical\" href=\"#{item_url}\">\n<meta http-equiv=\"refresh\" content=\"0; url=#{item_url}\">\n<h1>Redirecting…</h1>\n<a href=\"#{item_url}\">Click here if you are not redirected.</a>\n<script>location=\"#{item_url}\"</script>\n")
13
+ expect(page_content).to eq("<!DOCTYPE html>\n<html lang=\"en-US\">\n<meta charset=\"utf-8\">\n<title>Redirecting…</title>\n<link rel=\"canonical\" href=\"#{item_url}\">\n<meta http-equiv=\"refresh\" content=\"0; url=#{item_url}\">\n<h1>Redirecting…</h1>\n<a href=\"#{item_url}\">Click here if you are not redirected.</a>\n<script>location=\"#{item_url}\"</script>\n</html>\n")
14
14
  end
15
15
 
16
16
  it "contains the meta refresh tag" do
@@ -5,10 +5,12 @@ describe JekyllRedirectFrom::Redirector do
5
5
  let(:post_to_redirect) { setup_post("2014-01-03-redirect-me-plz.md") }
6
6
  let(:doc_to_redirect_from) { setup_doc("redirect-me-plz.md") }
7
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") }
8
9
  let(:page_with_one) { setup_page("one_redirect_url.md") }
9
10
  let(:page_with_many) { setup_page("multiple_redirect_urls.md") }
10
11
  let(:page_with_one_redirect_to) { setup_page("one_redirect_to.md") }
11
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") }
12
14
 
13
15
  it "knows if a page or post is requesting a redirect page" do
14
16
  if JekyllRedirectFrom.jekyll_3?
@@ -26,6 +28,10 @@ describe JekyllRedirectFrom::Redirector do
26
28
  expect(redirector.redirect_to_url(doc_to_redirect_to)).to eql(["http://www.zombo.com"])
27
29
  end
28
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
+
29
35
  it "handles one redirect path" do
30
36
  expect(redirector.alt_urls(page_with_one)).to eql(["mencius/was/my/father"])
31
37
  end
@@ -71,6 +77,12 @@ describe JekyllRedirectFrom::Redirector do
71
77
  expect(dest_dir("articles", "redirect-somewhere-else-plz.html").read).to include(%|<meta http-equiv="refresh" content="0; url=http://www.zombo.com">|)
72
78
  end
73
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
+
74
86
  it "generates the refresh page for the page with one redirect_to url" do
75
87
  expect(dest_dir("one_redirect_to.html")).to exist
76
88
  expect(dest_dir("one_redirect_to.html").read).to include(%|<meta http-equiv="refresh" content="0; url=https://www.github.com">|)
@@ -80,36 +92,57 @@ describe JekyllRedirectFrom::Redirector do
80
92
  expect(dest_dir("multiple_redirect_tos.html")).to exist
81
93
  expect(dest_dir("multiple_redirect_tos.html").read).to include(%|<meta http-equiv="refresh" content="0; url=https://www.jekyllrb.com">|)
82
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
83
106
  end
84
107
 
85
108
  context "prefix" do
86
- it "uses site.github.url as the redirect prefix" do
87
- @site.config['github'] = { "url" => "http://example.github.io/test" }
88
- expect(redirector.redirect_url(@site, page_with_one)).to start_with("http://example.github.io/test")
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")
89
113
  end
90
114
 
91
- it "converts non-string values in site.github.url to strings" do
92
- @site.config['github'] = { "url" => TestStringContainer.new("http://example.github.io/test") }
93
- expect(redirector.redirect_url(@site, page_with_one)).to start_with("http://example.github.io/test")
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")
94
119
  end
95
120
 
96
- it "uses site.baseurl as the redirect prefix when site.github.url is not set" do
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"
97
123
  @site.config['baseurl'] = "/fancy/prefix"
98
- expect(redirector.redirect_url(@site, page_with_one)).to start_with("/fancy/prefix")
124
+ expect(redirector.redirect_url(@site, page_with_one)).to eql("http://notgithub.io/fancy/prefix/one_redirect_url.html")
99
125
  end
100
126
 
101
- it "prefers site.github.url over site.baseurl" do
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"
102
130
  @site.config['github'] = { "url" => "http://example.github.io/test" }
103
- @site.config['baseurl'] = "/fancy/baseurl"
104
- expect(redirector.redirect_url(@site, page_with_one)).to start_with("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")
105
132
  end
106
133
 
107
- it "no-ops when site.github.url and site.baseurl are not set" do
108
- expect(redirector.redirect_url(@site, page_with_one)).to eql("/one_redirect_url.html")
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")
109
137
  end
110
138
 
111
- it "no-ops when site.github is set but site.github.url is not" do
139
+ it "uses site.url when site.github is set but site.github.url is not" do
112
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
113
146
  expect(redirector.redirect_url(@site, page_with_one)).to eql("/one_redirect_url.html")
114
147
  end
115
148
  end
data/spec/spec_helper.rb CHANGED
@@ -26,7 +26,11 @@ RSpec.configure do |config|
26
26
  "collections" => {
27
27
  "articles" => {"output" => true},
28
28
  "authors" => {}
29
- }
29
+ },
30
+ "defaults" => [{
31
+ "scope" => { "path" => "" },
32
+ "values" => { "layout" => "layout" }
33
+ }]
30
34
  }))
31
35
 
32
36
  @dest.rmtree if @dest.exist?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-redirect-from
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.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: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -105,14 +105,17 @@ files:
105
105
  - script/release
106
106
  - script/test
107
107
  - spec/fixtures/_articles/redirect-me-plz.md
108
+ - spec/fixtures/_articles/redirect-somewhere-else-im-a-permalink.html
108
109
  - spec/fixtures/_articles/redirect-somewhere-else-plz.html
109
110
  - spec/fixtures/_authors/kansaichris.md
110
111
  - spec/fixtures/_config.yml
112
+ - spec/fixtures/_layouts/layout.html
111
113
  - spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
112
114
  - spec/fixtures/multiple_redirect_tos.md
113
115
  - spec/fixtures/multiple_redirect_urls.md
114
116
  - spec/fixtures/one_redirect_to.md
115
117
  - spec/fixtures/one_redirect_url.md
118
+ - spec/fixtures/tags/how we work.md
116
119
  - spec/integrations_spec.rb
117
120
  - spec/jekyll_redirect_from/redirect_page_spec.rb
118
121
  - spec/jekyll_redirect_from/redirector_spec.rb
@@ -137,20 +140,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
140
  version: '0'
138
141
  requirements: []
139
142
  rubyforge_project:
140
- rubygems_version: 2.5.1
143
+ rubygems_version: 2.4.8
141
144
  signing_key:
142
145
  specification_version: 4
143
146
  summary: Seamlessly specify multiple redirection URLs for your pages and posts
144
147
  test_files:
145
148
  - spec/fixtures/_articles/redirect-me-plz.md
149
+ - spec/fixtures/_articles/redirect-somewhere-else-im-a-permalink.html
146
150
  - spec/fixtures/_articles/redirect-somewhere-else-plz.html
147
151
  - spec/fixtures/_authors/kansaichris.md
148
152
  - spec/fixtures/_config.yml
153
+ - spec/fixtures/_layouts/layout.html
149
154
  - spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
150
155
  - spec/fixtures/multiple_redirect_tos.md
151
156
  - spec/fixtures/multiple_redirect_urls.md
152
157
  - spec/fixtures/one_redirect_to.md
153
158
  - spec/fixtures/one_redirect_url.md
159
+ - spec/fixtures/tags/how we work.md
154
160
  - spec/integrations_spec.rb
155
161
  - spec/jekyll_redirect_from/redirect_page_spec.rb
156
162
  - spec/jekyll_redirect_from/redirector_spec.rb