Skip to content

Commit

Permalink
Try sorting versions
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Aug 27, 2023
1 parent 4d5a874 commit 3698f6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,26 @@ def github_url
end

def current_branch
current_project.versions.find { |version| version[:value] == current_version }[:branch]
versions[:branch]
end

def versions
@versions ||=
begin
vs = current_project.versions.find { |version| version[:value] == current_version }.sort_by { |version|
if version.match?(/[\d\.]+/)
[1, *version.split('.').map(&:to_i)]
else
[0, version]
end
}.reverse

if vs.size > 2
[vs[0], vs[-1], *vs[1...-1]]
else
vs
end
end
end

def nav
Expand Down Expand Up @@ -306,7 +325,7 @@ def gem_name
end

def set_version(url, new_version)
return url unless current_project.versions.empty?
return url unless versions.empty?

version = extract_version(url)

Expand Down
2 changes: 1 addition & 1 deletion source/partials/_version_switcher.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
h3.sidebar__version
'Version:
select#sidebar__version-switcher
- current_project.versions.each do |version|
- versions.each do |version|
- label = version[:value]
- value = "/gems/#{current_project}/#{label}"
option value=value selected=("selected" if current_version.eql?(label))
Expand Down

0 comments on commit 3698f6b

Please sign in to comment.