jekyll-redirect-from 0.1.0 → 0.2.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: 4e7750191f33e416706a027215c20020c8e15cf3
4
- data.tar.gz: e2e81d1df3c42e88700f765ab9abc4871417be16
3
+ metadata.gz: aec13092a90f8e5d5e8c9b4484b2e78c7dccdd6b
4
+ data.tar.gz: 18270a4f1c6667b89bda14064042cce909370686
5
5
  SHA512:
6
- metadata.gz: 79cc62c19389fe795d361b4163d59f0f111bfeca5af38c8c3ac8e350658364b59d0ecdb29310f1d3a79af699febc2af34ca641e9dea88b1a9998c72cba072295
7
- data.tar.gz: 589e328c455bbf4312a2d4ad9736d8f231545830822acd33a852494959ceff861b80b2157a8b54f220d47191bea52284fb20907fa232c88f0f7bc897251dd98d
6
+ metadata.gz: b108df3637aaf1355a1be30b15432816545fe29c905acc41607008c76b4a1fc9b2418c025eba1bd620315917284dcf2e7b88ea8f3cbb491dd60ede933126d4c2
7
+ data.tar.gz: e9328c6da23831ac226d13266f0b01fe620c59c8c02c7a8df0dfc06856b0607e9b08599a06bc1cb991eefe37ef94b44f93d5c199de3c0b9ea5901242388e14cc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+ script: "script/cibuild"
data/History.markdown ADDED
@@ -0,0 +1,27 @@
1
+ ## HEAD
2
+
3
+ ### Major Enhancements
4
+
5
+ ### Minor Enhancements
6
+
7
+ ### Bug Fixes
8
+
9
+ ### Development Fixes
10
+
11
+ ## 0.2.0 / 2014-01-04
12
+
13
+ ### Minor Enhancements
14
+
15
+ * Allow user to set one or many `redirect_from` URLs
16
+ * Rename from `jekyll-alt-urls` to `jekyll-redirect-from` (props to @benbalter)
17
+ * Namespace now its own module: `JekyllRedirectFrom` (#3)
18
+
19
+ ### Development Fixes
20
+
21
+ * Add history file
22
+ * Add specs (#3)
23
+ * Add TravisCI badge (#4)
24
+
25
+ ## 0.1.0 / 2013-12-15
26
+
27
+ * Birthday!
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Jekyll::AltUrls
1
+ # JekyllRedirectFrom
2
2
 
3
3
  Give your Jekyll posts and pages multiple URLs.
4
4
 
@@ -9,6 +9,8 @@ impractical to create new pages in the proper subdirectories so they, e.g.
9
9
  Instead of dealing with maintaining those pages for redirection, let
10
10
  `jekyll-redirect-from` handle it for you.
11
11
 
12
+ [![Build Status](https://travis-ci.org/jekyll/jekyll-redirect-from.png?branch=master)](https://travis-ci.org/jekyll/jekyll-redirect-from)
13
+
12
14
  ## Installation
13
15
 
14
16
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'jekyll/redirect_from/version'
4
+ require 'jekyll-redirect-from/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "jekyll-redirect-from"
8
- spec.version = Jekyll::RedirectFrom::VERSION
8
+ spec.version = JekyllRedirectFrom::VERSION
9
9
  spec.authors = ["Parker Moore"]
10
10
  spec.email = ["parkrmoore@gmail.com"]
11
11
  spec.description = %q{Seamlessly specify multiple redirection URLs for your pages and posts}
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
25
26
  end
@@ -0,0 +1,4 @@
1
+ require "jekyll"
2
+ require "jekyll-redirect-from/version"
3
+ require "jekyll-redirect-from/redirect_page"
4
+ require "jekyll-redirect-from/redirector"
@@ -0,0 +1,40 @@
1
+ module JekyllRedirectFrom
2
+ class RedirectPage < Jekyll::Page
3
+ # Initialize a new RedirectPage.
4
+ #
5
+ # site - The Site object.
6
+ # base - The String path to the source.
7
+ # dir - The String path between the source and the file.
8
+ # name - The String filename of the file.
9
+ def initialize(site, base, dir, name)
10
+ @site = site
11
+ @base = base
12
+ @dir = dir
13
+ @name = name
14
+
15
+ self.process(name)
16
+ self.data = {}
17
+ end
18
+
19
+ def generate_redirect_content(item_url)
20
+ self.output = self.content = <<-EOF
21
+ <!DOCTYPE html>
22
+ <html>
23
+ <head>
24
+ <title>Redirecting...</title>
25
+ <link rel="canonical" href="#{item_url}"/>
26
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
27
+ <meta http-equiv="refresh" content="0; url=#{item_url}" />
28
+ </head>
29
+ <body>
30
+ <p><strong>Redirecting...</strong></p>
31
+ <p><a href='#{item_url}'>Click here if you are not redirected.</a></p>
32
+ <script>
33
+ document.location.href = "#{item_url}";
34
+ </script>
35
+ </body>
36
+ </html>
37
+ EOF
38
+ end
39
+ end
40
+ end
@@ -1,8 +1,5 @@
1
- require "jekyll/redirect_from/version"
2
- require "jekyll/redirect_from/redirect_page"
3
-
4
- module Jekyll
5
- class RedirectFrom < Generator
1
+ module JekyllRedirectFrom
2
+ class Redirector < Jekyll::Generator
6
3
  def generate(site)
7
4
  original_pages = site.pages.dup
8
5
  generate_alt_urls(site, site.posts)
@@ -0,0 +1,3 @@
1
+ module JekyllRedirectFrom
2
+ VERSION = "0.2.0"
3
+ end
data/script/bootstrap ADDED
@@ -0,0 +1,3 @@
1
+ #! /bin/bash
2
+
3
+ bundle install
data/script/cibuild ADDED
@@ -0,0 +1,4 @@
1
+ #! /bin/bash
2
+
3
+ script/bootstrap > /dev/null 2>&1
4
+ bundle exec rake spec
@@ -0,0 +1,3 @@
1
+ url: http://jekyllrb.com
2
+ gems:
3
+ - jekyll-redirect-from
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: Please redirect me, sir.
3
+ redirect_from: /posts/23128432159832/mary-had-a-little-lamb
4
+ ---
5
+
6
+ Yay.
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: I have lots of redirect urls
3
+ redirect_from:
4
+ - help
5
+ - contact
6
+ - let-there/be/light-he-said
7
+ - /geepers/mccreepin
8
+ ---
9
+
10
+ Lots of redirect urls
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: I only have one redirect url.
3
+ redirect_from: mencius/was/my/father
4
+ ---
5
+
6
+ One redirect url
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ describe JekyllRedirectFrom::RedirectPage do
4
+ let(:redirect_page) { described_class.new(@site, @site.source, "posts/12435151125", "larry-had-a-little-lamb") }
5
+ let(:item_url) { File.join(@site.config["url"], "2014", "01", "03", "moving-to-jekyll.md") }
6
+ let(:page_content) { redirect_page.generate_redirect_content(item_url) }
7
+
8
+ context "#generate_redirect_content" do
9
+ it "sets the #content to the generated refresh page" do
10
+ expect(page_content).to eq(" <!DOCTYPE html>\n <html>\n <head>\n <title>Redirecting...</title>\n <link rel=\"canonical\" href=\"http://jekyllrb.com/2014/01/03/moving-to-jekyll.md\"/>\n <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n <meta http-equiv=\"refresh\" content=\"0; url=http://jekyllrb.com/2014/01/03/moving-to-jekyll.md\" />\n </head>\n <body>\n <p><strong>Redirecting...</strong></p>\n <p><a href='http://jekyllrb.com/2014/01/03/moving-to-jekyll.md'>Click here if you are not redirected.</a></p>\n <script>\n document.location.href = \"http://jekyllrb.com/2014/01/03/moving-to-jekyll.md\";\n </script>\n </body>\n </html>\n")
11
+ end
12
+
13
+ it "contains the meta refresh tag" do
14
+ expect(page_content).to include("<meta http-equiv=\"refresh\" content=\"0; url=#{item_url}\" />")
15
+ end
16
+
17
+ it "contains JavaScript redirect" do
18
+ expect(page_content).to include("document.location.href = \"http://jekyllrb.com/2014/01/03/moving-to-jekyll.md\";")
19
+ end
20
+
21
+ it "contains canonical link in header" do
22
+ expect(page_content).to include("<link rel=\"canonical\" href=\"http://jekyllrb.com/2014/01/03/moving-to-jekyll.md\"/>")
23
+ end
24
+
25
+ it "contains a clickable link to redirect" do
26
+ expect(page_content).to include("<a href='http://jekyllrb.com/2014/01/03/moving-to-jekyll.md'>Click here if you are not redirected.</a>")
27
+ end
28
+ end
29
+
30
+ context "when writing to disk" do
31
+ let(:redirect_page_full_path) { redirect_page.destination(@site.dest) }
32
+
33
+ before(:each) do
34
+ redirect_page.generate_redirect_content(item_url)
35
+ redirect_page.write(@site.dest)
36
+ end
37
+
38
+ it "fetches the path properly" do
39
+ expect(redirect_page_full_path).to match /\/spec\/fixtures\/\_site\/posts\/12435151125\/larry-had-a-little-lamb/
40
+ end
41
+
42
+ it "is written to the proper location" do
43
+ expect(File.exist?(redirect_page_full_path)).to be_true
44
+ end
45
+
46
+ it "writes the context we expect" do
47
+ expect(File.read(redirect_page_full_path)).to eql(page_content)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
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") }
8
+
9
+ 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
11
+ end
12
+
13
+ it "handles one redirect path" do
14
+ expect(redirector.alt_urls(page_with_one)).to eql(["mencius/was/my/father"])
15
+ end
16
+
17
+ it "handles many redirect paths" do
18
+ expect(redirector.alt_urls(page_with_many)).to eql(["help", "contact", "let-there/be/light-he-said", "/geepers/mccreepin"])
19
+ end
20
+
21
+ context "refresh page generation" do
22
+ before(:all) do
23
+ described_class.new.generate(@site)
24
+ end
25
+
26
+ 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
28
+ end
29
+
30
+ 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
35
+ end
36
+
37
+ 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
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,48 @@
1
+ require "jekyll"
2
+ require File.expand_path("lib/jekyll-redirect-from.rb")
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+ config.order = 'random'
9
+
10
+ config.expect_with :rspec do |c|
11
+ c.syntax = :expect
12
+ end
13
+
14
+ config.before(:all) do
15
+ Jekyll.logger.log_level = Jekyll::Stevenson::ERROR
16
+
17
+ @fixtures_path = Pathname.new(__FILE__).parent.join("fixtures")
18
+ @dest = @fixtures_path.join("_site")
19
+ @posts_src = File.join(@fixtures_path, "_posts")
20
+ @layouts_src = File.join(@fixtures_path, "_layouts")
21
+ @plugins_src = File.join(@fixtures_path, "_plugins")
22
+
23
+ @site = Jekyll::Site.new(Jekyll.configuration({
24
+ "source" => @fixtures_path.to_s,
25
+ "destination" => @dest.to_s,
26
+ "plugins" => @plugins_src
27
+ }))
28
+
29
+ @dest.rmtree if @dest.exist?
30
+ @site.process
31
+ end
32
+
33
+ config.after(:all) do
34
+ @dest.rmtree if @dest.exist?
35
+ end
36
+
37
+ def setup_post(file)
38
+ Jekyll::Post.new(@site, @fixtures_path, '', file)
39
+ end
40
+
41
+ def setup_page(file)
42
+ Jekyll::Page.new(@site, @fixtures_path, File.dirname(file), File.basename(file))
43
+ end
44
+
45
+ def destination_file_exists?(file)
46
+ File.exists?(File.join(@dest.to_s, file))
47
+ end
48
+ end
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.1.0
4
+ version: 0.2.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: 2013-12-15 00:00:00.000000000 Z
11
+ date: 2014-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Seamlessly specify multiple redirection URLs for your pages and posts
56
70
  email:
57
71
  - parkrmoore@gmail.com
@@ -60,14 +74,27 @@ extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
76
  - .gitignore
77
+ - .rspec
78
+ - .travis.yml
63
79
  - Gemfile
80
+ - History.markdown
64
81
  - LICENSE.txt
65
82
  - README.md
66
83
  - Rakefile
67
84
  - jekyll-redirect-from.gemspec
68
- - lib/jekyll/redirect_from.rb
69
- - lib/jekyll/redirect_from/redirect_page.rb
70
- - lib/jekyll/redirect_from/version.rb
85
+ - lib/jekyll-redirect-from.rb
86
+ - lib/jekyll-redirect-from/redirect_page.rb
87
+ - lib/jekyll-redirect-from/redirector.rb
88
+ - lib/jekyll-redirect-from/version.rb
89
+ - script/bootstrap
90
+ - script/cibuild
91
+ - spec/fixtures/_config.yml
92
+ - spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
93
+ - spec/fixtures/multiple_redirect_urls.md
94
+ - spec/fixtures/one_redirect_url.md
95
+ - spec/jekyll_redirect_from/redirect_page_spec.rb
96
+ - spec/jekyll_redirect_from/redirector_spec.rb
97
+ - spec/spec_helper.rb
71
98
  homepage: https://github.com/jekyll/jekyll-redirect-from
72
99
  licenses:
73
100
  - MIT
@@ -92,4 +119,11 @@ rubygems_version: 2.0.14
92
119
  signing_key:
93
120
  specification_version: 4
94
121
  summary: Seamlessly specify multiple redirection URLs for your pages and posts
95
- test_files: []
122
+ test_files:
123
+ - spec/fixtures/_config.yml
124
+ - spec/fixtures/_posts/2014-01-03-redirect-me-plz.md
125
+ - spec/fixtures/multiple_redirect_urls.md
126
+ - spec/fixtures/one_redirect_url.md
127
+ - spec/jekyll_redirect_from/redirect_page_spec.rb
128
+ - spec/jekyll_redirect_from/redirector_spec.rb
129
+ - spec/spec_helper.rb
@@ -1,41 +0,0 @@
1
- module Jekyll
2
- class RedirectFrom < Generator
3
- class RedirectPage < Page
4
- # Initialize a new RedirectPage.
5
- #
6
- # site - The Site object.
7
- # base - The String path to the source.
8
- # dir - The String path between the source and the file.
9
- # name - The String filename of the file.
10
- def initialize(site, base, dir, name)
11
- @site = site
12
- @base = base
13
- @dir = dir
14
- @name = name
15
-
16
- self.process(name)
17
- end
18
-
19
- def generate_redirect_content(item_url)
20
- self.content = <<-EOF
21
- <!DOCTYPE html>
22
- <html>
23
- <head>
24
- <title>Redirecting...</title>
25
- <link rel="canonical" href="#{item_url}"/>
26
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
27
- <meta http-equiv="refresh" content="0; url=#{item_url}" />
28
- </head>
29
- <body>
30
- <p><strong>Redirecting...</strong></p>
31
- <p><a href='#{item_url}'>Click here if you are not redirected.</a></p>
32
- <script>
33
- document.location.href = "#{item_url}";
34
- </script>
35
- </body>
36
- </html>
37
- EOF
38
- end
39
- end
40
- end
41
- end
@@ -1,5 +0,0 @@
1
- module Jekyll
2
- class RedirectFrom
3
- VERSION = "0.1.0"
4
- end
5
- end