# 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}#{request.fullpath[('/latest'.length)..]}") 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