History

Fix ordering of versioned docs in sidebar and search

Thibaut Courouble committed 9 years ago

Commit ecb56f11 parent 98a6eb51 file · +11 −3Browse files

Unified · Split

assets/javascripts/collections/docs.coffee+11−3
@@ -4,11 +4,19 @@ class app.collections.Docs extends app.Collection · 3 unmodified lines
4 findBySlug: (slug) ->4 findBySlug: (slug) ->
5 @findBy('slug', slug) or @findBy('slug_without_version', slug)5 @findBy('slug', slug) or @findBy('slug_without_version', slug)
6 6
7 NORMALIZE_VERSION_RGX = /\.(\d)$/
8 NORMALIZE_VERSION_SUB = '.0$1'
7 sort: ->9 sort: ->
8 @models.sort (a, b) ->10 @models.sort (a, b) ->
9 a = a.name.toLowerCase()11 if a.name is b.name
10 b = b.name.toLowerCase()12 if not a.version or a.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB) > b.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB)
11 if a < b then -1 else if a > b then 1 else 013 -1
14 else
15 1
16 else if a.name.toLowerCase() > b.name.toLowerCase()
17 1
18 else
19 -1
12 20
13 # Load models concurrently.21 # Load models concurrently.
14 # It's not pretty but I didn't want to import a promise library only for this.22 # It's not pretty but I didn't want to import a promise library only for this.