bunto-redirect-from 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +26 -0
- data/Gemfile +8 -0
- data/History.markdown +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +128 -0
- data/Rakefile +6 -0
- data/bunto-redirect-from.gemspec +27 -0
- data/lib/bunto-redirect-from.rb +4 -0
- data/lib/bunto-redirect-from/redirect_page.rb +34 -0
- data/lib/bunto-redirect-from/redirector.rb +86 -0
- data/lib/bunto-redirect-from/version.rb +3 -0
- data/script/bootstrap +3 -0
- data/script/cibuild +4 -0
- data/script/release +3 -0
- data/spec/bunto_redirect_from/redirect_page_spec.rb +72 -0
- data/spec/bunto_redirect_from/redirector_spec.rb +116 -0
- data/spec/fixtures/_articles/redirect-me-plz.md +6 -0
- data/spec/fixtures/_articles/redirect-somewhere-else-plz.html +6 -0
- data/spec/fixtures/_authors/kansaichris.md +5 -0
- data/spec/fixtures/_config.yml +7 -0
- data/spec/fixtures/_posts/2014-01-03-redirect-me-plz.md +6 -0
- data/spec/fixtures/multiple_redirect_tos.md +9 -0
- data/spec/fixtures/multiple_redirect_urls.md +10 -0
- data/spec/fixtures/one_redirect_to.md +6 -0
- data/spec/fixtures/one_redirect_url.md +6 -0
- data/spec/integrations_spec.rb +13 -0
- data/spec/spec_helper.rb +91 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bd17bdc8cbdfe1f44c7c04ed58155a421ff32042
|
4
|
+
data.tar.gz: 20d2d702d13bf8cb1d0cab45f1f288cc720bc87d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 09fa9f01c2f0c1606de73b27f067bf4cd2700130b162b8dcdc588be9dc3e08834ce4c32c115cfd7e370e228cdd5aeb8348ce0158a6c2b92e2738bfbe0d9659c3
|
7
|
+
data.tar.gz: eb8605dc9b36aecc48181136af0b0c47ef46b0298c1261c6fc464dbdbaf7928ceea77d6d843e34e74596ca0966fef4b0b23576df1c9813753749f282fe1536c1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
language: ruby
|
2
|
+
before_script: bundle update
|
3
|
+
script: "script/cibuild"
|
4
|
+
sudo: false
|
5
|
+
cache: bundler
|
6
|
+
|
7
|
+
matrix:
|
8
|
+
include:
|
9
|
+
- # GitHub Pages
|
10
|
+
rvm: 2.1.1
|
11
|
+
env: GH_PAGES=true
|
12
|
+
- # Ruby 1.9
|
13
|
+
rvm: 1.9
|
14
|
+
env: BUNTO_VERSION=1.0
|
15
|
+
allow_failures:
|
16
|
+
- env: GH_PAGES=true
|
17
|
+
fast_finish: true
|
18
|
+
|
19
|
+
rvm:
|
20
|
+
- 2.2
|
21
|
+
- 2.1
|
22
|
+
- 2.0
|
23
|
+
env:
|
24
|
+
- ""
|
25
|
+
- BUNTO_VERSION=2.0
|
26
|
+
- BUNTO_VERSION=1.0
|
data/Gemfile
ADDED
data/History.markdown
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016-present Parker Moore
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# BuntoRedirectFrom
|
2
|
+
|
3
|
+
Give your Bunto posts and pages multiple URLs.
|
4
|
+
|
5
|
+
When importing your posts and pages from, say, Tumblr, it's annoying and
|
6
|
+
impractical to create new pages in the proper subdirectories so they, e.g.
|
7
|
+
`/post/123456789/my-slug-that-is-often-incompl`, redirect to the new post URL.
|
8
|
+
|
9
|
+
Instead of dealing with maintaining those pages for redirection, let
|
10
|
+
`bunto-redirect-from` handle it for you.
|
11
|
+
|
12
|
+
[](https://travis-ci.org/bunto/bunto-redirect-from)
|
13
|
+
|
14
|
+
## How it Works
|
15
|
+
|
16
|
+
Redirects are performed by serving an HTML file with an HTTP-REFRESH meta
|
17
|
+
tag which points to your destination. No `.htaccess` file, nginx conf, xml
|
18
|
+
file, or anything else will be generated. It simply creates HTML files.
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
gem 'bunto-redirect-from'
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install bunto-redirect-from
|
33
|
+
|
34
|
+
Once it's installed into your evironment, add it to your `_config.yml`:
|
35
|
+
|
36
|
+
```yaml
|
37
|
+
gems:
|
38
|
+
- bunto-redirect-from
|
39
|
+
```
|
40
|
+
|
41
|
+
If you're using Bunto in `safe` mode to mimic GitHub Pages, make sure to
|
42
|
+
add bunto-redirect-from to your whitelist:
|
43
|
+
|
44
|
+
```yaml
|
45
|
+
whitelist:
|
46
|
+
- bunto-redirect-from
|
47
|
+
```
|
48
|
+
|
49
|
+
Then run `bunto <cmd> --safe` like normal.
|
50
|
+
|
51
|
+
## Usage
|
52
|
+
|
53
|
+
The object of this gem is to allow an author to specify multiple URLs for a
|
54
|
+
page, such that the alternative URLs redirect to the new Bunto URL.
|
55
|
+
|
56
|
+
To use it, simply add the array to the YAML front-matter of your page or post:
|
57
|
+
|
58
|
+
```yaml
|
59
|
+
title: My amazing post
|
60
|
+
redirect_from:
|
61
|
+
- /post/123456789/
|
62
|
+
- /post/123456789/my-amazing-post/
|
63
|
+
```
|
64
|
+
|
65
|
+
Redirects including a trailing slash will generate a corresponding subdirectory containing an `index.html`, while redirects without a trailing slash will generate a corresponding `filename` without an extension, and without a subdirectory.
|
66
|
+
|
67
|
+
For example...
|
68
|
+
|
69
|
+
```text
|
70
|
+
redirect_from:
|
71
|
+
- /post/123456789/my-amazing-post
|
72
|
+
```
|
73
|
+
|
74
|
+
...will generate the following page in the destination:
|
75
|
+
|
76
|
+
```text
|
77
|
+
/post/123456789/my-amazing-post
|
78
|
+
```
|
79
|
+
|
80
|
+
While...
|
81
|
+
|
82
|
+
```text
|
83
|
+
redirect_from:
|
84
|
+
- /post/123456789/my-amazing-post/
|
85
|
+
```
|
86
|
+
|
87
|
+
...will generate the following page in the destination:
|
88
|
+
|
89
|
+
```text
|
90
|
+
/post/123456789/my-amazing-post/index.html
|
91
|
+
```
|
92
|
+
|
93
|
+
These pages will contain an HTTP-REFRESH meta tag which redirect to your URL.
|
94
|
+
|
95
|
+
You can also specify just **one url** like this:
|
96
|
+
|
97
|
+
```text
|
98
|
+
title: My other awesome post
|
99
|
+
redirect_from: /post/123456798/
|
100
|
+
```
|
101
|
+
|
102
|
+
### Prefix
|
103
|
+
If `site.baseurl` is set, its value is used as a prefix for the redirect url automatically.
|
104
|
+
This is useful for scenarios where a site isn't available from the domain root, so the redirects point to the correct path.
|
105
|
+
|
106
|
+
**_Note_**: If you are hosting your Bunto 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`.
|
107
|
+
|
108
|
+
### Redirect To
|
109
|
+
|
110
|
+
Sometimes, you may want to redirect a site page to a totally different website. This plugin also supports that with the `redirect_to` key:
|
111
|
+
|
112
|
+
```yaml
|
113
|
+
title: My amazing post
|
114
|
+
redirect_to:
|
115
|
+
- http://www.github.com
|
116
|
+
```
|
117
|
+
|
118
|
+
If you have multiple `redirect_to`s set, only the first one will be respected.
|
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.
|
121
|
+
|
122
|
+
## Contributing
|
123
|
+
|
124
|
+
1. Fork it
|
125
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
126
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
127
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
128
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bunto-redirect-from/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bunto-redirect-from"
|
8
|
+
spec.version = BuntoRedirectFrom::VERSION
|
9
|
+
spec.authors = ["Parker Moore", "Suriyaa Kudo"]
|
10
|
+
spec.email = ["parkrmoore@gmail.com", "SuriyaaKudoIsc@users.noreply.github.com"]
|
11
|
+
spec.description = %q{Seamlessly specify multiple redirection URLs for your pages and posts}
|
12
|
+
spec.summary = %q{Seamlessly specify multiple redirection URLs for your pages and posts}
|
13
|
+
spec.homepage = "https://github.com/bunto/bunto-redirect-from"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "bunto"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "bunto-sitemap", "~> 0.8.1"
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Encoding: utf-8
|
2
|
+
|
3
|
+
module BuntoRedirectFrom
|
4
|
+
class RedirectPage < Bunto::Page
|
5
|
+
# Initialize a new RedirectPage.
|
6
|
+
#
|
7
|
+
# site - The Site object.
|
8
|
+
# base - The String path to the source.
|
9
|
+
# dir - The String path between the source and the file.
|
10
|
+
# name - The String filename of the file.
|
11
|
+
def initialize(site, base, dir, name)
|
12
|
+
@site = site
|
13
|
+
@base = base
|
14
|
+
@dir = dir
|
15
|
+
@name = name
|
16
|
+
|
17
|
+
self.process(name)
|
18
|
+
self.data = {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_redirect_content(item_url)
|
22
|
+
self.output = self.content = <<-EOF
|
23
|
+
<!DOCTYPE html>
|
24
|
+
<meta charset="utf-8">
|
25
|
+
<title>Redirecting…</title>
|
26
|
+
<link rel="canonical" href="#{item_url}">
|
27
|
+
<meta http-equiv="refresh" content="0; url=#{item_url}">
|
28
|
+
<h1>Redirecting…</h1>
|
29
|
+
<a href="#{item_url}">Click here if you are not redirected.</a>
|
30
|
+
<script>location="#{item_url}"</script>
|
31
|
+
EOF
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module BuntoRedirectFrom
|
2
|
+
class Redirector < Bunto::Generator
|
3
|
+
safe true
|
4
|
+
|
5
|
+
def generate(site)
|
6
|
+
original_pages = site.pages.dup
|
7
|
+
generate_alt_urls(site, site.posts) if Bunto::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, "", "")
|
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
|
+
redirect_page = RedirectPage.new(site, site.source, File.dirname(item.url), File.basename(item.url))
|
27
|
+
redirect_page.data['permalink'] = item.url
|
28
|
+
redirect_page.data['sitemap'] = false
|
29
|
+
redirect_page.generate_redirect_content(alt_url)
|
30
|
+
if item.is_a?(Bunto::Document)
|
31
|
+
item.content = item.output = redirect_page.content
|
32
|
+
else
|
33
|
+
site.pages << redirect_page
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_dynamic_document?(page_or_post)
|
41
|
+
page_or_post.is_a?(Bunto::Page) ||
|
42
|
+
page_or_post.is_a?(Bunto::Document) ||
|
43
|
+
(Bunto::VERSION < '3.0.0' &&
|
44
|
+
page_or_post.is_a?(Bunto::Post))
|
45
|
+
end
|
46
|
+
|
47
|
+
def has_alt_urls?(page_or_post)
|
48
|
+
is_dynamic_document?(page_or_post) &&
|
49
|
+
page_or_post.data.has_key?('redirect_from') &&
|
50
|
+
!alt_urls(page_or_post).empty?
|
51
|
+
end
|
52
|
+
|
53
|
+
def alt_urls(page_or_post)
|
54
|
+
Array[page_or_post.data['redirect_from']].flatten.compact
|
55
|
+
end
|
56
|
+
|
57
|
+
def has_redirect_to_url?(page_or_post)
|
58
|
+
is_dynamic_document?(page_or_post) &&
|
59
|
+
page_or_post.data.has_key?('redirect_to') &&
|
60
|
+
!redirect_to_url(page_or_post).empty?
|
61
|
+
end
|
62
|
+
|
63
|
+
def redirect_to_url(page_or_post)
|
64
|
+
[Array[page_or_post.data['redirect_to']].flatten.first].compact
|
65
|
+
end
|
66
|
+
|
67
|
+
def redirect_url(site, item)
|
68
|
+
File.join redirect_prefix(site), item.url
|
69
|
+
end
|
70
|
+
|
71
|
+
def redirect_prefix(site)
|
72
|
+
config_github_url(site) || config_baseurl(site) || ""
|
73
|
+
end
|
74
|
+
|
75
|
+
def config_github_url(site)
|
76
|
+
github_config = site.config['github']
|
77
|
+
if github_config.is_a?(Hash) && github_config['url']
|
78
|
+
github_config['url'].to_s
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def config_baseurl(site)
|
83
|
+
site.config.fetch('baseurl', nil)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/script/bootstrap
ADDED
data/script/cibuild
ADDED
data/script/release
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe BuntoRedirectFrom::RedirectPage do
|
6
|
+
let(:permalink) { "/posts/12435151125/larry-had-a-little-lamb" }
|
7
|
+
let(:redirect_page) { new_redirect_page(permalink) }
|
8
|
+
let(:item_url) { File.join(@site.config["url"], "2014", "01", "03", "moving-to-bunto.md") }
|
9
|
+
let(:page_content) { redirect_page.generate_redirect_content(item_url) }
|
10
|
+
|
11
|
+
context "#generate_redirect_content" do
|
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")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "contains the meta refresh tag" do
|
17
|
+
expect(page_content).to include("<meta http-equiv=\"refresh\" content=\"0; url=#{item_url}\">")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "contains JavaScript redirect" do
|
21
|
+
expect(page_content).to include("location=\"http://bunto.isc/2014/01/03/moving-to-bunto.md\"")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "contains canonical link in header" do
|
25
|
+
expect(page_content).to include("<link rel=\"canonical\" href=\"http://bunto.isc/2014/01/03/moving-to-bunto.md\">")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "contains a clickable link to redirect" do
|
29
|
+
expect(page_content).to include("<a href=\"http://bunto.isc/2014/01/03/moving-to-bunto.md\">Click here if you are not redirected.</a>")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when determining the write destination" do
|
34
|
+
context "of a redirect page meant to be a dir" do
|
35
|
+
let(:permalink_dir) { "/posts/1914798137981389/larry-had-a-little-lamb/" }
|
36
|
+
let(:redirect_page) { new_redirect_page(permalink_dir) }
|
37
|
+
|
38
|
+
it "knows to add the index.html if it's a folder" do
|
39
|
+
dest = dest_dir("/posts/1914798137981389/larry-had-a-little-lamb/index.html")
|
40
|
+
expect(redirect_page.destination("/")).to eql(dest)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "of a redirect page meant to be a file" do
|
45
|
+
it "knows not to add the index.html if it's not a folder" do
|
46
|
+
dest = dest_dir("/posts/12435151125/larry-had-a-little-lamb")
|
47
|
+
expect(redirect_page.destination("/")).to eql(dest)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when writing to disk" do
|
53
|
+
let(:redirect_page_full_path) { redirect_page.destination(@site.dest) }
|
54
|
+
|
55
|
+
before(:each) do
|
56
|
+
redirect_page.generate_redirect_content(item_url)
|
57
|
+
redirect_page.write(@site.dest)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "fetches the path properly" do
|
61
|
+
expect(redirect_page_full_path).to match /\/spec\/fixtures\/\_site\/posts\/12435151125\/larry-had-a-little-lamb$/
|
62
|
+
end
|
63
|
+
|
64
|
+
it "is written to the proper location" do
|
65
|
+
expect(File.exist?(redirect_page_full_path)).to be_truthy
|
66
|
+
end
|
67
|
+
|
68
|
+
it "writes the context we expect" do
|
69
|
+
expect(File.read(redirect_page_full_path)).to eql(page_content)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BuntoRedirectFrom::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(:page_with_one) { setup_page("one_redirect_url.md") }
|
9
|
+
let(:page_with_many) { setup_page("multiple_redirect_urls.md") }
|
10
|
+
let(:page_with_one_redirect_to) { setup_page("one_redirect_to.md") }
|
11
|
+
let(:page_with_many_redirect_to) { setup_page("multiple_redirect_tos.md") }
|
12
|
+
|
13
|
+
it "knows if a page or post is requesting a redirect page" do
|
14
|
+
if Bunto::VERSION < '3.0.0'
|
15
|
+
expect(redirector.has_alt_urls?(post_to_redirect)).to be_truthy
|
16
|
+
else
|
17
|
+
skip "Don't need to test posts in Bunto 3"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "knows if a document is requesting a redirect page" do
|
22
|
+
expect(redirector.has_alt_urls?(doc_to_redirect_from)).to be_truthy
|
23
|
+
end
|
24
|
+
|
25
|
+
it "knows if a document is requesting a redirect away" do
|
26
|
+
expect(redirector.redirect_to_url(doc_to_redirect_to)).to eql(["http://www.zombo.com"])
|
27
|
+
end
|
28
|
+
|
29
|
+
it "handles one redirect path" do
|
30
|
+
expect(redirector.alt_urls(page_with_one)).to eql(["mencius/was/my/father"])
|
31
|
+
end
|
32
|
+
|
33
|
+
it "handles many redirect paths" do
|
34
|
+
expect(redirector.alt_urls(page_with_many)).to eql(["help", "contact", "let-there/be/light-he-said", "/geepers/mccreepin"])
|
35
|
+
end
|
36
|
+
|
37
|
+
it "handles a single redirect_to url" do
|
38
|
+
expect(redirector.redirect_to_url(page_with_one_redirect_to)).to eql(["https://www.github.com"])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "handles a many redirect_to urls" do
|
42
|
+
expect(redirector.redirect_to_url(page_with_many_redirect_to)).to eql(["https://www.bunto.isc"])
|
43
|
+
end
|
44
|
+
|
45
|
+
it "does not include pages with a redirect in sitemap" do
|
46
|
+
expect(destination_sitemap).not_to include(%|one_redirect_to.html|)
|
47
|
+
end
|
48
|
+
|
49
|
+
context "refresh page generation" do
|
50
|
+
before(:each) do
|
51
|
+
described_class.new.generate(@site)
|
52
|
+
end
|
53
|
+
|
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
|
56
|
+
end
|
57
|
+
|
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
|
63
|
+
end
|
64
|
+
|
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
|
67
|
+
end
|
68
|
+
|
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">|)
|
72
|
+
end
|
73
|
+
|
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">|)
|
77
|
+
end
|
78
|
+
|
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.bunto.isc">|)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
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")
|
89
|
+
end
|
90
|
+
|
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")
|
94
|
+
end
|
95
|
+
|
96
|
+
it "uses site.baseurl as the redirect prefix when site.github.url is not set" do
|
97
|
+
@site.config['baseurl'] = "/fancy/prefix"
|
98
|
+
expect(redirector.redirect_url(@site, page_with_one)).to start_with("/fancy/prefix")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "prefers site.github.url over site.baseurl" do
|
102
|
+
@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")
|
105
|
+
end
|
106
|
+
|
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")
|
109
|
+
end
|
110
|
+
|
111
|
+
it "no-ops when site.github is set but site.github.url is not" do
|
112
|
+
@site.config['github'] = "username"
|
113
|
+
expect(redirector.redirect_url(@site, page_with_one)).to eql("/one_redirect_url.html")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe("Integration Tests") do
|
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
|
7
|
+
end
|
8
|
+
|
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
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require "bunto"
|
2
|
+
require File.expand_path("lib/bunto-redirect-from.rb")
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.run_all_when_everything_filtered = true
|
6
|
+
config.filter_run :focus
|
7
|
+
config.order = 'random'
|
8
|
+
|
9
|
+
config.expect_with :rspec do |c|
|
10
|
+
c.syntax = :expect
|
11
|
+
end
|
12
|
+
|
13
|
+
config.before(:each) do
|
14
|
+
Bunto.logger.log_level = :error
|
15
|
+
|
16
|
+
@fixtures_path = Pathname.new(__FILE__).parent.join("fixtures")
|
17
|
+
@dest = @fixtures_path.join("_site")
|
18
|
+
@posts_src = @fixtures_path.join("_posts")
|
19
|
+
@layouts_src = @fixtures_path.join("_layouts")
|
20
|
+
@plugins_src = @fixtures_path.join("_plugins")
|
21
|
+
|
22
|
+
@site = Bunto::Site.new(Bunto.configuration({
|
23
|
+
"source" => @fixtures_path.to_s,
|
24
|
+
"destination" => @dest.to_s,
|
25
|
+
"plugins" => @plugins_src.to_s,
|
26
|
+
"collections" => {
|
27
|
+
"articles" => {"output" => true},
|
28
|
+
"authors" => {}
|
29
|
+
}
|
30
|
+
}))
|
31
|
+
|
32
|
+
@dest.rmtree if @dest.exist?
|
33
|
+
@site.process
|
34
|
+
end
|
35
|
+
|
36
|
+
config.after(:each) do
|
37
|
+
@dest.rmtree if @dest.exist?
|
38
|
+
end
|
39
|
+
|
40
|
+
def dest_dir(*paths)
|
41
|
+
File.join(@dest.to_s, *paths)
|
42
|
+
end
|
43
|
+
|
44
|
+
def unpublished_doc
|
45
|
+
@site.collections["authors"].docs.first
|
46
|
+
end
|
47
|
+
|
48
|
+
def setup_doc(doc_filename)
|
49
|
+
@site.collections["articles"].docs.find { |d| d.relative_path.match(doc_filename) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def setup_post(file)
|
53
|
+
Bunto::Post.new(@site, @fixtures_path.to_s, '', file)
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup_page(file)
|
57
|
+
Bunto::Page.new(@site, @fixtures_path.to_s, File.dirname(file), File.basename(file))
|
58
|
+
end
|
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
|
+
def new_redirect_page(permalink)
|
73
|
+
page = BuntoRedirectFrom::RedirectPage.new(@site, @site.source, "", "")
|
74
|
+
page.data['permalink'] = permalink
|
75
|
+
page
|
76
|
+
end
|
77
|
+
|
78
|
+
def destination_sitemap
|
79
|
+
File.read(File.join(@dest.to_s, 'sitemap.xml'))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class TestStringContainer
|
84
|
+
def initialize(strValue)
|
85
|
+
@val = strValue
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_s
|
89
|
+
@val
|
90
|
+
end
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bunto-redirect-from
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Parker Moore
|
8
|
+
- Suriyaa Kudo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-02-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bunto
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.3'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.3'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bunto-sitemap
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.8.1
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.8.1
|
84
|
+
description: Seamlessly specify multiple redirection URLs for your pages and posts
|
85
|
+
email:
|
86
|
+
- parkrmoore@gmail.com
|
87
|
+
- SuriyaaKudoIsc@users.noreply.github.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- History.markdown
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bunto-redirect-from.gemspec
|
101
|
+
- lib/bunto-redirect-from.rb
|
102
|
+
- lib/bunto-redirect-from/redirect_page.rb
|
103
|
+
- lib/bunto-redirect-from/redirector.rb
|
104
|
+
- lib/bunto-redirect-from/version.rb
|
105
|
+
- script/bootstrap
|
106
|
+
- script/cibuild
|
107
|
+
- script/release
|
108
|
+
- spec/bunto_redirect_from/redirect_page_spec.rb
|
109
|
+
- spec/bunto_redirect_from/redirector_spec.rb
|
110
|
+
- spec/fixtures/_articles/redirect-me-plz.md
|
111
|
+
- spec/fixtures/_articles/redirect-somewhere-else-plz.html
|
112
|
+
- spec/fixtures/_authors/kansaichris.md
|
113
|
+
- spec/fixtures/_config.yml
|
114
|
+
- spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
|
115
|
+
- spec/fixtures/multiple_redirect_tos.md
|
116
|
+
- spec/fixtures/multiple_redirect_urls.md
|
117
|
+
- spec/fixtures/one_redirect_to.md
|
118
|
+
- spec/fixtures/one_redirect_url.md
|
119
|
+
- spec/integrations_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
homepage: https://github.com/bunto/bunto-redirect-from
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.2.2
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Seamlessly specify multiple redirection URLs for your pages and posts
|
145
|
+
test_files:
|
146
|
+
- spec/bunto_redirect_from/redirect_page_spec.rb
|
147
|
+
- spec/bunto_redirect_from/redirector_spec.rb
|
148
|
+
- spec/fixtures/_articles/redirect-me-plz.md
|
149
|
+
- spec/fixtures/_articles/redirect-somewhere-else-plz.html
|
150
|
+
- spec/fixtures/_authors/kansaichris.md
|
151
|
+
- spec/fixtures/_config.yml
|
152
|
+
- spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
|
153
|
+
- spec/fixtures/multiple_redirect_tos.md
|
154
|
+
- spec/fixtures/multiple_redirect_urls.md
|
155
|
+
- spec/fixtures/one_redirect_to.md
|
156
|
+
- spec/fixtures/one_redirect_url.md
|
157
|
+
- spec/integrations_spec.rb
|
158
|
+
- spec/spec_helper.rb
|