Bläddra i källkod

Fix ordering of versioned docs in sidebar and search

Thibaut Courouble 8 år sedan
förälder
incheckning
ecb56f1e97
1 ändrade filer med 11 tillägg och 3 borttagningar
  1. 11 3
      assets/javascripts/collections/docs.coffee

+ 11 - 3
assets/javascripts/collections/docs.coffee

@@ -4,11 +4,19 @@ class app.collections.Docs extends app.Collection
   findBySlug: (slug) ->
     @findBy('slug', slug) or @findBy('slug_without_version', slug)
 
+  NORMALIZE_VERSION_RGX = /\.(\d)$/
+  NORMALIZE_VERSION_SUB = '.0$1'
   sort: ->
     @models.sort (a, b) ->
-      a = a.name.toLowerCase()
-      b = b.name.toLowerCase()
-      if a < b then -1 else if a > b then 1 else 0
+      if a.name is b.name
+        if not a.version or a.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB) > b.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB)
+          -1
+        else
+          1
+      else if a.name.toLowerCase() > b.name.toLowerCase()
+        1
+      else
+        -1
 
   # Load models concurrently.
   # It's not pretty but I didn't want to import a promise library only for this.