jekyll-redirect-from 0.9.1 → 0.10.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: 1d02e44aaf2c3a2c7fb503ad76226e05910dd092
4
- data.tar.gz: 0520c094f2ada7609791410bc9dbe0c80cdff345
3
+ metadata.gz: 9fa3f92815ea1139cb6a777eec89fea9088c969a
4
+ data.tar.gz: c2eacde6b4baf40005a2bcdfeabdad17583c3f87
5
5
  SHA512:
6
- metadata.gz: fa17956617938d9c608ee4f61fabcd86142c7ac8307cbc5ad6498eb6c433395e7ca42467f6bd7b6657e7dc63f815a5595c6c2345202009fd4b4b22aa6f79ba70
7
- data.tar.gz: 01117527d4cdea7a53f59cec4addc7e046d23f5e9895e33043f7f26777e3ff3075e0f4b18e1a615f2e06b42d01849d5493b3e18a9a420151c2f1716e36806765
6
+ metadata.gz: 1fa268f45a18a89bc730731c3bf607cb83eaba4305b5e0d661675699179f791e818092b2b5b10a568bcc8120344dc96b07d82630ae748dbcecf8cdb7d56743e5
7
+ data.tar.gz: 76bf75329d712007916612d41258a977e1ef3b7e48bb3408d3de734b3fa9ee181f7a65814e47dd8ef6d140f94092c53ec0ae4d6bbb187787f47e9a20e513a0fc
data/History.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.10.0 / 2016-03-16
2
+
3
+ * Ensure output extension is assigned (#96)
4
+
1
5
  ## 0.9.1 / 2015-12-11
2
6
 
3
7
  * Enforce double-quote strings to pass htmlhint (#83)
@@ -92,4 +96,4 @@
92
96
 
93
97
  ## 0.1.0 / 2013-12-15
94
98
 
95
- * Birthday!
99
+ * Birthday!
@@ -1,4 +1,11 @@
1
1
  require "jekyll"
2
+
3
+ module JekyllRedirectFrom
4
+ def self.jekyll_3?
5
+ @jekyll_3 ||= (Jekyll::VERSION >= '3.0.0')
6
+ end
7
+ end
8
+
2
9
  require "jekyll-redirect-from/version"
3
10
  require "jekyll-redirect-from/redirect_page"
4
11
  require "jekyll-redirect-from/redirector"
@@ -1,3 +1,5 @@
1
+ # Encoding: utf-8
2
+
1
3
  module JekyllRedirectFrom
2
4
  class RedirectPage < Jekyll::Page
3
5
  # Initialize a new RedirectPage.
@@ -14,16 +16,22 @@ module JekyllRedirectFrom
14
16
 
15
17
  self.process(name)
16
18
  self.data = {}
19
+
20
+ data.default_proc = proc do |_, key|
21
+ site.frontmatter_defaults.find(File.join(dir, name), type, key)
22
+ end
23
+
24
+ Jekyll::Hooks.trigger :pages, :post_init, self if JekyllRedirectFrom.jekyll_3?
17
25
  end
18
26
 
19
27
  def generate_redirect_content(item_url)
20
28
  self.output = self.content = <<-EOF
21
29
  <!DOCTYPE html>
22
30
  <meta charset="utf-8">
23
- <title>Redirecting...</title>
31
+ <title>Redirecting…</title>
24
32
  <link rel="canonical" href="#{item_url}">
25
33
  <meta http-equiv="refresh" content="0; url=#{item_url}">
26
- <h1>Redirecting...</h1>
34
+ <h1>Redirecting…</h1>
27
35
  <a href="#{item_url}">Click here if you are not redirected.</a>
28
36
  <script>location="#{item_url}"</script>
29
37
  EOF
@@ -13,7 +13,7 @@ module JekyllRedirectFrom
13
13
  list.each do |item|
14
14
  if has_alt_urls?(item)
15
15
  alt_urls(item).each do |alt_url|
16
- redirect_page = RedirectPage.new(site, site.source, "", "")
16
+ redirect_page = RedirectPage.new(site, site.source, "", "redirect.html")
17
17
  redirect_page.data['permalink'] = alt_url
18
18
  redirect_page.data['sitemap'] = false
19
19
  redirect_page.generate_redirect_content(redirect_url(site, item))
@@ -1,3 +1,3 @@
1
1
  module JekyllRedirectFrom
2
- VERSION = "0.9.1"
2
+ VERSION = "0.10.0"
3
3
  end
data/script/test ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ bundle exec rspec $@
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe("Integration Tests") do
4
4
  it "writes the redirect pages for collection items which are outputted" do
5
- expect(@dest.join("articles", "redirect-me-plz.html")).to exist
6
- expect(@dest.join("articles", "23128432159832", "mary-had-a-little-lamb")).to exist
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
7
  end
8
8
 
9
9
  it "doesn't write redirect pages for collection items which are not outputted" do
10
- expect(@dest.join("authors")).not_to exist
11
- expect(@dest.join("kansaichris")).not_to exist
10
+ expect(dest_dir("authors")).not_to exist
11
+ expect(dest_dir("kansaichris")).not_to exist
12
12
  end
13
13
  end
@@ -1,3 +1,5 @@
1
+ # Encoding: utf-8
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe JekyllRedirectFrom::RedirectPage do
@@ -8,7 +10,7 @@ describe JekyllRedirectFrom::RedirectPage do
8
10
 
9
11
  context "#generate_redirect_content" do
10
12
  it "sets the #content to the generated refresh page" do
11
- 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<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")
12
14
  end
13
15
 
14
16
  it "contains the meta refresh tag" do
@@ -34,15 +36,19 @@ describe JekyllRedirectFrom::RedirectPage do
34
36
  let(:redirect_page) { new_redirect_page(permalink_dir) }
35
37
 
36
38
  it "knows to add the index.html if it's a folder" do
37
- dest = dest_dir("/posts/1914798137981389/larry-had-a-little-lamb/index.html")
38
- expect(redirect_page.destination("/")).to eql(dest)
39
+ expected = dest_dir("posts", "1914798137981389", "larry-had-a-little-lamb", "index.html").to_s
40
+ dest = redirect_page.destination("/")
41
+ dest = "#{@site.dest}#{dest}" unless dest.start_with? @site.dest
42
+ expect(dest).to eql(expected)
39
43
  end
40
44
  end
41
45
 
42
46
  context "of a redirect page meant to be a file" do
43
47
  it "knows not to add the index.html if it's not a folder" do
44
- dest = dest_dir("/posts/12435151125/larry-had-a-little-lamb")
45
- expect(redirect_page.destination("/")).to eql(dest)
48
+ expected = dest_dir("posts", "12435151125", "larry-had-a-little-lamb#{forced_output_ext}").to_s
49
+ dest = redirect_page.destination("/")
50
+ dest = "#{@site.dest}#{dest}" unless dest.start_with? @site.dest
51
+ expect(dest).to eql(expected)
46
52
  end
47
53
  end
48
54
  end
@@ -56,7 +62,7 @@ describe JekyllRedirectFrom::RedirectPage do
56
62
  end
57
63
 
58
64
  it "fetches the path properly" do
59
- expect(redirect_page_full_path).to match /\/spec\/fixtures\/\_site\/posts\/12435151125\/larry-had-a-little-lamb$/
65
+ expect(redirect_page_full_path).to match /\/spec\/fixtures\/\_site\/posts\/12435151125\/larry-had-a-little-lamb#{forced_output_ext}$/
60
66
  end
61
67
 
62
68
  it "is written to the proper location" do
@@ -11,10 +11,10 @@ describe JekyllRedirectFrom::Redirector do
11
11
  let(:page_with_many_redirect_to) { setup_page("multiple_redirect_tos.md") }
12
12
 
13
13
  it "knows if a page or post is requesting a redirect page" do
14
- if Jekyll::VERSION < '3.0.0'
15
- expect(redirector.has_alt_urls?(post_to_redirect)).to be_truthy
16
- else
14
+ if JekyllRedirectFrom.jekyll_3?
17
15
  skip "Don't need to test posts in Jekyll 3"
16
+ else
17
+ expect(redirector.has_alt_urls?(post_to_redirect)).to be_truthy
18
18
  end
19
19
  end
20
20
 
@@ -52,33 +52,33 @@ describe JekyllRedirectFrom::Redirector do
52
52
  end
53
53
 
54
54
  it "generates the refresh page for the post properly" do
55
- expect(destination_file_exists?("posts/23128432159832/mary-had-a-little-lamb")).to be_truthy
55
+ expect(dest_dir("posts/23128432159832/mary-had-a-little-lamb#{forced_output_ext}")).to exist
56
56
  end
57
57
 
58
58
  it "generates the refresh pages for the page with multiple redirect_from urls" do
59
- expect(destination_file_exists?("help")).to be_truthy
60
- expect(destination_file_exists?("contact")).to be_truthy
61
- expect(destination_file_exists?("let-there/be/light-he-said")).to be_truthy
62
- expect(destination_file_exists?("/geepers/mccreepin")).to be_truthy
59
+ expect(dest_dir("help")).to be_truthy
60
+ expect(dest_dir("contact")).to be_truthy
61
+ expect(dest_dir("let-there/be/light-he-said")).to be_truthy
62
+ expect(dest_dir("/geepers/mccreepin")).to be_truthy
63
63
  end
64
64
 
65
65
  it "generates the refresh page for the page with one redirect_from url" do
66
- expect(destination_file_exists?("mencius/was/my/father")).to be_truthy
66
+ expect(dest_dir("mencius/was/my/father#{forced_output_ext}")).to exist
67
67
  end
68
68
 
69
69
  it "generates the refresh page for the collection with one redirect_to url" do
70
- expect(@dest.join("articles", "redirect-somewhere-else-plz.html")).to exist
71
- expect(destination_doc_contents("articles", "redirect-somewhere-else-plz.html")).to include(%|<meta http-equiv="refresh" content="0; url=http://www.zombo.com">|)
70
+ expect(dest_dir("articles", "redirect-somewhere-else-plz.html")).to exist
71
+ expect(dest_dir("articles", "redirect-somewhere-else-plz.html").read).to include(%|<meta http-equiv="refresh" content="0; url=http://www.zombo.com">|)
72
72
  end
73
73
 
74
74
  it "generates the refresh page for the page with one redirect_to url" do
75
- expect(destination_file_exists?("one_redirect_to.html")).to be_truthy
76
- expect(destination_file_contents("one_redirect_to.html")).to include(%|<meta http-equiv="refresh" content="0; url=https://www.github.com">|)
75
+ expect(dest_dir("one_redirect_to.html")).to exist
76
+ expect(dest_dir("one_redirect_to.html").read).to include(%|<meta http-equiv="refresh" content="0; url=https://www.github.com">|)
77
77
  end
78
78
 
79
79
  it "generates the refresh page for the page with multiple redirect_to urls" do
80
- expect(destination_file_exists?("multiple_redirect_tos.html")).to be_truthy
81
- expect(destination_file_contents("multiple_redirect_tos.html")).to include(%|<meta http-equiv="refresh" content="0; url=https://www.jekyllrb.com">|)
80
+ expect(dest_dir("multiple_redirect_tos.html")).to exist
81
+ expect(dest_dir("multiple_redirect_tos.html").read).to include(%|<meta http-equiv="refresh" content="0; url=https://www.jekyllrb.com">|)
82
82
  end
83
83
  end
84
84
 
data/spec/spec_helper.rb CHANGED
@@ -38,7 +38,7 @@ RSpec.configure do |config|
38
38
  end
39
39
 
40
40
  def dest_dir(*paths)
41
- File.join(@dest.to_s, *paths)
41
+ @dest.join(*paths)
42
42
  end
43
43
 
44
44
  def unpublished_doc
@@ -57,26 +57,19 @@ RSpec.configure do |config|
57
57
  Jekyll::Page.new(@site, @fixtures_path.to_s, File.dirname(file), File.basename(file))
58
58
  end
59
59
 
60
- def destination_file_exists?(file)
61
- File.exists?(File.join(@dest.to_s, file))
62
- end
63
-
64
- def destination_file_contents(file)
65
- File.read(File.join(@dest.to_s, file))
66
- end
67
-
68
- def destination_doc_contents(collection, file)
69
- File.read(File.join(@dest.to_s, collection, file))
70
- end
71
-
72
60
  def new_redirect_page(permalink)
73
- page = JekyllRedirectFrom::RedirectPage.new(@site, @site.source, "", "")
61
+ page = JekyllRedirectFrom::RedirectPage.new(@site, @site.source, "", "index.html")
74
62
  page.data['permalink'] = permalink
63
+ page.data['sitemap'] = false
75
64
  page
76
65
  end
77
66
 
78
67
  def destination_sitemap
79
- File.read(File.join(@dest.to_s, 'sitemap.xml'))
68
+ @dest.join("sitemap.xml").read
69
+ end
70
+
71
+ def forced_output_ext
72
+ JekyllRedirectFrom.jekyll_3? ? ".html" : ""
80
73
  end
81
74
  end
82
75
 
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.9.1
4
+ version: 0.10.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: 2015-12-11 00:00:00.000000000 Z
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -103,6 +103,7 @@ files:
103
103
  - script/bootstrap
104
104
  - script/cibuild
105
105
  - script/release
106
+ - script/test
106
107
  - spec/fixtures/_articles/redirect-me-plz.md
107
108
  - spec/fixtures/_articles/redirect-somewhere-else-plz.html
108
109
  - spec/fixtures/_authors/kansaichris.md
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
137
  version: '0'
137
138
  requirements: []
138
139
  rubyforge_project:
139
- rubygems_version: 2.2.5
140
+ rubygems_version: 2.5.1
140
141
  signing_key:
141
142
  specification_version: 4
142
143
  summary: Seamlessly specify multiple redirection URLs for your pages and posts