nanoc-redirector 0.2.1 → 0.4.1

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
- SHA1:
3
- metadata.gz: 7fb0da35d3e7afc4bf672a1d9eb608ce32e9c430
4
- data.tar.gz: 9b37d22ba63efb07a0b2221fbaee159a9234a8d5
2
+ SHA256:
3
+ metadata.gz: ac9a06ba7c6ceccd6033155f23e151bfdd9e7fa36f92ce116c708c3b56883919
4
+ data.tar.gz: 8be34f3d29976ef25a42c0b69f31c79a5882e97cfa0517435d6e6c1385bddc61
5
5
  SHA512:
6
- metadata.gz: 3ab3e45fa7b6e8a86b492fd0898f5d135b953b0df29c152c3c4f37d3393fd82c7d97103390a65927ba277217d86ce3352c704ec009d816d36c0baf6e9f2da286
7
- data.tar.gz: 6bf518bbb869ce3b40edbe4b8403443ebc16941a6704d84c70d02f8edcb1338e2500fd551e5a478b947d439a548af9aabf561ba44f47fdc696ed8b3c3e072bb0
6
+ metadata.gz: d1ffb91131970f29755c8a72ed84718fc54e116905ad499d79f99591dbfaaed4b031cd8cc8dde65d3fe03d2f6a38787811cad507af850569d5824b58a4a71b67
7
+ data.tar.gz: 2c656ed22b097be021224f2b1d8d985b9a36a8da735931db56011041500fc4ad55a06123cc64e8ada54a53021535d83eaafce0403166a32f30019d2e82d686f1
data/.gitignore CHANGED
@@ -27,4 +27,6 @@ doc/
27
27
  .DS_Store
28
28
 
29
29
  test/fixtures/output
30
+ test/fixtures/somewhere
30
31
  test/fixtures/tmp
32
+ test/fixtures/nanoc.yaml
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
3
+ - 2.6.3
4
4
  env:
5
5
  global:
6
6
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Garen Torikian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -57,15 +57,22 @@ redirect_from: /post/123456798/
57
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
58
 
59
59
  ``` ruby
60
+ require 'nanoc-redirector'
61
+
60
62
  postprocess do
61
- REPS.each do |rep|
62
- @items.each do |item|
63
- NanocRedirector::RedirectFrom.process(item, item.path(rep: rep))
64
- end
63
+ @items.each do |item|
64
+ NanocRedirector::RedirectFrom.process(item, item.identifier.without_ext)
65
65
  end
66
66
  end
67
67
  ```
68
68
 
69
+ #### Configuration
70
+
71
+ `RedirectFrom.process` takes an additional argument, `config`, which accepts two keys:
72
+
73
+ * [`:output_dir`](https://nanoc.ws/doc/reference/config/#output_dir): the directory where files are written to
74
+ * [`:index_filenames`](https://nanoc.ws/doc/reference/config/#index_filenames): a list of index filenames, i.e. names of files that will be served by a web server when a directory is requested.
75
+
69
76
  ### Redirect To filter
70
77
 
71
78
  Sometimes, you may want to redirect a site page to a totally different website. This plugin also supports that with the `redirect_to` key:
@@ -3,11 +3,13 @@ require 'version'
3
3
 
4
4
  module NanocRedirector
5
5
  module RedirectFrom
6
- def self.process(item, dest)
6
+ def self.process(item, dest, config = {})
7
7
  return if item[:redirect_from].nil?
8
8
  return if dest.nil?
9
9
  redirect_hash = {}
10
10
 
11
+ output_dir = config[:output_dir] || 'output'
12
+ index_filenames = config[:index_filenames] || ['index.html']
11
13
  key = item.identifier.without_ext
12
14
  value = item[:redirect_from].is_a?(String) ? [item[:redirect_from]] : item[:redirect_from]
13
15
 
@@ -16,10 +18,12 @@ module NanocRedirector
16
18
  redirect_hash.values.each do |redirects|
17
19
  redirects.each do |redirect|
18
20
  content = NanocRedirector.redirect_template(dest)
19
- dir = File.join("output", redirect)
20
- redirect_path = File.join(dir, "index.html")
21
- FileUtils.mkdir_p(dir) unless File.directory?(dir)
22
- File.write(redirect_path, content) unless File.exist? redirect_path
21
+ dir = File.join(output_dir, redirect)
22
+ index_filenames.each do |index_filename|
23
+ redirect_path = File.join(dir, index_filename)
24
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
25
+ File.write(redirect_path, content) unless File.exist? redirect_path
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -34,6 +38,8 @@ module NanocRedirector
34
38
  <title>Redirecting...</title>
35
39
  <link rel=canonical href="#{item_url}">
36
40
  <meta http-equiv=refresh content="0; url=#{item_url}">
41
+ </head>
42
+ <body>
37
43
  <h1>Redirecting...</h1>
38
44
  <a href="#{item_url}">Click here if you are not redirected.</a>
39
45
  <script>location='#{item_url}'</script>
@@ -1,3 +1,3 @@
1
1
  module NanocRedirector
2
- VERSION = '0.2.1'
2
+ VERSION = '0.4.1'.freeze
3
3
  end
@@ -7,6 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.version = NanocRedirector::VERSION
8
8
  spec.authors = 'Garen J. Torikian'
9
9
  spec.email = %w(gjtorikian@gmail.com)
10
+ spec.licenses = ['MIT']
10
11
 
11
12
  spec.summary = %w(Allows you to generate redirects to and from an item.)
12
13
  spec.homepage = 'https://www.github.com/gjtorikian/nanoc-redirector'
@@ -16,7 +17,7 @@ Gem::Specification.new do |spec|
16
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
18
  spec.require_paths = ['lib']
18
19
 
19
- spec.add_runtime_dependency 'nanoc', '~> 4.3.0'
20
+ spec.add_runtime_dependency 'nanoc', '~> 4.9'
20
21
 
21
22
  spec.add_development_dependency 'rake'
22
23
  spec.add_development_dependency 'minitest', '~> 5.8'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-redirector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen J. Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-05 00:00:00.000000000 Z
11
+ date: 2020-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nanoc
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.3.0
19
+ version: '4.9'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 4.3.0
26
+ version: '4.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -76,6 +76,7 @@ files:
76
76
  - ".gitignore"
77
77
  - ".travis.yml"
78
78
  - Gemfile
79
+ - LICENSE
79
80
  - README.md
80
81
  - Rakefile
81
82
  - lib/nanoc-redirector.rb
@@ -84,7 +85,8 @@ files:
84
85
  - nanoc-redirector.gemspec
85
86
  - script/bootstrap
86
87
  homepage: https://www.github.com/gjtorikian/nanoc-redirector
87
- licenses: []
88
+ licenses:
89
+ - MIT
88
90
  metadata: {}
89
91
  post_install_message:
90
92
  rdoc_options: []
@@ -101,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
103
  - !ruby/object:Gem::Version
102
104
  version: '0'
103
105
  requirements: []
104
- rubyforge_project:
105
- rubygems_version: 2.4.5.1
106
+ rubygems_version: 3.1.2
106
107
  signing_key:
107
108
  specification_version: 4
108
109
  summary: '["Allows", "you", "to", "generate", "redirects", "to", "and", "from", "an",