jekyll-redirect-from 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.markdown +4 -0
- data/README.md +14 -0
- data/lib/jekyll-redirect-from/redirector.rb +5 -1
- data/lib/jekyll-redirect-from/version.rb +1 -1
- data/spec/fixtures/_articles/redirect-somewhere-else-plz.html +6 -0
- data/spec/jekyll_redirect_from/redirector_spec.rb +13 -3
- data/spec/spec_helper.rb +6 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47035373089df8e9b0a6f22de4b389a6d11947c6
|
4
|
+
data.tar.gz: c93eed49a5d32f3cd5831460909f905d13d24799
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f0c2d2340649cc9de1ad797ce127dcba66d5720a3e3f9f8af30f1bf5c85b6f364637129c9f862e72af0843b79699f307f6fc73d3f732b81044ee96a5066c4f4
|
7
|
+
data.tar.gz: 34b91e287cd20a980c737470d3e80921a0f305865e963a55ca455d27c8cb64637dd4e03fea5cdc4ebaf750d88c49c42309819db2788a9ebbd66a6523984390cf
|
data/History.markdown
CHANGED
data/README.md
CHANGED
@@ -89,6 +89,20 @@ This is useful for scenarios where a site isn't available from the domain root,
|
|
89
89
|
|
90
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
91
|
|
92
|
+
### Redirect To
|
93
|
+
|
94
|
+
Sometimes, you may want to redirect a site page to a totally different website. This plugin also supports that with the `redirect_to` key:
|
95
|
+
|
96
|
+
```yaml
|
97
|
+
title: My amazing post
|
98
|
+
redirect_to:
|
99
|
+
- www.github.com
|
100
|
+
```
|
101
|
+
|
102
|
+
If you have multiple `redirect_to`s set, only the first one will be respected.
|
103
|
+
|
104
|
+
**Note**: if using `redirect_to` with collections, your collection's extension ***must** end in *.html* in order for `redirect_to` to properly process.
|
105
|
+
|
92
106
|
## Contributing
|
93
107
|
|
94
108
|
1. Fork it
|
@@ -24,7 +24,11 @@ module JekyllRedirectFrom
|
|
24
24
|
redirect_page = RedirectPage.new(site, site.source, File.dirname(item.url), File.basename(item.url))
|
25
25
|
redirect_page.data['permalink'] = item.url
|
26
26
|
redirect_page.generate_redirect_content(alt_url)
|
27
|
-
|
27
|
+
if item.is_a?(Jekyll::Document)
|
28
|
+
item.content = item.output = redirect_page.content
|
29
|
+
else
|
30
|
+
site.pages << redirect_page
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
@@ -3,7 +3,8 @@ require "spec_helper"
|
|
3
3
|
describe JekyllRedirectFrom::Redirector do
|
4
4
|
let(:redirector) { described_class.new }
|
5
5
|
let(:post_to_redirect) { setup_post("2014-01-03-redirect-me-plz.md") }
|
6
|
-
let(:
|
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") }
|
7
8
|
let(:page_with_one) { setup_page("one_redirect_url.md") }
|
8
9
|
let(:page_with_many) { setup_page("multiple_redirect_urls.md") }
|
9
10
|
let(:page_with_one_redirect_to) { setup_page("one_redirect_to.md") }
|
@@ -14,7 +15,11 @@ describe JekyllRedirectFrom::Redirector do
|
|
14
15
|
end
|
15
16
|
|
16
17
|
it "knows if a document is requesting a redirect page" do
|
17
|
-
expect(redirector.has_alt_urls?(
|
18
|
+
expect(redirector.has_alt_urls?(doc_to_redirect_from)).to be_truthy
|
19
|
+
end
|
20
|
+
|
21
|
+
it "knows if a document is requesting a redirect away" do
|
22
|
+
expect(redirector.redirect_to_url(doc_to_redirect_to)).to eql(["http://www.zombo.com"])
|
18
23
|
end
|
19
24
|
|
20
25
|
it "handles one redirect path" do
|
@@ -53,6 +58,11 @@ describe JekyllRedirectFrom::Redirector do
|
|
53
58
|
expect(destination_file_exists?("mencius/was/my/father")).to be_truthy
|
54
59
|
end
|
55
60
|
|
61
|
+
it "generates the refresh page for the collection with one redirect_to url" do
|
62
|
+
expect(@dest.join("articles", "redirect-somewhere-else-plz.html")).to exist
|
63
|
+
expect(destination_doc_contents("articles", "redirect-somewhere-else-plz.html")).to include(%|<meta http-equiv=refresh content="0; url=http://www.zombo.com">|)
|
64
|
+
end
|
65
|
+
|
56
66
|
it "generates the refresh page for the page with one redirect_to url" do
|
57
67
|
expect(destination_file_exists?("one_redirect_to.html")).to be_truthy
|
58
68
|
expect(destination_file_contents("one_redirect_to.html")).to include(%|<meta http-equiv=refresh content="0; url=https://www.github.com">|)
|
@@ -80,7 +90,7 @@ describe JekyllRedirectFrom::Redirector do
|
|
80
90
|
@site.config['baseurl'] = "/fancy/baseurl"
|
81
91
|
expect(redirector.redirect_url(@site, page_with_one)).to start_with("http://example.github.io/test")
|
82
92
|
end
|
83
|
-
|
93
|
+
|
84
94
|
it "no-ops when site.github.url and site.baseurl are not set" do
|
85
95
|
expect(redirector.redirect_url(@site, page_with_one)).to eql("/one_redirect_url.html")
|
86
96
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -41,8 +41,8 @@ RSpec.configure do |config|
|
|
41
41
|
@site.collections["authors"].docs.first
|
42
42
|
end
|
43
43
|
|
44
|
-
def setup_doc
|
45
|
-
@site.collections["articles"].docs.
|
44
|
+
def setup_doc(doc_filename)
|
45
|
+
@site.collections["articles"].docs.find { |d| d.relative_path.match(doc_filename) }
|
46
46
|
end
|
47
47
|
|
48
48
|
def setup_post(file)
|
@@ -61,6 +61,10 @@ RSpec.configure do |config|
|
|
61
61
|
File.read(File.join(@dest.to_s, file))
|
62
62
|
end
|
63
63
|
|
64
|
+
def destination_doc_contents(collection, file)
|
65
|
+
File.read(File.join(@dest.to_s, collection, file))
|
66
|
+
end
|
67
|
+
|
64
68
|
def new_redirect_page(permalink)
|
65
69
|
page = JekyllRedirectFrom::RedirectPage.new(@site, @site.source, "", "")
|
66
70
|
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.6.
|
4
|
+
version: 0.6.2
|
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-09-
|
11
|
+
date: 2014-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- script/cibuild
|
91
91
|
- script/release
|
92
92
|
- spec/fixtures/_articles/redirect-me-plz.md
|
93
|
+
- spec/fixtures/_articles/redirect-somewhere-else-plz.html
|
93
94
|
- spec/fixtures/_authors/kansaichris.md
|
94
95
|
- spec/fixtures/_config.yml
|
95
96
|
- spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
|
@@ -127,6 +128,7 @@ specification_version: 4
|
|
127
128
|
summary: Seamlessly specify multiple redirection URLs for your pages and posts
|
128
129
|
test_files:
|
129
130
|
- spec/fixtures/_articles/redirect-me-plz.md
|
131
|
+
- spec/fixtures/_articles/redirect-somewhere-else-plz.html
|
130
132
|
- spec/fixtures/_authors/kansaichris.md
|
131
133
|
- spec/fixtures/_config.yml
|
132
134
|
- spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
|