Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: versioned docs dropdown #3226

Merged
merged 4 commits into from
Jan 15, 2025
Merged

Conversation

fykaa
Copy link
Contributor

@fykaa fykaa commented Jan 8, 2025

closes #3171

This pull request implements a version dropdown in the Docusaurus configuration (docusaurus.config.js) to support versioned documentation. The following changes were made:

  1. Added version dropdown to Navbar:

    • Updated docusaurus.config.js to include a docsVersionDropdown in the navbar letting users to switch between different doc versions
  2. Versioned doc creation:

    • Ran npm run docusaurus docs:version <version> for each version (1.0, 1.1) to generate versioned docs.
    • Updated the versions.json file to include the new versions.

Next Steps: update release procedure

  • To maintain the latest doc with each minor/ patch update, the process of running npm run docusaurus docs:version <version> should be added to the release procedures
image

@fykaa fykaa self-assigned this Jan 8, 2025
@fykaa fykaa requested review from a team as code owners January 8, 2025 12:11
Copy link

netlify bot commented Jan 8, 2025

Deploy Preview for docs-kargo-io ready!

Name Link
🔨 Latest commit 9cad25a
🔍 Latest deploy log https://app.netlify.com/sites/docs-kargo-io/deploys/6786caa63847a800083cc3f7
😎 Deploy Preview https://deploy-preview-3226.docs.kargo.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.05%. Comparing base (32291db) to head (9cad25a).
Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3226   +/-   ##
=======================================
  Coverage   52.05%   52.05%           
=======================================
  Files         295      295           
  Lines       26695    26695           
=======================================
  Hits        13895    13895           
  Misses      12041    12041           
  Partials      759      759           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fykaa fykaa force-pushed the feat/versioned-docs-dropdown branch from 605f72b to fb61a6b Compare January 8, 2025 12:29
@krancour
Copy link
Member

krancour commented Jan 8, 2025

I see that this is based on what @rpelczar had linked you to, but this process is frankly much too onerous and prone to human error. It doesn't satisfy this requirement that I included in #3171:

Each time we have a minor release, that release's branch becomes the branch that the main docs are served from. Older release branches move to subdomains like release-1-1.docs.kargo.io

We need to add a drop down to the header so that docs for older releases can be selected. It just needs to redirect readers to the correct subdomain.

This would introduce no new complications or process changes.

Edit: I had been under the impression that Docusaurus had built-in support for that approach, but it appears not. It's possible that a plugin exists for this. If not, I think this would be a very easy plugin to write.

Copy link
Member

@krancour krancour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

@krancour
Copy link
Member

krancour commented Jan 9, 2025

Older release branches move to subdomains like release-1-1.docs.kargo.io

It's possible that a plugin exists for this. If not, I think this would be a very easy plugin to write.

I looked for one and didn't find one. It doesn't mean it's not our there somewhere.

Rolling our own is really not too bad. It could probably be as simple as:

  1. Look at window.location.hostname to determine what version the user is currently viewing. If it's docs.kargo.io, they're viewing current docs. If it is a release docs subdomain, parse it to learn the major and minor revision numbers. This gives you everything you need to make something like a very slim banner at the top of the page that says something like "You're viewing documentation for v1.1.x". For any other value of window.location.hostname, version number is "unknown".

  2. You can position a dropdown for "Other Versions" to the right of it. To find the version numbers, you can hit https://api.github.com/repos/akuity/kargo/branches to get the names of all branches. Use a regex to identify all GA release branches and cache it for some short period of time in the browser's local storage. Use that to populate the dropdown.

After this is working to our satisfaction in main, we'd backport it to release-1.1 and release-1.0.

@fykaa
Copy link
Contributor Author

fykaa commented Jan 9, 2025

I see that this is based on what @rpelczar had linked you to, but this process is frankly much too onerous and prone to human error. It doesn't satisfy this requirement that I included in #3171
This would introduce no new complications or process changes.

I do not have access to Netlify, which made it tough for me to understand how the separate release doc is being built and deployed to their respective subdomains. I’ve noticed that this pattern of subdomain-based doc only works for some versions, which reinforces the inconsistencies in the deployment process. like, while https://release-1-1.docs.kargo.io works, https://release-1-0.docs.kargo.io does not. seems not every version has been built and deployed to its subdomain, and I may need access to Netlify to run the build process for each missing versions. Hence, i opted to work directly with Rafal’s suggestion, it simplifies the process by treating each release as a separate static site with its subdomain.

I will start working on the custom plugin that could detect the current doc version, fetch available versions from github and provide a dropdown (with doc redirection) for users to switch between versions

@krancour
Copy link
Member

krancour commented Jan 9, 2025

@fykaa don't get caught up in building or deploying docs.

Please just assume that for every branch release-x-y with x > 1, the subdomain will exist. If one of them does not, I can fix it.

The reason that the 1.0 docs don't currently exist has to do with the migration we did from docs.kargo.akuity.io to docs.kargo.io. iirc, there were some changes related to the domain change that didn't get backported that far, so I just didn't deploy them. I'll investigate and fix it.

@krancour
Copy link
Member

krancour commented Jan 9, 2025

iirc, there were some changes related to the domain change that didn't get backported that far, so I just didn't deploy them

It was dumber than that. Something just got stuck on their end during the migration.

Should be all set now.

All of the following exist:

  • docs.kargo.io (currently published from release-1.1)
  • release-1-1.docs.kargo.io (published from release-1.1)
  • release-1-0.docs.kargo.io (published from release-1.0)
  • main.docs.kargo.io ("edge" docs, published from main)

@fykaa fykaa force-pushed the feat/versioned-docs-dropdown branch 11 times, most recently from 76e88ae to 8f4b86e Compare January 13, 2025 14:57
const fetchVersions = async () => {
try {
console.log("Before fetching versions")
const response = await fetch(githubApiUrl);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you look in local storage instead of unconditionally making this request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a valid point, and I did consider using local storage caching. but in this case I opted not to because the fetchVersions function is only called once when the dropdown component is initially rendered. since we’re only making a single API call to fetch the data, which is then reused on subsequent renders, I felt caching might not be strictly necessary. the network tab also shows that the API call isn't repeated.

image

But I’m open to revisiting this if it turns out we need to optimize further by caching the branches for, say 30 minute?. Currently, API calls are only made when the page is Refreshed.

@fykaa fykaa force-pushed the feat/versioned-docs-dropdown branch from f489cc5 to fa6a2f6 Compare January 14, 2025 01:21
@fykaa fykaa force-pushed the feat/versioned-docs-dropdown branch 3 times, most recently from 8e94c3d to 91c4022 Compare January 14, 2025 14:19
Signed-off-by: Faeka Ansari <faeka6@gmail.com>

clean plugin code

Signed-off-by: Faeka Ansari <faeka6@gmail.com>

make version picker a component instead of a plugin

Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>

remove accidental/unnecessary comma

Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>

add caching and filtering logic

Signed-off-by: Faeka Ansari <faeka6@gmail.com>

optimise component

Signed-off-by: Faeka Ansari <faeka6@gmail.com>

address review

Signed-off-by: Faeka Ansari <faeka6@gmail.com>

dropdown title sync

Signed-off-by: Faeka Ansari <faeka6@gmail.com>

styling dropdown

Signed-off-by: Faeka Ansari <faeka6@gmail.com>

minor cleanup

Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
@fykaa fykaa force-pushed the feat/versioned-docs-dropdown branch from cd8408d to 956a43b Compare January 14, 2025 19:30
Signed-off-by: Faeka Ansari <faeka6@gmail.com>
@krancour krancour added this to the Live Docs milestone Jan 14, 2025
@krancour krancour added this pull request to the merge queue Jan 15, 2025
Merged via the queue into akuity:main with commit 0800734 Jan 15, 2025
24 checks passed
github-actions bot pushed a commit that referenced this pull request Jan 15, 2025
Signed-off-by: Faeka Ansari <faeka6@gmail.com>
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
(cherry picked from commit 0800734)
@akuitybot
Copy link

Successfully created backport PR for release-1.0:

github-actions bot pushed a commit that referenced this pull request Jan 15, 2025
Signed-off-by: Faeka Ansari <faeka6@gmail.com>
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
(cherry picked from commit 0800734)
@akuitybot
Copy link

Successfully created backport PR for release-1.1:

github-actions bot pushed a commit that referenced this pull request Jan 15, 2025
Signed-off-by: Faeka Ansari <faeka6@gmail.com>
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
(cherry picked from commit 0800734)
@akuitybot
Copy link

Successfully created backport PR for release-1.2:

fykaa added a commit to fykaa/kargo that referenced this pull request Jan 16, 2025
Signed-off-by: Faeka Ansari <faeka6@gmail.com>
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
krancour pushed a commit to krancour/kargo that referenced this pull request Jan 17, 2025
Signed-off-by: Faeka Ansari <faeka6@gmail.com>
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
krancour pushed a commit to krancour/kargo that referenced this pull request Jan 17, 2025
Signed-off-by: Faeka Ansari <faeka6@gmail.com>
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs: make multiple versions available from a drop down in the header
4 participants