History

Fix and simplify doc route

Thibaut committed 11 years ago

Commit 9ec670c1 parent d0deb1b1 file · +4 −4Browse files

Unified · Split

lib/app.rb+4−4
@@ -161,13 +161,13 @@ class App < Sinatra::Application · 160 unmodified lines
161161 redirect 'http://www.reddit.com/submit?url=http%3A%2F%2Fdevdocs.io&title=All-in-one%2C%20quickly%20searchable%20API%20docs&resubmit=true'
162162 end
163163
164− get %r{\A/(\w+)(\-[\w\-]+)?(/)?(.+)?\z} do |doc, type, slash, rest|
164+ get %r{\A/(\w+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest|
165165 return 404 unless @doc = settings.docs[doc]
166166
167− if !rest && !slash
167+ if rest.nil?
168168 redirect "/#{doc}#{type}/"
169− elsif rest && rest.end_with?('/')
170− redirect "#{doc}#{type}#{slash}#{rest[0...-1]}"
169+ elsif rest.length > 1 && rest.end_with?('/')
170+ redirect "/#{doc}#{type}#{rest[0...-1]}"
171171 else
172172 erb :other
173173 end