History

Add trailing slash redirections

Fixes #13.

Thibaut committed 13 years ago

Commit dec2f5a1 parent 5ed77221 file · +12 −5Browse files

Unified · Split

lib/app.rb+12−5
@@ -118,15 +118,22 @@ class App < Sinatra::Application · 117 unmodified lines
118118 end
119119 end
120120
121− get %r{\A/(.+?)(?=\-|/)} do |doc|
122− return 404 unless @doc = settings.docs[doc]
123− erb :other
124− end
125−
126121 get '/ping' do
127122 200
128123 end
129124
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+
130137 not_found do
131138 send_file File.join(settings.public_folder, '404.html'), status: status
132139 end