yarrow 0.7.0 → 0.7.1

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
  SHA256:
3
- metadata.gz: ff50d9afd65a1ab1f8fd668c7db4acc0ceacabc095bccd65b384c2b47f8e7eb0
4
- data.tar.gz: cb0f022b2163753231e701b98e1da2da2ee963b61cd635031f4128b7ce6034be
3
+ metadata.gz: 95557525739422605b678c010cad87b67b3e01e1382a9a7b65b032cd7ccfdceb
4
+ data.tar.gz: 90bd1dfc26fc41c8aee75586f760b05d0b122fe1868cb061b29a7344a0627165
5
5
  SHA512:
6
- metadata.gz: 93f4705d0556fee8b22ea19ca0a42a272a85ec52b7ced0ab408072147b27789173465c5ea0bcb4f95787da01499499f16d57971b325de5af3bb2d0a1b1f8ccf4
7
- data.tar.gz: 59df4131a12acd9bd7ea051c1e308d17b99cd391e63e07b5582340f8bcd7e2be1216b98a32e2b4a86d8b88278dd11505d7d0b689997d249ca30057222ca4cc4e
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 }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Yarrow
3
3
  APP_NAME = 'Yarrow'
4
- VERSION = '0.7.0'
4
+ VERSION = '0.7.1'
5
5
  end
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.0
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-30 00:00:00.000000000 Z
11
+ date: 2021-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mementus