nanoc-redirector 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9af124d8b7a32fd875577a066429214faf9d78c7
4
+ data.tar.gz: 6a4442383d789bacce4ff049cbcce9c9c095cce7
5
+ SHA512:
6
+ metadata.gz: 203cf8a015375f9449a9b7f50eb77fb2257b9bf2b1445a8c64787732960d6a0b778f275c2104ae4e9c8cf7f0f3d5485654cdb1a1741602df456346e1432edebb
7
+ data.tar.gz: 8156759b947c00ff710ecbe0b8df6786cb93ea44add4ddd3b1ed9e49cad315a53e4e4c2be51700c70bff77702f70eaa628568e7049c7582e6c9424e3e3cc5a9f
@@ -0,0 +1,30 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+ bin
15
+
16
+ Gemfile.lock
17
+ out/
18
+ sample.rb
19
+ run_sample.rb
20
+ src/
21
+ docs/
22
+
23
+ # YARD artifacts
24
+ .yardoc
25
+ _yardoc
26
+ doc/
27
+ .DS_Store
28
+
29
+ test/fixtures/output
30
+ test/fixtures/tmp
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ env:
5
+ global:
6
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
7
+
8
+ sudo: false
9
+ cache: bundler
10
+
11
+ git:
12
+ depth: 10
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nanoc-redirector.gemspec
4
+ gemspec
@@ -0,0 +1,88 @@
1
+ # Nanoc-Redirector
2
+
3
+ This plugin implements client-side redirects _from_ and _to_ other generated pages. It's pretty close in functionality to Jekyll's [redirect-from](https://github.com/jekyll/jekyll-redirect-from) plugin.
4
+
5
+ Redirects are performed by serving an HTML file with an HTTP-REFRESH meta
6
+ tag which points to your destination. No `.htaccess` file, nginx conf, xml
7
+ file, or anything else will be generated. It simply creates HTML files.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'nanoc-redirector'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install nanoc-redirector
24
+
25
+ ## Usage
26
+
27
+ The object of this gem is to allow an author to specify multiple URLs for a
28
+ page, such that the alternative URLs redirect to the new URL.
29
+
30
+ To use it, simply add a string or array to the YAML front-matter of your page:
31
+
32
+ ### Redirect From
33
+
34
+ ``` yaml
35
+ title: My amazing post
36
+ redirect_from:
37
+ - /post/123456789/
38
+ - /post/123456789/my-amazing-post/
39
+ ```
40
+
41
+ For example, this frontmatter will generate two pages in the following destinations:
42
+
43
+ ```
44
+ /post/123456789/
45
+ /post/123456789/my-amazing-post/
46
+ ```
47
+
48
+ Each will point to wherever `My amazing post` is routed to.
49
+
50
+ You can also specify just one url like this:
51
+
52
+ ```text
53
+ title: My other awesome post
54
+ redirect_from: /post/123456798/
55
+ ```
56
+
57
+ You can implement this functionality by calling `NanocRedirector::RedirectFrom.process` anywhere in your Rules file. You must pass in the item to redirect to, as well as its destination. For example:
58
+
59
+ ``` ruby
60
+ postprocess do
61
+ REPS.each do |rep|
62
+ @items.each do |item|
63
+ NanocRedirector::RedirectFrom.process(item, item.path(rep: rep))
64
+ end
65
+ end
66
+ end
67
+ ```
68
+
69
+ ### Redirect To filter
70
+
71
+ Sometimes, you may want to redirect a site page to a totally different website. This plugin also supports that with the `redirect_to` key:
72
+
73
+ ``` yaml
74
+ title: My amazing post
75
+ redirect_to:
76
+ - http://www.github.com
77
+ ```
78
+
79
+ If you have multiple `redirect_to`s set, only the first one will be respected.
80
+
81
+ You can implement this functionality by adding a filter to your compile step:
82
+
83
+ ``` ruby
84
+ compile '/**/*.md' do
85
+ filter :redirect_to, { :redirect_to => @item[:redirect_to] }
86
+ layout '/default.*'
87
+ end
88
+ ```
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task default: [:test]
@@ -0,0 +1,45 @@
1
+ require 'redirect-to-filter'
2
+ require 'version'
3
+
4
+ module NanocRedirector
5
+ module RedirectFrom
6
+ def self.process(item, dest)
7
+ return if item[:redirect_from].nil?
8
+ return if dest.nil?
9
+ redirect_hash = {}
10
+
11
+ key = item.identifier.without_ext
12
+ value = item[:redirect_from].is_a?(String) ? [item[:redirect_from]] : item[:redirect_from]
13
+
14
+ redirect_hash[key] = value
15
+
16
+ redirect_hash.values.each do |redirects|
17
+ redirects.each do |redirect|
18
+ content = NanocRedirector.redirect_template(dest)
19
+ dir = "output/#{redirect}"
20
+ unless File.directory?(dir)
21
+ FileUtils.mkdir_p(dir)
22
+ File.write("#{dir}/index.html", content)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def self.redirect_template(item_url)
30
+ <<-EOF
31
+ <!DOCTYPE html>
32
+ <html>
33
+ <head>
34
+ <meta charset=utf-8>
35
+ <title>Redirecting...</title>
36
+ <link rel=canonical href="#{item_url}">
37
+ <meta http-equiv=refresh content="0; url=#{item_url}">
38
+ <h1>Redirecting...</h1>
39
+ <a href="#{item_url}">Click here if you are not redirected.</a>
40
+ <script>location='#{item_url}'</script>
41
+ </body>
42
+ </html>
43
+ EOF
44
+ end
45
+ end
@@ -0,0 +1,9 @@
1
+ class RedirectToFilter < Nanoc::Filter
2
+ identifier :redirect_to
3
+ type :text
4
+
5
+ def run(content, params = {})
6
+ return content unless params[:redirect_to]
7
+ NanocRedirector.redirect_template(params[:redirect_to])
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module NanocRedirector
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'nanoc-redirector'
7
+ spec.version = NanocRedirector::VERSION
8
+ spec.authors = %w(Garen Torikian)
9
+ spec.email = %w(gjtorikian@gmail.com)
10
+
11
+ spec.summary = %w(Allows you to generate redirects to and from an item.)
12
+ spec.homepage = 'https://www.github.com/gjtorikian/nanoc-redirector'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.bindir = 'bin'
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_runtime_dependency 'nanoc', '4.1.0rc1'
20
+
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'minitest', '~> 5.8'
23
+ spec.add_development_dependency 'awesome_print'
24
+ end
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ bundle install "$@"
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-redirector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Garen
8
+ - Torikian
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-12-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nanoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 4.1.0rc1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 4.1.0rc1
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '5.8'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '5.8'
56
+ - !ruby/object:Gem::Dependency
57
+ name: awesome_print
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
+ description:
71
+ email:
72
+ - gjtorikian@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - lib/nanoc-redirector.rb
83
+ - lib/redirect-to-filter.rb
84
+ - lib/version.rb
85
+ - nanoc-redirector.gemspec
86
+ - script/bootstrap
87
+ homepage: https://www.github.com/gjtorikian/nanoc-redirector
88
+ licenses: []
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.5.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: '["Allows", "you", "to", "generate", "redirects", "to", "and", "from", "an",
110
+ "item."]'
111
+ test_files: []