middleman-redirects 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e6d8e9f845a8cc57f8f303557f82600e52f4ed8
4
- data.tar.gz: aaa494ed37ee623e3fbe37e598453d0c67c95b4c
3
+ metadata.gz: 22d25b0d40674b666d6c1ce99606bbbe1d5f69b1
4
+ data.tar.gz: a701875e1f23b7a2c352795320832869b47040e1
5
5
  SHA512:
6
- metadata.gz: be1178019d46ea3c9d65196686c9db76cd17c2cfdf7111bb509ec960a2ede0019259dee5ff3954ca155ad7ee29b42107e5296edb895b142ecc120d5e007c60ee
7
- data.tar.gz: 375a9ef39314dbb9c7612467df2823a8f334a79a50a36eb74534fd5fdeaae5f6bfc5d774488a5e23c84f461831dcc6cd2db90216c480f78162cb61aae2916309
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
@@ -23,11 +23,11 @@ module Middleman
23
23
 
24
24
  def call(env)
25
25
  source = env['PATH_INFO']
26
- if destination = ::Middleman::Redirects.redirects[source]
27
- [302, {"Location" => destination}, []]
28
- else
29
- @app.call(env)
30
- end
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 = Hash[self.redirects_file_path.each_line.map do |line|
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
- source, destination = line.split.map { |s| URI.parse(s) }
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, destination.to_s]
69
- end.compact]
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, destination|
84
+ @redirects.each do |source, destination_and_code|
76
85
  next if source[-1] == '/'
77
- autogenerated_redirects["#{source}/"] = destination
86
+ autogenerated_redirects["#{source}/"] = destination_and_code
78
87
  end
79
88
  end
80
89
 
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Redirects
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
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.2.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: 2017-08-10 00:00:00.000000000 Z
11
+ date: 2019-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler