middleman-redirects 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/middleman/redirects.rb +20 -11
- data/lib/middleman/redirects/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22d25b0d40674b666d6c1ce99606bbbe1d5f69b1
|
4
|
+
data.tar.gz: a701875e1f23b7a2c352795320832869b47040e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 391822e486f5a15a861e314d5b0b864861264bae5ad2873f4fdb16d83a44b74def6e6ede46fba6e1816991e2b2fd7750d31a6c130bafc4b3a0e87f34917cae34
|
7
|
+
data.tar.gz: 5ad22b77be206c310e953d511f4fac6ef364342accade4a485af74e855742f581bc7f53fac78f3bea893578627229fe1d6509844586c1e82c28d563cda6bd684
|
data/README.md
CHANGED
@@ -5,10 +5,15 @@ Makes middleman parse `REDIRECTS` files during development and perform the redir
|
|
5
5
|
```
|
6
6
|
# REDIRECTS
|
7
7
|
#
|
8
|
-
# Syntax:
|
8
|
+
# Syntax for "Found" (302) redirects:
|
9
9
|
#
|
10
10
|
# <source> <destination>
|
11
11
|
/github https://github.com/PSPDFKit-labs/middleman-redirects
|
12
|
+
|
13
|
+
# Syntax for "Moved Permanently" (301) redirects:
|
14
|
+
#
|
15
|
+
# <source> <destination> permanent
|
16
|
+
/github https://github.com/PSPDFKit-labs/middleman-redirects permanent
|
12
17
|
```
|
13
18
|
|
14
19
|
## Development
|
data/lib/middleman/redirects.rb
CHANGED
@@ -23,11 +23,11 @@ module Middleman
|
|
23
23
|
|
24
24
|
def call(env)
|
25
25
|
source = env['PATH_INFO']
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
destination, redirect_code = ::Middleman::Redirects.redirects[source]
|
27
|
+
|
28
|
+
return @app.call(env) unless destination
|
29
|
+
|
30
|
+
[redirect_code, {"Location" => destination}, []]
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -53,28 +53,37 @@ module Middleman
|
|
53
53
|
|
54
54
|
def self.read_redirects
|
55
55
|
@mtime = self.redirects_file_path.mtime
|
56
|
-
@redirects =
|
56
|
+
@redirects = {}
|
57
|
+
|
58
|
+
self.redirects_file_path.each_line.map do |line|
|
57
59
|
next if line =~ /^#/ # ignore comments
|
58
60
|
next if line.empty?
|
59
61
|
next if BLANK_RE === line
|
60
62
|
|
61
|
-
|
63
|
+
parts = line.split
|
64
|
+
source = URI.parse(parts[0])
|
65
|
+
destination = URI.parse(parts[1])
|
66
|
+
redirect_code = if parts[2] =~ /permanent/
|
67
|
+
301
|
68
|
+
else
|
69
|
+
302
|
70
|
+
end
|
62
71
|
|
63
72
|
# don't allow a single / or * as source
|
64
73
|
next if source.path == '/'
|
65
74
|
next if source.path == '.*'
|
66
75
|
next if source.path == '*' # invalid
|
67
76
|
|
68
|
-
[source.to_s
|
69
|
-
end
|
77
|
+
@redirects[source.to_s] = [destination.to_s, redirect_code]
|
78
|
+
end
|
70
79
|
|
71
80
|
autogenerated_redirects = {}
|
72
81
|
|
73
82
|
# duplicate redirect so it also matches URIs with a trailing slash
|
74
83
|
if self.match_trailing_slashes
|
75
|
-
@redirects.each do |source,
|
84
|
+
@redirects.each do |source, destination_and_code|
|
76
85
|
next if source[-1] == '/'
|
77
|
-
autogenerated_redirects["#{source}/"] =
|
86
|
+
autogenerated_redirects["#{source}/"] = destination_and_code
|
78
87
|
end
|
79
88
|
end
|
80
89
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-redirects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Schurrer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|