jekyll-redirect-from 0.4.0 → 0.5.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: 112381245761df69cddfd8b8c7d67755d6037cd8
4
- data.tar.gz: fcd9362806dba6253fa56680db4142b1b401f996
3
+ metadata.gz: 00b63d3652670cb824eac206484575da47507dd7
4
+ data.tar.gz: 4b21faeb8f35a76532c4473bf9df0fe79453b97a
5
5
  SHA512:
6
- metadata.gz: 40503272424d63e5baf7df133bada0382c3cd4478c16d41671b4201a311e74537a0690259d86b30b22bd22a613c7ceda4d4fdce9dd0f38825b2b2e6d07924f38
7
- data.tar.gz: 65ed493e7b3a3e34c6c86da859f3626460ae8e4f477de5e984d27b135458e9f5c6a9df9f8a8363fb8ccc276725ad1286a6b2c1a806e3605ccf8b0fb09a2ee1c2
6
+ metadata.gz: 37a01d9e02364740b8f76373e8a3f987df5ab2c46625cd8372fd221a88194fae4be7812d4069a93784116ba735811b916e9d9b7f6301fa1f08b5adf494c1e92a
7
+ data.tar.gz: af8280d5ab1735fdfc02dc1c3480b1ea514ef10c50e332bd97110537218b6a6ade3851ba47569135f82d43b80d33c05d3115d2f6853f1118e2be94dc40f98ca5
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
4
- - 2.0.0
3
+ - 2.1
4
+ - 2.0
5
5
  - 1.9.3
6
6
  script: "script/cibuild"
data/History.markdown CHANGED
@@ -1,13 +1,20 @@
1
1
  ## HEAD
2
2
 
3
- ### Major Enhancements
3
+ ## 0.5.0 / 2014-08-10
4
4
 
5
5
  ### Minor Enhancements
6
6
 
7
+ * Support `redirect_to` property (#32)
8
+ * Automatically prefix redirects with the `baseurl` or GitHub URL. (#26)
9
+
7
10
  ### Bug Fixes
8
11
 
12
+ * Remove unnecessary `Array#flatten` (#34)
13
+
9
14
  ### Development Fixes
10
15
 
16
+ * Use `be_truthy` instead of `be_true`. (#33)
17
+
11
18
  ## 0.4.0 / 2014-05-06
12
19
 
13
20
  ### Major Enhancements
data/README.md CHANGED
@@ -83,6 +83,12 @@ title: My other awesome post
83
83
  redirect_from: /post/123456798/
84
84
  ```
85
85
 
86
+ ### Prefix
87
+ If `site.baseurl` is set, its value is used as a prefix for the redirect url automatically.
88
+ This is useful for scenarios where a site isn't available from the domain root, so the redirects point to the correct path.
89
+
90
+ **_Note_**: If you are hosting your Jekyll site on [GitHub Pages](https://pages.github.com/), the prefix is set to the pages domain name i.e. `http://example.github.io/project` or a custom `CNAME`.
91
+
86
92
  ## Contributing
87
93
 
88
94
  1. Fork it
@@ -11,10 +11,18 @@ module JekyllRedirectFrom
11
11
  def generate_alt_urls(site, list)
12
12
  list.each do |item|
13
13
  if has_alt_urls?(item)
14
- alt_urls(item).flatten.each do |alt_url|
14
+ alt_urls(item).each do |alt_url|
15
15
  redirect_page = RedirectPage.new(site, site.source, "", "")
16
16
  redirect_page.data['permalink'] = alt_url
17
- redirect_page.generate_redirect_content(item.url)
17
+ redirect_page.generate_redirect_content(redirect_url(site, item))
18
+ site.pages << redirect_page
19
+ end
20
+ end
21
+ if has_redirect_to_url?(item)
22
+ redirect_to_url(item).flatten.each do |alt_url|
23
+ redirect_page = RedirectPage.new(site, site.source, File.dirname(item.url), File.basename(item.url))
24
+ redirect_page.data['permalink'] = item.url
25
+ redirect_page.generate_redirect_content(alt_url)
18
26
  site.pages << redirect_page
19
27
  end
20
28
  end
@@ -30,5 +38,31 @@ module JekyllRedirectFrom
30
38
  def alt_urls(page_or_post)
31
39
  Array[page_or_post.data['redirect_from']].flatten
32
40
  end
41
+
42
+ def has_redirect_to_url?(page_or_post)
43
+ page_or_post.data.has_key?('redirect_to') &&
44
+ !alt_urls(page_or_post).nil? &&
45
+ !alt_urls(page_or_post).empty?
46
+ end
47
+
48
+ def redirect_to_url(page_or_post)
49
+ [Array[page_or_post.data['redirect_to']].flatten.first]
50
+ end
51
+
52
+ def redirect_url(site, item)
53
+ File.join redirect_prefix(site), item.url
54
+ end
55
+
56
+ def redirect_prefix(site)
57
+ config_github_url(site) || config_baseurl(site) || ""
58
+ end
59
+
60
+ def config_github_url(site)
61
+ site.config.fetch('github', Hash.new).fetch('url', nil)
62
+ end
63
+
64
+ def config_baseurl(site)
65
+ site.config.fetch('baseurl', nil)
66
+ end
33
67
  end
34
68
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllRedirectFrom
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,9 @@
1
+ ---
2
+ title: I have lots of redirect to urls
3
+ redirect_to:
4
+ - https://www.jekyllrb.com
5
+ - https://www.github.com
6
+ - https://www.twitter.com
7
+ ---
8
+
9
+ Lots of redirect to urls.
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: I am going somewhere else.
3
+ redirect_to: https://www.github.com
4
+ ---
5
+
6
+ Redirecting elsewhere.
@@ -58,7 +58,7 @@ describe JekyllRedirectFrom::RedirectPage do
58
58
  end
59
59
 
60
60
  it "is written to the proper location" do
61
- expect(File.exist?(redirect_page_full_path)).to be_true
61
+ expect(File.exist?(redirect_page_full_path)).to be_truthy
62
62
  end
63
63
 
64
64
  it "writes the context we expect" do
@@ -1,13 +1,15 @@
1
1
  require "spec_helper"
2
2
 
3
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(:page_with_one) { setup_page("one_redirect_url.md") }
7
- let(:page_with_many) { setup_page("multiple_redirect_urls.md") }
4
+ let(:redirector) { described_class.new }
5
+ let(:post_to_redirect) { setup_post("2014-01-03-redirect-me-plz.md") }
6
+ let(:page_with_one) { setup_page("one_redirect_url.md") }
7
+ let(:page_with_many) { setup_page("multiple_redirect_urls.md") }
8
+ let(:page_with_one_redirect_to) { setup_page("one_redirect_to.md") }
9
+ let(:page_with_many_redirect_to) { setup_page("multiple_redirect_tos.md") }
8
10
 
9
11
  it "knows if a page or post is requesting a redirect page" do
10
- expect(redirector.has_alt_urls?(post_to_redirect)).to be_true
12
+ expect(redirector.has_alt_urls?(post_to_redirect)).to be_truthy
11
13
  end
12
14
 
13
15
  it "handles one redirect path" do
@@ -18,24 +20,64 @@ describe JekyllRedirectFrom::Redirector do
18
20
  expect(redirector.alt_urls(page_with_many)).to eql(["help", "contact", "let-there/be/light-he-said", "/geepers/mccreepin"])
19
21
  end
20
22
 
23
+ it "handles a single redirect_to url" do
24
+ expect(redirector.redirect_to_url(page_with_one_redirect_to)).to eql(["https://www.github.com"])
25
+ end
26
+
27
+ it "handles a many redirect_to urls" do
28
+ expect(redirector.redirect_to_url(page_with_many_redirect_to)).to eql(["https://www.jekyllrb.com"])
29
+ end
30
+
21
31
  context "refresh page generation" do
22
- before(:all) do
32
+ before(:each) do
23
33
  described_class.new.generate(@site)
24
34
  end
25
35
 
26
36
  it "generates the refresh page for the post properly" do
27
- expect(destination_file_exists?("posts/23128432159832/mary-had-a-little-lamb")).to be_true
37
+ expect(destination_file_exists?("posts/23128432159832/mary-had-a-little-lamb")).to be_truthy
28
38
  end
29
39
 
30
40
  it "generates the refresh pages for the page with multiple redirect_from urls" do
31
- expect(destination_file_exists?("help")).to be_true
32
- expect(destination_file_exists?("contact")).to be_true
33
- expect(destination_file_exists?("let-there/be/light-he-said")).to be_true
34
- expect(destination_file_exists?("/geepers/mccreepin")).to be_true
41
+ expect(destination_file_exists?("help")).to be_truthy
42
+ expect(destination_file_exists?("contact")).to be_truthy
43
+ expect(destination_file_exists?("let-there/be/light-he-said")).to be_truthy
44
+ expect(destination_file_exists?("/geepers/mccreepin")).to be_truthy
35
45
  end
36
46
 
37
47
  it "generates the refresh page for the page with one redirect_from url" do
38
- expect(destination_file_exists?("mencius/was/my/father")).to be_true
48
+ expect(destination_file_exists?("mencius/was/my/father")).to be_truthy
49
+ end
50
+
51
+ it "generates the refresh page for the page with one redirect_to url" do
52
+ expect(destination_file_exists?("one_redirect_to.html")).to be_truthy
53
+ expect(destination_file_contents("one_redirect_to.html")).to include(%|<meta http-equiv=refresh content="0; url=https://www.github.com">|)
54
+ end
55
+
56
+ it "generates the refresh page for the page with multiple redirect_to urls" do
57
+ expect(destination_file_exists?("multiple_redirect_tos.html")).to be_truthy
58
+ expect(destination_file_contents("multiple_redirect_tos.html")).to include(%|<meta http-equiv=refresh content="0; url=https://www.jekyllrb.com">|)
59
+ end
60
+ end
61
+
62
+ context "prefix" do
63
+ it "uses site.github.url as the redirect prefix" do
64
+ @site.config['github'] = { "url" => "http://example.github.io/test" }
65
+ expect(redirector.redirect_url(@site, page_with_one)).to start_with("http://example.github.io/test")
66
+ end
67
+
68
+ it "uses site.baseurl as the redirect prefix when site.github.url is not set" do
69
+ @site.config['baseurl'] = "/fancy/prefix"
70
+ expect(redirector.redirect_url(@site, page_with_one)).to start_with("/fancy/prefix")
71
+ end
72
+
73
+ it "prefers site.github.url over site.baseurl" do
74
+ @site.config['github'] = { "url" => "http://example.github.io/test" }
75
+ @site.config['baseurl'] = "/fancy/baseurl"
76
+ expect(redirector.redirect_url(@site, page_with_one)).to start_with("http://example.github.io/test")
77
+ end
78
+
79
+ it "no-ops when site.github.url and site.baseurl are not set" do
80
+ expect(redirector.redirect_url(@site, page_with_one)).to eql("/one_redirect_url.html")
39
81
  end
40
82
  end
41
83
  end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,6 @@ require "jekyll"
2
2
  require File.expand_path("lib/jekyll-redirect-from.rb")
3
3
 
4
4
  RSpec.configure do |config|
5
- config.treat_symbols_as_metadata_keys_with_true_values = true
6
5
  config.run_all_when_everything_filtered = true
7
6
  config.filter_run :focus
8
7
  config.order = 'random'
@@ -11,7 +10,7 @@ RSpec.configure do |config|
11
10
  c.syntax = :expect
12
11
  end
13
12
 
14
- config.before(:all) do
13
+ config.before(:each) do
15
14
  Jekyll.logger.log_level = :error
16
15
 
17
16
  @fixtures_path = Pathname.new(__FILE__).parent.join("fixtures")
@@ -30,7 +29,7 @@ RSpec.configure do |config|
30
29
  @site.process
31
30
  end
32
31
 
33
- config.after(:all) do
32
+ config.after(:each) do
34
33
  @dest.rmtree if @dest.exist?
35
34
  end
36
35
 
@@ -46,6 +45,10 @@ RSpec.configure do |config|
46
45
  File.exists?(File.join(@dest.to_s, file))
47
46
  end
48
47
 
48
+ def destination_file_contents(file)
49
+ File.read(File.join(@dest.to_s, file))
50
+ end
51
+
49
52
  def new_redirect_page(permalink)
50
53
  page = JekyllRedirectFrom::RedirectPage.new(@site, @site.source, "", "")
51
54
  page.data['permalink'] = permalink
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.4.0
4
+ version: 0.5.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: 2014-05-07 00:00:00.000000000 Z
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -91,7 +91,9 @@ files:
91
91
  - script/release
92
92
  - spec/fixtures/_config.yml
93
93
  - spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
94
+ - spec/fixtures/multiple_redirect_tos.md
94
95
  - spec/fixtures/multiple_redirect_urls.md
96
+ - spec/fixtures/one_redirect_to.md
95
97
  - spec/fixtures/one_redirect_url.md
96
98
  - spec/jekyll_redirect_from/redirect_page_spec.rb
97
99
  - spec/jekyll_redirect_from/redirector_spec.rb
@@ -123,7 +125,9 @@ summary: Seamlessly specify multiple redirection URLs for your pages and posts
123
125
  test_files:
124
126
  - spec/fixtures/_config.yml
125
127
  - spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
128
+ - spec/fixtures/multiple_redirect_tos.md
126
129
  - spec/fixtures/multiple_redirect_urls.md
130
+ - spec/fixtures/one_redirect_to.md
127
131
  - spec/fixtures/one_redirect_url.md
128
132
  - spec/jekyll_redirect_from/redirect_page_spec.rb
129
133
  - spec/jekyll_redirect_from/redirector_spec.rb