jekyll-redirect-from 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e7750191f33e416706a027215c20020c8e15cf3
4
+ data.tar.gz: e2e81d1df3c42e88700f765ab9abc4871417be16
5
+ SHA512:
6
+ metadata.gz: 79cc62c19389fe795d361b4163d59f0f111bfeca5af38c8c3ac8e350658364b59d0ecdb29310f1d3a79af699febc2af34ca641e9dea88b1a9998c72cba072295
7
+ data.tar.gz: 589e328c455bbf4312a2d4ad9736d8f231545830822acd33a852494959ceff861b80b2157a8b54f220d47191bea52284fb20907fa232c88f0f7bc897251dd98d
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-alt-urls.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 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,70 @@
1
+ # Jekyll::AltUrls
2
+
3
+ Give your Jekyll 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
+ `jekyll-redirect-from` handle it for you.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'jekyll-redirect-from'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install jekyll-redirect-from
25
+
26
+ Once it's installed into your evironment, add it to your `_config.yml`:
27
+
28
+ ```yaml
29
+ gem:
30
+ - jekyll-redirect-from
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ The object of this gem is to allow an author to specify multiple URLs for a
36
+ page, such that the alternative URLs redirect to the new Jekyll URL. This is
37
+
38
+ To use it, simply add the array to the YAML front-matter of your page or post:
39
+
40
+ ```yaml
41
+ title: My amazing post
42
+ redirect_from:
43
+ - /post/123456789
44
+ - /post/123456789/my-amazing-post
45
+ ```
46
+
47
+ This will generate the following pages in the destination:
48
+
49
+ ```text
50
+ /post/123456789/index.html
51
+ /post/123456789/my-amazing-post/index.html
52
+ ```
53
+
54
+ These pages will contain an HTTP-REFRESH meta tag which redirect to your URL.
55
+
56
+ You can also specify just one url like this:
57
+
58
+
59
+ ```text
60
+ title: My other awesome post
61
+ redirect_from: /post/123456798
62
+ ```
63
+
64
+ ## Contributing
65
+
66
+ 1. Fork it
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll/redirect_from/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-redirect-from"
8
+ spec.version = Jekyll::RedirectFrom::VERSION
9
+ spec.authors = ["Parker Moore"]
10
+ spec.email = ["parkrmoore@gmail.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/jekyll/jekyll-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 "jekyll", "~> 1.4"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,34 @@
1
+ require "jekyll/redirect_from/version"
2
+ require "jekyll/redirect_from/redirect_page"
3
+
4
+ module Jekyll
5
+ class RedirectFrom < Generator
6
+ def generate(site)
7
+ original_pages = site.pages.dup
8
+ generate_alt_urls(site, site.posts)
9
+ generate_alt_urls(site, original_pages)
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).flatten.each do |alt_url|
16
+ redirect_page = RedirectPage.new(site, site.source, File.dirname(alt_url), File.basename(alt_url))
17
+ redirect_page.generate_redirect_content(item.url)
18
+ site.pages << redirect_page
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def has_alt_urls?(page_or_post)
25
+ page_or_post.data.has_key?('redirect_from') &&
26
+ !alt_urls(page_or_post).nil? &&
27
+ !alt_urls(page_or_post).empty?
28
+ end
29
+
30
+ def alt_urls(page_or_post)
31
+ Array[page_or_post.data['redirect_from']].flatten
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
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
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ class RedirectFrom
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-redirect-from
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Parker Moore
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Seamlessly specify multiple redirection URLs for your pages and posts
56
+ email:
57
+ - parkrmoore@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - 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
71
+ homepage: https://github.com/jekyll/jekyll-redirect-from
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.0.14
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Seamlessly specify multiple redirection URLs for your pages and posts
95
+ test_files: []