diff options
author | Sarah German <sgerman@gitlab.com> | 2022-10-19 19:32:34 +0300 |
---|---|---|
committer | Sarah German <sgerman@gitlab.com> | 2022-10-19 19:32:34 +0300 |
commit | 9acf3772451af14e4fa0372f4fe1a314822de5cc (patch) | |
tree | ac81078dd7f3a6370d422d7838250a41ec8dcb4a /lib | |
parent | a896ec2495a86914d410680df5a953bf1b530c93 (diff) |
Set site version in metatag
Diffstat (limited to 'lib')
-rw-r--r-- | lib/helpers/versions.rb | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/lib/helpers/versions.rb b/lib/helpers/versions.rb index 70fa6a67..90b5739b 100644 --- a/lib/helpers/versions.rb +++ b/lib/helpers/versions.rb @@ -15,13 +15,49 @@ module Nanoc::Helpers end # - # Check if the current version is the latest. + # Get online versions from the JSON file. # - def latest? + def get_versions file = File.read('./content/versions.json') parsed = JSON.parse(file) - latest_version = parsed[0]['current'] - ENV['CI_COMMIT_REF_NAME'] == ENV['CI_DEFAULT_BRANCH'] || ENV['CI_COMMIT_REF_NAME'] == latest_version + parsed[0] + end + + # + # Returns the site version using the branch or tag from the CI build. + # + def site_version + if !ENV['CI_COMMIT_REF_NAME'].nil? && stable_version?(ENV['CI_COMMIT_REF_NAME']) + ENV['CI_COMMIT_REF_NAME'] + else + # If this wasn't built on CI, this is a local site that can default to the pre-release version. + get_versions["next"] + end + end + + # + # Returns the site version for Algolia DocSearch. + # + # For DocSearch, we need to pass "main" instead of a version number + # in the case of the pre-release site. + # + def docsearch_version + if get_versions["next"] == site_version + ENV['CI_DEFAULT_BRANCH'] + else + site_version + end + end + + # + # Check if this site version is the latest. + # + # We consider two versions to be "latest": + # 1) The main branch (CI_DEFAULT_BRANCH), which are pre-release docs for the next version. + # 2) The most recent stable release, which is "current" in versions.json. + # + def latest? + ENV['CI_COMMIT_REF_NAME'] == ENV['CI_DEFAULT_BRANCH'] || ENV['CI_COMMIT_REF_NAME'] == get_versions["current"] end # |