mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
Fix ordering of versioned docs in sidebar and search
This commit is contained in:
parent
98a6eb58cb
commit
ecb56f1e97
1 changed files with 11 additions and 3 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue