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
44 findBySlug: (slug) ->
55 @findBy('slug', slug) or @findBy('slug_without_version', slug)
66
7+ NORMALIZE_VERSION_RGX = /\.(\d)$/
8+ NORMALIZE_VERSION_SUB = '.0$1'
79 sort: ->
810 @models.sort (a, b) ->
9− a = a.name.toLowerCase()
10− b = b.name.toLowerCase()
11− if a < b then -1 else if a > b then 1 else 0
11+ if a.name is b.name
12+ if not a.version or a.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB) > b.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB)
13+ -1
14+ else
15+ 1
16+ else if a.name.toLowerCase() > b.name.toLowerCase()
17+ 1
18+ else
19+ -1
1220
1321 # Load models concurrently.
1422 # It's not pretty but I didn't want to import a promise library only for this.