nanoc-redirector 0.3.0 → 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: eb61dd555ad942541bbf82b7feaa9e1dfce02381
4
- data.tar.gz: c6057a35380dc3aad633af5d30d5f949a07dae2b
2
+ SHA256:
3
+ metadata.gz: ac9a06ba7c6ceccd6033155f23e151bfdd9e7fa36f92ce116c708c3b56883919
4
+ data.tar.gz: 8be34f3d29976ef25a42c0b69f31c79a5882e97cfa0517435d6e6c1385bddc61
5
5
  SHA512:
6
- metadata.gz: 746c2bb57624bfb7d500d4cf323946a9b7228b2ea0b2d5c56129047f35dda29d14d3504feffa12988d3c7ab29378b4819fae113e334f9b3ba8512e5234cea10f
7
- data.tar.gz: 3514fb18bee71fc21c3e6897500f1b1d8f06edaf6ca3f83fe413bf7239a7bd44d855050d89dcd7c904d2c90af33361fd1d0e166c5c22d51ab15eb72975d4f828
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
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3
3
+ - 2.6.3
4
4
  env:
5
5
  global:
6
6
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
data/README.md CHANGED
@@ -57,13 +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
63
  @items.each do |item|
62
- NanocRedirector::RedirectFrom.process(item, item.path)
64
+ NanocRedirector::RedirectFrom.process(item, item.identifier.without_ext)
63
65
  end
64
66
  end
65
67
  ```
66
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
+
67
76
  ### Redirect To filter
68
77
 
69
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>
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module NanocRedirector
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.1'.freeze
3
3
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_runtime_dependency 'nanoc', '~> 4.9.0'
20
+ spec.add_runtime_dependency 'nanoc', '~> 4.9'
21
21
 
22
22
  spec.add_development_dependency 'rake'
23
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.3.0
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: 2018-06-02 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.9.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.9.0
26
+ version: '4.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -103,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.6.12
106
+ rubygems_version: 3.1.2
108
107
  signing_key:
109
108
  specification_version: 4
110
109
  summary: '["Allows", "you", "to", "generate", "redirects", "to", "and", "from", "an",