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(theme): add versions attribute to docsVersionDropdown navbar item #10852

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

hrumhurum
Copy link

@hrumhurum hrumhurum commented Jan 18, 2025

Motivation

Fix #10833

The docsVersionDropdown navbar item supports a new versions attribute to filter/whitelist displayed versions. Only the provided versions will be displayed.

Example:

{
  type: 'docsVersionDropdown',
  versions: ['1.0.1', '2.1.1']
},

Also gives the ability to override version attributes (for now, only display label) by providing an object.

{
  type: 'docsVersionDropdown',
  versions: {
  '1.0.1': {label: '1.x'},
  '2.1.1': {label: '2.x'},
},

Test Plan

  1. Go to the deploy preview website
  2. Locate the docs version dropdown in the upper part of the website
  3. Click on the dropdown
  4. Notice how the version titles are customized
  5. Notice how the list of versions are customized to display just a subset of versions
  6. Visit Docusaurus documentation preview to take a look at the documentation for new functionality

Test links

Deploy preview: https://gp-temp-docusaurus-app1.netlify.app/eazfuscator.net

@facebook-github-bot
Copy link
Contributor

Hi @hrumhurum!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Copy link

netlify bot commented Jan 18, 2025

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 1f3ec76
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/678e5a7aaaf29f00085cb840
😎 Deploy Preview https://deploy-preview-10852--docusaurus-2.netlify.app
📱 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

github-actions bot commented Jan 18, 2025

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO Report
/ 🔴 39 🟢 98 🟢 96 🟢 100 Report
/docs/installation 🔴 49 🟢 97 🟢 100 🟢 100 Report
/docs/category/getting-started 🟠 72 🟢 100 🟢 100 🟠 86 Report
/blog 🟠 62 🟢 96 🟢 100 🟠 86 Report
/blog/preparing-your-site-for-docusaurus-v3 🔴 46 🟢 92 🟢 100 🟢 100 Report
/blog/tags/release 🟠 63 🟢 96 🟢 100 🟠 86 Report
/blog/tags 🟠 73 🟢 100 🟢 100 🟠 86 Report

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jan 18, 2025
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

The feature works thanks 👍

But I'd like a few things changed

packages/docusaurus-theme-classic/src/options.ts Outdated Show resolved Hide resolved
// that's why we use 'version.label' as a secondary version identifier
// that can be referenced in configuration
const label = version.label;
if (!versionMap.has(label)) versionMap.set(label, version);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not super fan of this logic.
We don't do this kind of thing anywhere else in the codebase so I'd prefer not introduce this here

Copy link
Author

Choose a reason for hiding this comment

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

I am not a fan of that too but it's a workaround for a serious usability omission. Without that logic, a user faces a specifically annoying inconvenience.

Suppose a user wants to restrict the displayed versions to:

versions: ['2024.3','2024.2','2024.1','2023.4']

But without that logic, that aforementioned statement will not work. The user will be forced to specify something hacky like:

versions: ['current','2024.2','2024.1','2023.4']

or even:

versions: ['next','current','2024.1','2023.4']

This is technically ok, but it breaks mental expectations of the user. It can be clearly seen in the guide: it is simple now, but if we try to communicate "you cannot specify the current version by its true name, you must use the special keyword name 'current' because we have particular internals XXX in our code". Well, it will look inconvenient and broken to the user.

The right way to overcome that is to add the original name property to the GlobalVersion type:

export type GlobalVersion = {
  name: string;
+ /** The true version name as defined in the config */
+ canonicalName: string;
  label: string;
  isLast: boolean;
  path: string;
  /** The doc with `slug: /`, or first doc in first sidebar */
  mainDocId: string;
  docs: GlobalDoc[];
  /** Unversioned IDs. In development, this list is empty. */
  draftIds: string[];
  sidebars?: {[sidebarId: string]: GlobalSidebar};
};

and then use it as a secondary (or primary) version identifier.

website/docs/api/themes/theme-configuration.mdx Outdated Show resolved Hide resolved
website/docs/api/themes/theme-configuration.mdx Outdated Show resolved Hide resolved
@slorber slorber changed the title Implementation and docs for versions configuration of "docsVersionDropdown" navbar item feat(theme):Add versions attribute to docsVersionDropdown navbar item Jan 20, 2025
@slorber slorber changed the title feat(theme):Add versions attribute to docsVersionDropdown navbar item feat(theme): add versions attribute to docsVersionDropdown navbar item Jan 20, 2025
@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Jan 20, 2025
@hrumhurum hrumhurum requested a review from slorber January 20, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Limiting number of versions visible in the version dropdown switch
3 participants