Fixes #13.
Unified · Split
| @@ -118,15 +118,22 @@ class App < Sinatra::Application · 117 unmodified lines | |||
| 118 | end | 118 | end |
| 119 | end | 119 | end |
| 120 | 120 | ||
| 121 | get %r{\A/(.+?)(?=\-|/)} do |doc| | ||
| 122 | return 404 unless @doc = settings.docs[doc] | ||
| 123 | erb :other | ||
| 124 | end | ||
| 125 | |||
| 126 | get '/ping' do | 121 | get '/ping' do |
| 127 | 200 | 122 | 200 |
| 128 | end | 123 | end |
| 129 | 124 | ||
| 125 | get %r{\A/(\w+)(\-[\w\-]+)?(/)?(.+)?\z} do |doc, type, slash, rest| | ||
| 126 | return 404 unless @doc = settings.docs[doc] | ||
| 127 | |||
| 128 | if !rest && !slash | ||
| 129 | redirect "/#{doc}#{type}/" | ||
| 130 | elsif rest && rest.end_with?('/') | ||
| 131 | redirect "#{doc}#{type}#{slash}#{rest[0...-1]}" | ||
| 132 | else | ||
| 133 | erb :other | ||
| 134 | end | ||
| 135 | end | ||
| 136 | |||
| 130 | not_found do | 137 | not_found do |
| 131 | send_file File.join(settings.public_folder, '404.html'), status: status | 138 | send_file File.join(settings.public_folder, '404.html'), status: status |
| 132 | end | 139 | end |