Skip to content

Detect site version from metatag

Sarah German requested to merge sarahg/version-metatag into main

What does this MR do and why?

The Versions menu needs to know the currently-viewed site version. The first iteration of the component determined this from the URL (e.g, docs.gitlab.com/15.2 = 15.2).

Turns out it's simpler to get the site version at build time from the CI branch/tag, and we already had a few Ruby functions to help with this.

This MR:

  • moves the logic from Vue to the backend
  • passes the version to the frontend via a new metatag
  • also uses the new site_version method in the existing docsearch:version metatag, since it also needs to know the version and had its own logic for this

Why:

  • This will make it easier to use the same Versions menu component on the future archives site.
  • This is safer for self-hosted docs installs where we can't guarantee that the URL paths will match ours (e.g, hosting in a subdirectory, which probably breaks in other ways currently, but someday might be something we want to allow for)
  • I'd started this refactor in !3174 (merged) but decided to split off this piece for the sake of smaller MRs.

Related issue: #1290 (closed)

Screenshots, screen recordings, or links to review app

image

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Configure a local GitLab Docs environment: https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/doc/setup.md.
  2. Check the HTML source for this tag: <meta name="gitlab-docs-version" content="15.5">
  3. Verify the docsearch:version metatag shows the same value in the content attribute.
  4. Verify the Versions drop-down shows this same version as the default value.

Merge request acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Sarah German

Merge request reports