2024-05-03 03:04:43 +00:00
|
|
|
# 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
|
2024-05-09 02:25:36 +00:00
|
|
|
redirect_to("/#{latest_version}#{request.fullpath[('/latest'.length)..]}")
|
2024-05-03 03:04:43 +00:00
|
|
|
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
|