yarrow 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yarrow/server.rb +33 -0
- data/lib/yarrow/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95557525739422605b678c010cad87b67b3e01e1382a9a7b65b032cd7ccfdceb
|
4
|
+
data.tar.gz: 90bd1dfc26fc41c8aee75586f760b05d0b122fe1868cb061b29a7344a0627165
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb128a24a28ad30bef33b1db635e952a3c4930d75094ce5434fe3cbeb890644fb1704a4d619144a915b0e71cc41c333d8ce3186fb2b8d5e3eee334bb68aa8b9d
|
7
|
+
data.tar.gz: ee6767873b4afa6270b7a8e21dc096eac492624d47063e7d742d81cdc3e5b2608595f8ce945f299e036cb19245b980df56322a768d225731f16275088bd54dd3
|
data/lib/yarrow/server.rb
CHANGED
@@ -41,6 +41,38 @@ module Yarrow
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
# Rack Middleware for rewriting extensionless URLs
|
45
|
+
#
|
46
|
+
# See surge.sh rewrite rules, that seems like a good starting point for
|
47
|
+
# generic behaviour that can be put in place without needing large amounts
|
48
|
+
# of config each time.
|
49
|
+
class ResourceRewriter
|
50
|
+
def initialize(app)
|
51
|
+
# No options enabled
|
52
|
+
@app = app
|
53
|
+
end
|
54
|
+
|
55
|
+
def should_try_rewrite(path)
|
56
|
+
!request_path.ends_with(".html") || !request_path.ends_with("/")
|
57
|
+
end
|
58
|
+
|
59
|
+
def call(env)
|
60
|
+
# TODO: document and disambiguate usage of Rack::Request vs env PATH_INFO
|
61
|
+
request_path = env["PATH_INFO"]
|
62
|
+
|
63
|
+
try_response = @app.call(env)
|
64
|
+
|
65
|
+
# TODO: reproduces default Netlify behaviour—should be a 301 instead?
|
66
|
+
if try_response[0] == 404 and should_try_rewrite(request_path)
|
67
|
+
try_response = @app.call(env.merge!({
|
68
|
+
"PATH_INFO" => "#{request_path}.html"
|
69
|
+
}))
|
70
|
+
end
|
71
|
+
|
72
|
+
try_response
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
44
76
|
##
|
45
77
|
# Builds a Rack application to serve files in the output directory.
|
46
78
|
#
|
@@ -58,6 +90,7 @@ module Yarrow
|
|
58
90
|
app.use(middleware)
|
59
91
|
end
|
60
92
|
|
93
|
+
app.use(ResourceRewriter)
|
61
94
|
app.use(DirectoryIndex, root: docroot, index: default_index)
|
62
95
|
|
63
96
|
app_args = [docroot, {}].tap { |args| args.push(default_type) if default_type }
|
data/lib/yarrow/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yarrow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rickerby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mementus
|