jekyll-redirect-from 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.rubocop.yml +14 -0
- data/.travis.yml +1 -8
- data/Gemfile +0 -2
- data/History.markdown +20 -0
- data/README.md +12 -3
- data/jekyll-redirect-from.gemspec +2 -1
- data/lib/jekyll-redirect-from.rb +12 -6
- data/lib/jekyll-redirect-from/context.rb +14 -0
- data/lib/jekyll-redirect-from/generator.rb +38 -0
- data/lib/jekyll-redirect-from/layout.rb +17 -0
- data/lib/jekyll-redirect-from/redirect.html +10 -0
- data/lib/jekyll-redirect-from/redirect_page.rb +52 -33
- data/lib/jekyll-redirect-from/redirectable.rb +25 -0
- data/lib/jekyll-redirect-from/version.rb +1 -1
- data/script/cibuild +2 -0
- data/spec/fixtures/{multiple_redirect_urls.md → multiple_redirect_froms.md} +0 -0
- data/spec/fixtures/one_redirect_from.md +6 -0
- data/spec/fixtures/one_redirect_to_path.md +6 -0
- data/spec/fixtures/{one_redirect_to.md → one_redirect_to_url.md} +1 -1
- data/spec/integrations_spec.rb +81 -8
- data/spec/jekyll_redirect_from/context_spec.rb +12 -0
- data/spec/jekyll_redirect_from/generator_spec.rb +87 -0
- data/spec/jekyll_redirect_from/layout_spec.rb +32 -0
- data/spec/jekyll_redirect_from/redirect_page_spec.rb +173 -42
- data/spec/jekyll_redirect_from/redirectable_spec.rb +61 -0
- data/spec/spec_helper.rb +29 -60
- metadata +43 -18
- data/lib/jekyll-redirect-from/redirector.rb +0 -91
- data/spec/fixtures/_config.yml +0 -7
- data/spec/fixtures/one_redirect_url.md +0 -6
- data/spec/jekyll_redirect_from/redirector_spec.rb +0 -149
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e24a249a812fdc138185c2969c99551fe3381e4
|
4
|
+
data.tar.gz: cae3b55835fb5559a4ba03fd2c9a1daf1e7c3042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 495dde833d74a819dd8b46f5e0b003813bfac7458cf31697ba048cce13c715236f0792fc8e7d53c20d1dd47b48c026f64b407e24649bcf0c2d0dc02e184c1d54
|
7
|
+
data.tar.gz: 4dc27cedf73031652945823ee9aa75bce46a2a9df78f9aa49ad37cc05d4e7ce18c7273bf333a9121bd1f9c19bb8ec42dcd186df26aa76deb2ad08ee1b58e5549
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
@@ -9,18 +9,11 @@ matrix:
|
|
9
9
|
- # GitHub Pages
|
10
10
|
rvm: 2.1.1
|
11
11
|
env: GH_PAGES=true
|
12
|
-
- # Ruby 1.9
|
13
|
-
rvm: 1.9
|
14
|
-
env: JEKYLL_VERSION=2.0
|
15
12
|
allow_failures:
|
16
13
|
- env: GH_PAGES=true # Jekyll 2.4 will fail tests
|
17
14
|
fast_finish: true
|
18
15
|
|
19
16
|
rvm:
|
17
|
+
- 2.3.0
|
20
18
|
- 2.2
|
21
19
|
- 2.1
|
22
|
-
- 2.0
|
23
|
-
env:
|
24
|
-
- ""
|
25
|
-
- JEKYLL_VERSION=3.0
|
26
|
-
- JEKYLL_VERSION=2.0
|
data/Gemfile
CHANGED
data/History.markdown
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## HEAD
|
2
|
+
|
3
|
+
### Major Enhancements
|
4
|
+
|
5
|
+
* Support for custom redirect templates
|
6
|
+
* Use Jekyll's `absolute_url` filter to generate canonical URLs (now respecting `baseurl`)
|
7
|
+
* Rely more heavily on Jekyll's native Page, permalink, and extension handling logic
|
8
|
+
|
9
|
+
### Minor Enhancementse
|
10
|
+
|
11
|
+
* redirect_to Pages should not have a layout. (#115)
|
12
|
+
* Require Jekyll >= 3.3
|
13
|
+
|
14
|
+
### Development Enhancements
|
15
|
+
|
16
|
+
* Push redirect logic to the redirect page model (#131)
|
17
|
+
* Add Rubocop and enforce Jekyll coding standards
|
18
|
+
* Tests no longer build and write the entire site between each example
|
19
|
+
* Removed all the `is_*`? and `has_*`? helpers from the generator
|
20
|
+
|
1
21
|
## 0.11.0 / 2016-07-06
|
2
22
|
|
3
23
|
* Redirect page should not have any layout (#106)
|
data/README.md
CHANGED
@@ -100,10 +100,10 @@ redirect_from: /post/123456798/
|
|
100
100
|
```
|
101
101
|
|
102
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
103
|
|
106
|
-
|
104
|
+
If `site.url` is set, its value, together with `site.baseurl`, is used as a prefix for the redirect url automatically. This is useful for scenarios where a site isn't available from the domain root, so the redirects point to the correct path. If `site.url` is not set, only `site.baseurl` is used, if set.
|
105
|
+
|
106
|
+
**_Note_**: If you are hosting your Jekyll site on [GitHub Pages](https://pages.github.com/), and `site.url` is not set, the prefix is set to the pages domain name i.e. http://example.github.io/project or a custom CNAME.
|
107
107
|
|
108
108
|
### Redirect To
|
109
109
|
|
@@ -120,6 +120,15 @@ If you have multiple `redirect_to`s set, only the first one will be respected.
|
|
120
120
|
|
121
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.
|
122
122
|
|
123
|
+
## Customizing the redirect template
|
124
|
+
|
125
|
+
If you want to customize the redirect template, you can. Simply create a layout in your site's `_layouts` directory called `redirect.html`.
|
126
|
+
|
127
|
+
Your layout will get the following variables:
|
128
|
+
|
129
|
+
* `page.redirect.from` - the relative path to the redirect page
|
130
|
+
* `page.redirect.to` - the absolute URL (where available) to the target page
|
131
|
+
|
123
132
|
## Contributing
|
124
133
|
|
125
134
|
1. Fork it
|
@@ -18,10 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency "jekyll", "
|
21
|
+
spec.add_runtime_dependency "jekyll", "~> 3.3"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "rspec"
|
26
26
|
spec.add_development_dependency "jekyll-sitemap", "~> 0.8.1"
|
27
|
+
spec.add_development_dependency "rubocop", "~> 0.43"
|
27
28
|
end
|
data/lib/jekyll-redirect-from.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
require "jekyll"
|
2
|
+
require "jekyll-redirect-from/version"
|
3
|
+
require "jekyll-redirect-from/generator"
|
2
4
|
|
3
5
|
module JekyllRedirectFrom
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
# Jekyll classes which should be redirectable
|
7
|
+
CLASSES = [Jekyll::Page, Jekyll::Document].freeze
|
8
|
+
|
9
|
+
autoload :Context, "jekyll-redirect-from/context"
|
10
|
+
autoload :RedirectPage, "jekyll-redirect-from/redirect_page"
|
11
|
+
autoload :Redirectable, "jekyll-redirect-from/redirectable"
|
12
|
+
autoload :Layout, "jekyll-redirect-from/layout"
|
7
13
|
end
|
8
14
|
|
9
|
-
|
10
|
-
|
11
|
-
|
15
|
+
JekyllRedirectFrom::CLASSES.each do |klass|
|
16
|
+
klass.include JekyllRedirectFrom::Redirectable
|
17
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module JekyllRedirectFrom
|
2
|
+
class Generator < Jekyll::Generator
|
3
|
+
safe true
|
4
|
+
attr_reader :site
|
5
|
+
|
6
|
+
def generate(site)
|
7
|
+
@site = site
|
8
|
+
|
9
|
+
# Inject our layout, unless the user has already specified a redirect layout'
|
10
|
+
unless site.layouts.keys.any? { |name| name == "redirect" }
|
11
|
+
site.layouts["redirect"] = JekyllRedirectFrom::Layout.new(site)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Must duplicate pages to modify while in loop
|
15
|
+
(site.docs_to_write + site.pages.dup).each do |doc|
|
16
|
+
next unless JekyllRedirectFrom::CLASSES.include?(doc.class)
|
17
|
+
generate_redirect_from(doc)
|
18
|
+
generate_redirect_to(doc)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# For every `redirect_from` entry, generate a redirect page
|
25
|
+
def generate_redirect_from(doc)
|
26
|
+
doc.redirect_from.each do |path|
|
27
|
+
doc.site.pages << RedirectPage.redirect_from(doc, path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate_redirect_to(doc)
|
32
|
+
return unless doc.redirect_to
|
33
|
+
redirect_page = RedirectPage.redirect_to(doc, doc.redirect_to)
|
34
|
+
doc.data.merge!(redirect_page.data)
|
35
|
+
doc.content = doc.output = redirect_page.output
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module JekyllRedirectFrom
|
2
|
+
# A stubbed layout for our default redirect template
|
3
|
+
# We cannot use the standard Layout class because of site.in_source_dir
|
4
|
+
class Layout < Jekyll::Layout
|
5
|
+
def initialize(site)
|
6
|
+
@site = site
|
7
|
+
@base = File.dirname(__FILE__)
|
8
|
+
@name = "redirect.html"
|
9
|
+
@path = File.expand_path(@name, @base)
|
10
|
+
@relative_path = "_layouts/redirect.html"
|
11
|
+
|
12
|
+
self.data = {}
|
13
|
+
self.ext = "html"
|
14
|
+
self.content = File.read(@path)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en-US">
|
3
|
+
<meta charset="utf-8">
|
4
|
+
<title>Redirecting…</title>
|
5
|
+
<link rel="canonical" href="{{ page.redirect.to }}">
|
6
|
+
<meta http-equiv="refresh" content="0; url={{ page.redirect.to }}">
|
7
|
+
<h1>Redirecting…</h1>
|
8
|
+
<a href="{{ page.redirect.to }}">Click here if you are not redirected.</a>
|
9
|
+
<script>location="{{ page.redirect.to }}"</script>
|
10
|
+
</html>
|
@@ -1,42 +1,61 @@
|
|
1
1
|
# Encoding: utf-8
|
2
|
-
|
3
2
|
module JekyllRedirectFrom
|
3
|
+
# Specialty page which implements the redirect path logic
|
4
4
|
class RedirectPage < Jekyll::Page
|
5
|
-
#
|
5
|
+
# Use Jekyll's native absolute_url filter
|
6
|
+
include Jekyll::Filters::URLFilters
|
7
|
+
|
8
|
+
DEFAULT_DATA = {
|
9
|
+
"sitemap" => false,
|
10
|
+
"layout" => "redirect"
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
# Creates a new RedirectPage instance from a source path and redirect path
|
6
14
|
#
|
7
|
-
# site - The Site object
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
Jekyll::Hooks.trigger :pages, :post_init, self if JekyllRedirectFrom.jekyll_3?
|
15
|
+
# site - The Site object
|
16
|
+
# from - the (URL) path, relative to the site root to redirect from
|
17
|
+
# to - the relative path or URL which the page should redirect to
|
18
|
+
def self.from_paths(site, from, to)
|
19
|
+
page = RedirectPage.new(site, site.source, "", "redirect.html")
|
20
|
+
page.set_paths(from, to)
|
21
|
+
page
|
22
|
+
end
|
23
|
+
|
24
|
+
# Creates a new RedirectPage instance from the path to the given doc
|
25
|
+
def self.redirect_from(doc, path)
|
26
|
+
RedirectPage.from_paths(doc.site, path, doc.url)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Creates a new RedirectPage instance from the doc to the given path
|
30
|
+
def self.redirect_to(doc, path)
|
31
|
+
RedirectPage.from_paths(doc.site, doc.url, path)
|
25
32
|
end
|
26
33
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
# Overwrite the default read_yaml method since the file doesn't exist
|
35
|
+
def read_yaml(_base, _name, _opts = {})
|
36
|
+
self.content = ""
|
37
|
+
self.data ||= DEFAULT_DATA.dup
|
38
|
+
end
|
39
|
+
|
40
|
+
# Helper function to set the appropriate path metadata
|
41
|
+
#
|
42
|
+
# from - the relative path to the redirect page
|
43
|
+
# to - the relative path or absolute URL to the redirect target
|
44
|
+
def set_paths(from, to)
|
45
|
+
@context ||= context
|
46
|
+
data.merge!({
|
47
|
+
"permalink" => from,
|
48
|
+
"redirect" => {
|
49
|
+
"from" => from,
|
50
|
+
"to" => to =~ %r!^https?://! ? to : absolute_url(to)
|
51
|
+
}
|
52
|
+
})
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def context
|
58
|
+
JekyllRedirectFrom::Context.new(site)
|
40
59
|
end
|
41
60
|
end
|
42
61
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module JekyllRedirectFrom
|
2
|
+
# Module which can be mixed in to documents (and pages) to provide
|
3
|
+
# redirect_to and redirect_from helpers
|
4
|
+
module Redirectable
|
5
|
+
# Returns a string representing the relative path or URL
|
6
|
+
# to which the document should be redirected
|
7
|
+
def redirect_to
|
8
|
+
if to_liquid["redirect_to"].is_a?(Array)
|
9
|
+
to_liquid["redirect_to"].compact.first
|
10
|
+
else
|
11
|
+
to_liquid["redirect_to"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns an array representing the relative paths to other
|
16
|
+
# documents which should be redirected to this document
|
17
|
+
def redirect_from
|
18
|
+
if to_liquid["redirect_from"].is_a?(Array)
|
19
|
+
to_liquid["redirect_from"].compact
|
20
|
+
else
|
21
|
+
[to_liquid["redirect_from"]].compact
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/script/cibuild
CHANGED
File without changes
|
data/spec/integrations_spec.rb
CHANGED
@@ -1,13 +1,86 @@
|
|
1
|
-
|
1
|
+
RSpec.describe "JekyllRedirectFrom integration tests" do
|
2
|
+
before { site.process }
|
3
|
+
let(:relative_path) { "" }
|
4
|
+
let(:path) { dest_dir(relative_path) }
|
5
|
+
let(:contents) { File.read(path) }
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
+
context "pages" do
|
8
|
+
context "single redirect from" do
|
9
|
+
let(:relative_path) { "some/other/path.html" }
|
10
|
+
|
11
|
+
it "exists in the built site" do
|
12
|
+
expect(path).to exist
|
13
|
+
expect(contents).to match("http://jekyllrb.com/one_redirect_from.html")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "multiple redirect froms" do
|
18
|
+
%w(help contact let-there/be/light-he-said geepers/mccreepin).each do |redirect|
|
19
|
+
context "the #{redirect} redirect" do
|
20
|
+
let(:relative_path) { "#{redirect}.html" }
|
21
|
+
|
22
|
+
it "exists in the built site" do
|
23
|
+
expect(path).to exist
|
24
|
+
expect(contents).to match("http://jekyllrb.com/multiple_redirect_froms.html")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "a redirect to URL" do
|
31
|
+
let(:relative_path) { "one_redirect_to_url.html" }
|
32
|
+
|
33
|
+
it "exists in the built site" do
|
34
|
+
expect(path).to exist
|
35
|
+
expect(contents).to match("https://www.github.com")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "a redirect to path" do
|
40
|
+
let(:relative_path) { "one_redirect_to_path.html" }
|
41
|
+
|
42
|
+
it "exists in the built site" do
|
43
|
+
expect(path).to exist
|
44
|
+
expect(contents).to match("http://jekyllrb.com/foo")
|
45
|
+
end
|
46
|
+
end
|
7
47
|
end
|
8
48
|
|
9
|
-
|
10
|
-
|
11
|
-
|
49
|
+
context "documents" do
|
50
|
+
context "a single redirect from" do
|
51
|
+
let(:relative_path) { "articles/23128432159832/mary-had-a-little-lamb.html" }
|
52
|
+
|
53
|
+
it "exists in the built site" do
|
54
|
+
expect(path).to exist
|
55
|
+
expect(contents).to match("http://jekyllrb.com/articles/redirect-me-plz.html")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "redirect to" do
|
60
|
+
let(:relative_path) { "articles/redirect-somewhere-else-plz.html" }
|
61
|
+
|
62
|
+
it "exists in the built site" do
|
63
|
+
expect(path).to exist
|
64
|
+
expect(contents).to match("http://www.zombo.com")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with a permalink" do
|
69
|
+
let(:relative_path) { "tags/our projects/index.html" }
|
70
|
+
|
71
|
+
it "exists in the built site" do
|
72
|
+
expect(path).to exist
|
73
|
+
expect(contents).to match("http://jekyllrb.com/tags/our-projects/")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "sitemap" do
|
79
|
+
let(:relative_path) { "sitemap.xml" }
|
80
|
+
|
81
|
+
it "doesn't contain redirects" do
|
82
|
+
expect(contents).to_not be_nil
|
83
|
+
expect(contents).to_not match("redirect_to")
|
84
|
+
end
|
12
85
|
end
|
13
86
|
end
|