-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
base: main
Are you sure you want to change the base?
Conversation
…ionDropdown" navbar item
…rsionDropdown" navbar item
…sVersionDropdown" navbar item
Hi @hrumhurum! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
…ration of "docsVersionDropdown" navbar item
…ion of "docsVersionDropdown" navbar item
…"docsVersionDropdown" navbar item
…"docsVersionDropdown" navbar item
…on docs of "docsVersionDropdown" navbar item
…gurations in "docsVersionDropdown" navbar item
…ions in "docsVersionDropdown" navbar item
…navbar item: code refactoring
There was a problem hiding this 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
@@ -204,12 +208,23 @@ const DropdownNavbarItemSchema = NavbarItemBaseSchema.append({ | |||
items: Joi.array().items(DropdownSubitemSchema).required(), | |||
}); | |||
|
|||
const DocsVersionNameSchema = Joi.string().min(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to "inline" this schema because it's tightly coupled to the dropdown but its name makes me thing it is a more general purpose schema. If we don't inline it, we'd rather have a "scoped name" such as DocsVersionDropdownVersionNameSchema
which is a bit awkward. Considering the schema is relatively simple it's not a big deal if inlining means duplicating twice.
configuration?: VersionConfiguration; | ||
}; | ||
|
||
function configureVersions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm that looks a bit complicated to me.
Here's some pseudo-code I'd write to normalize the 3 cases under a single one:
type VersionConfig = {
label?: string
}
type VersionItem = {
version: GlobalVersion,
config?: VersionConfig
}
function getDropdownVersions({versions,item)}): VersionItem[] {
const versionMap = new Map<string, GlobalVersion>(
versions.map((version) => [version.name, version]),
);
if ( item.versions ) {
// Maybe fail-fast if the user provide version names that do not exist
// But it's preferable to do this earlier in Node.js side, if possible
if (Array.isArray(item.versions)) {
return item.versions.map(name => ({
version: versionMap[name],
config: undefined;
}));
}
else {
// pseudo code: in practice, we don't want to import Lodash in theme code
return _.mapValues(item.versions,(config,name) => ({
version: versionMap[name],
config,
}));
}
}
else {
return versions.map(v => ({version, config: undefined})
}
}
// 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); |
There was a problem hiding this comment.
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
@@ -597,6 +597,7 @@ Accepted fields: | |||
| `dropdownItemsAfter` | <code>[LinkLikeItem](#navbar-dropdown)[]</code> | `[]` | Add additional dropdown items at the end of the dropdown. | | |||
| `docsPluginId` | `string` | `'default'` | The ID of the docs plugin that the doc versioning belongs to. | | |||
| `dropdownActiveClassDisabled` | `boolean` | `false` | Do not add the link active class when browsing docs. | | |||
| `versions` | <code>string[] \| object</code> | `undefined` | Specify a custom list of versions to include in the dropdown, or specify an object with detailed version configurations. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd need to document a type/shape, not just object
If needed, as a "Types: "
code block, similar to what we do in other places such as https://docusaurus.io/docs/next/api/plugins/@docusaurus/plugin-content-docs#types
(since the example is not a heading, no need to create a ### Types
heading here for consistency)
What I'd do:
Types:
```ts
type DropdownVersions = string[] | {[name: string]: {label?: string}}
```
By default, the version dropdown displays all the versions provided by the docs. | ||
However, sometimes it may be beneficial to restrict the number of displayed versions to declutter the UI. | ||
To achieve that, it is possible to specify a custom list of versions that should be offered in the dropdown: | ||
|
||
```js title="docusaurus.config.js" | ||
export default { | ||
themeConfig: { | ||
navbar: { | ||
items: [ | ||
{ | ||
type: 'docsVersionDropdown', | ||
// highlight-start | ||
versions: ['2024.3', '2024.2', '2024.1', '2023.4'], | ||
// highlight-end | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
``` | ||
|
||
Some versioning schemes may benefit from an even more detailed configuration of displayed versions. | ||
For example, if you are using semantic versioning, you may have versions such as: | ||
|
||
``` | ||
2.1.1 | ||
2.1.0 | ||
2.0.1 | ||
2.0.0 | ||
1.0.1 | ||
1.0.0 | ||
``` | ||
|
||
And maybe you want to have them in the dropdown as: | ||
|
||
``` | ||
2.1 | ||
2.0 | ||
1.0 | ||
``` | ||
|
||
or maybe just: | ||
|
||
``` | ||
1.x | ||
2.x | ||
``` | ||
|
||
To achieve that, you can specify a custom configuration for every version that should be displayed in the dropdown: | ||
|
||
```js title="docusaurus.config.js" | ||
export default { | ||
themeConfig: { | ||
navbar: { | ||
items: [ | ||
{ | ||
type: 'docsVersionDropdown', | ||
// highlight-start | ||
versions: { | ||
'1.0.1': {label: '1.x'}, | ||
'2.1.1': {label: '2.x'}, | ||
}, | ||
// highlight-end | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
``` | ||
|
||
The fields accepted by the custom version configuration: | ||
|
||
```mdx-code-block | ||
<APITable name="navbar-docs-version-dropdown-configuration"> | ||
``` | ||
|
||
| Name | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| `label` | `string` | Optional | The custom name to be shown in the dropdown for this version. | | ||
|
||
```mdx-code-block | ||
</APITable> | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are in the "reference docs" section, which is concise and formal on purpose.
However, sometimes it may be beneficial to restrict the number of displayed versions to declutter the UI
What you write here is more in the tone of a "guide" rather than "reference docs". It has an opinion on how this feature should be used and explains it in depth.
This kind of thing belongs to another place, such as this one:
https://docusaurus.io/docs/next/versioning#navbar-items
Can you please keep this section as concise, formal, and normaliezed as possible?
The idea is to just have one table of attributes, one config example, and if needed a types code block, and nothing more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: if you really want to write this "opinionated guide" about this new feature, we'd probably need to document all the other navbar items one by one here for consistency: https://docusaurus.io/docs/next/versioning#navbar-items
Since we don't have that already, maybe it's better to do that in a separate docs-only PR so that we don't block this PR being merged due to docs organization concerns
versions
attribute to docsVersionDropdown
navbar item
versions
attribute to docsVersionDropdown
navbar itemversions
attribute to docsVersionDropdown
navbar item
Pre-flight checklist
Motivation
This PR implements a part of the functionality required to complete the feature.
Test Plan
Test links
Deploy preview: https://gp-temp-docusaurus-app1.netlify.app/eazfuscator.net
Related issues/PRs