From ecb56f1e97e0835f39b1b497cb176e5bb45ee085 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 16 Apr 2017 12:45:40 -0400 Subject: [PATCH] Fix ordering of versioned docs in sidebar and search --- assets/javascripts/collections/docs.coffee | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/collections/docs.coffee b/assets/javascripts/collections/docs.coffee index c4b2e368..d76e0f07 100644 --- a/assets/javascripts/collections/docs.coffee +++ b/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.