Fix ordering of versioned docs in sidebar and search

pull/385/merge
Thibaut Courouble 8 years ago
parent 98a6eb58cb
commit ecb56f1e97

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

Loading…
Cancel
Save