Skip to content

Commit

Permalink
fix(docs): sorting versions in docs header (resolve #660)
Browse files Browse the repository at this point in the history
  • Loading branch information
epaminond committed Jun 21, 2018
1 parent 91dfd92 commit 6d40e38
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions docs/_assets/js/versions.js.es6
@@ -1,13 +1,32 @@
import * as $ from 'jquery'

const sortVersions = arr =>
arr
.map(a =>
a
.split('.')
.map(n => (isNaN(n) ? n : +n + 100000))
.join('.')
)
.sort()
.map(a =>
a
.split('.')
.map(n => (isNaN(n) ? n : +n - 100000))
.join('.')
)

function update() {
jQuery.getJSON('https://s3.amazonaws.com/botpress-docs/versions.json', function(data) {
$('#dropdownVersion + .dropdown-menu').empty()
const current = $('.navbar-versions-label').text()
data.sort().reverse().forEach(version => {
const activeCls = current === version ? ' active' : ''
$('#dropdownVersion + .dropdown-menu').append(`<a href="/docs/${version}" class="dropdown-item ${activeCls}">${version}</a>`)
})
$('#dropdownVersion + .dropdown-menu').html(
sortVersions(data)
.reverse()
.map(version => {
const activeCls = current === version ? ' active' : ''
return `<a href="/docs/${version}" class="dropdown-item ${activeCls}">${version}</a>`
})
)
})
}

Expand Down

0 comments on commit 6d40e38

Please sign in to comment.