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
161 redirect 'http://www.reddit.com/submit?url=http%3A%2F%2Fdevdocs.io&title=All-in-one%2C%20quickly%20searchable%20API%20docs&resubmit=true'161 redirect 'http://www.reddit.com/submit?url=http%3A%2F%2Fdevdocs.io&title=All-in-one%2C%20quickly%20searchable%20API%20docs&resubmit=true'
162 end162 end
163 163
164 get %r{\A/(\w+)(\-[\w\-]+)?(/)?(.+)?\z} do |doc, type, slash, rest|164 get %r{\A/(\w+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest|
165 return 404 unless @doc = settings.docs[doc]165 return 404 unless @doc = settings.docs[doc]
166 166
167 if !rest && !slash167 if rest.nil?
168 redirect "/#{doc}#{type}/"168 redirect "/#{doc}#{type}/"
169 elsif rest && rest.end_with?('/')169 elsif rest.length > 1 && rest.end_with?('/')
170 redirect "#{doc}#{type}#{slash}#{rest[0...-1]}"170 redirect "/#{doc}#{type}#{rest[0...-1]}"
171 else171 else
172 erb :other172 erb :other
173 end173 end