Websites/app/controllers/oceanic_ws/docs_controller.rb
2024-05-02 22:04:43 -05:00

40 lines
942 B
Ruby

# frozen_string_literal: true
module OceanicWs
GITHUB_REPO = "https://github.com/OceanicJS/Oceanic"
class DocsController < OceanicWs::ApplicationController
include ::ApplicationController::CommonAssetRoutes
def index
@versions = versions
end
def json
render(json: {
versions: versions,
})
end
def latest
redirect_to("/#{latest_version}#{params[:other]}")
end
private
def versions
ver = Cache.redis.smembers("oceanic:versions")
branches = ver.filter { |v| !v.start_with?("v") }
tags = ver.filter { |v| v.start_with?("v") }
{
branches: branches.sort,
tags: tags.sort_by { |v| Gem::Version.new(v[1..]) },
}
end
def latest_version
`git ls-remote --tags #{GITHUB_REPO}`.split("\n").map { |line| line.split("\t")[-1].gsub("refs/tags/", "") }.max_by { |ver| Gem::Version.new(ver[1..]) }
end
end
end