Browse Source

Fix and simplify doc route

Thibaut 11 years ago
parent
commit
9ec670c7d8
1 changed files with 4 additions and 4 deletions
  1. 4 4
      lib/app.rb

+ 4 - 4
lib/app.rb

@@ -161,13 +161,13 @@ class App < Sinatra::Application
     redirect 'http://www.reddit.com/submit?url=http%3A%2F%2Fdevdocs.io&title=All-in-one%2C%20quickly%20searchable%20API%20docs&resubmit=true'
   end
 
-  get %r{\A/(\w+)(\-[\w\-]+)?(/)?(.+)?\z} do |doc, type, slash, rest|
+  get %r{\A/(\w+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest|
     return 404 unless @doc = settings.docs[doc]
 
-    if !rest && !slash
+    if rest.nil?
       redirect "/#{doc}#{type}/"
-    elsif rest && rest.end_with?('/')
-      redirect "#{doc}#{type}#{slash}#{rest[0...-1]}"
+    elsif rest.length > 1 && rest.end_with?('/')
+      redirect "/#{doc}#{type}#{rest[0...-1]}"
     else
       erb :other
     end