Refactor path handling for self-hosted archive sites
What does this MR do and why?
Refactors how we determine if a site is an archived version or not. Our previous logic incorrectly assumed that archived versions always run on archives.docs.gitlab.com
, which neglected to account for self-hosted docs sites.
Self-hosted docs sites are likely run in air-gapped/offline environments, so we also needed to use a method for determining archive status that works offline (so, no remote querying of versions.json or archive_versions.json).
This refactor addresses a few issues:
- Lunr search result links did not include the version prefix on self-hosted docs instances.
- Links to the latest docs from the "archived version" banner were incorrect when viewing a site on
archives.docs.gitlab.com
. The base URL for this link should always bedocs.gitlab.com
. Closes #1755 (closed). - The link on the logo in the top-right corner should point to the version-prefixed site homepage. Closes #1768 (closed).
I've bundled these fixes in the single MR for (hopefully) easier backporting.
Feature table:
Version | versions dropdown menu | "archived version" banner | Search |
---|---|---|---|
Pre-release (16.10) | Shows the same options as docs.gitlab.com. Local links will not work; this is expected since you do not have all the versions available locally. | No banner | Google, non-prefixed result URLs |
Stable (16.9) | Shows the same options as docs.gitlab.com. Local links will not work; this is expected since you do not have all the versions available locally. | No banner | Google, non-prefixed result URLs |
Archive (16.6) | Shows only the active version (16.6) and a link back to docs.gitlab.com/archives. | Banner (interior pages only) | Lunr with prefixed URLs |
Offline archive (16.6, sans wifi) | Shows only the active version (16.6) and a link back to docs.gitlab.com/archives. | Banner (interior pages only) | Lunr with prefixed URLs |
Screenshots, screen recordings, or links to review app
No visual changes. Can't validate these on the review app. See below for testing steps.
How to set up and validate locally
1. Test the pre-release
- Run a fresh compile:
make clean && make view
- Browse the site at http://localhost:3000 and verify version-related features* (see below) work as expected.
Validation:
- Shows the same options as docs.gitlab.com. Local links will not work; this is expected since you do not have all the versions available locally.
- No banner.
- Google search, non-prefixed result URLs.
2. Test the latest stable release
- Stop the server (
CTRL+C
) and set yourself an env var:export VER="16.9"
- Create a "release" version (this runs the same steps as we do through single.Dockerfile):
./scripts/normalize-links.sh public $VER && mkdir $VER && scripts/minify-assets.sh $VER/ public/ && mkdir dest && mv $VER dest/
- Move this into the public directory so we can browse it locally:
mv dest/$VER public
- Run the local server:
bundle exec nanoc view
- Browse the site at http://localhost:3000/16.9 and verify version-related features* work as expected.
Validation:
- Shows the same options as docs.gitlab.com. Local links will not work; this is expected since you do not have all the versions available locally.
- No banner.
- Lunr search with prefixed URLs.
3. Test an online archived release
- Clean up the last test (
rm -rf dest
) and hitCTRL+C
to quit the lastnanoc view
process. - Set a new env var:
export VER="16.6"
- New compile:
make clean && SEARCH_BACKEND="lunr" CI_COMMIT_REF_NAME=$VER make compile
- Create a "release" version (this runs the same steps as we do through single.Dockerfile):
./scripts/normalize-links.sh public $VER && mkdir $VER && scripts/minify-assets.sh $VER/ public/ && mkdir dest && mv $VER dest/
- Move this into the public directory so we can browse it locally:
mv dest/$VER public
- Run the local server:
bundle exec nanoc view
- Browse the site at http://localhost:3000/16.6 and verify version-related features* work as expected.
Validation:
- Shows only the active version (16.6) and a link back to docs.gitlab.com/archives.
- Banner (interior pages only)
- Lunr search with prefixed URLs.
4. Test an offline archived release
Turn off your wifi (
You may need to do a hard refresh or use an incognito window if your browser has cached the banner data from the previous test.
Validation:
- Shows only the active version (16.6) and a link back to docs.gitlab.com/archives.
- Banner (interior pages only)
- Lunr search with prefixed URLs.
5. Test the Docker build
In theory the test case above works the same as it would built through Docker, but it would be helpful to double-check this since I could not get the Docker builds to work locally (#1765 (closed)).
-
docker build -f dockerfiles/single.Dockerfile . --build-arg VER=16.6 --build-arg SEARCH_BACKEND="lunr" --tag docs:16.6
-
Run the site using this image: docker run -it --rm -p 4000:4000 docs:16.6
-
Visit the site http://localhost:4000/16.6
and verify version-related features* work as expected.
Validation:
- Shows only the active version (16.6) and a link back to docs.gitlab.com/archives.
- Banner (interior pages only)
- Lunr search with prefixed URLs.
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.
-
I have evaluated the MR acceptance checklist for this merge request.