nanoc-redirector 0.3.2 → 0.4.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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +8 -1
- data/lib/nanoc-redirector.rb +9 -5
- data/lib/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7abeee55bb8736eaa1e726e905368b2ebbf409d435a2e54a3d3a3f8e344f0dd
|
4
|
+
data.tar.gz: b334d24cce12bf8a67e259167b59b4ec4bc9333b3de69a6975ffacf4e5600cf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d6aa2684637c4bf7cdf9179d0e93995697d20f3eb0c923b7ab183dad35257a34749b1a9e15f93d966d3b5328937e02490a8da755e97252be6fa541edd8a316b
|
7
|
+
data.tar.gz: d14ea79599dd76c15bdb7af2898edde5f7e594e5cfe7d5ede6a8c99bbdd559133062a64117e6c8be08286ea3ce499642a3b8c4bd30f105121917c16f60f3ad8a
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -61,11 +61,18 @@ require 'nanoc-redirector'
|
|
61
61
|
|
62
62
|
postprocess do
|
63
63
|
@items.each do |item|
|
64
|
-
NanocRedirector::RedirectFrom.process(item, 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:
|
data/lib/nanoc-redirector.rb
CHANGED
@@ -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(
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
data/lib/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.0
|
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: 2019-
|
11
|
+
date: 2019-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nanoc
|
@@ -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
|
-
|
107
|
-
rubygems_version: 2.7.6
|
106
|
+
rubygems_version: 3.0.6
|
108
107
|
signing_key:
|
109
108
|
specification_version: 4
|
110
109
|
summary: '["Allows", "you", "to", "generate", "redirects", "to", "and", "from", "an",
|