mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-16 17:52:29 +02:00
feat: docs plugin options sidebarCollapsible + sidebarCollapsed (#5203)
* Add prop Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Add `collapsible` option to sidebar item Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Add eslint-ignore Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Move new page Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Allow in autogenerated Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix tests Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Move config options to plugin-docs Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Make non-collapsible items always expanded Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * docs versioning cli should receive a single options object * Update cli.test.ts * revert validateCategoryMetadataFile change * remove theme usage of themeConfig.sidebarCollapsible * better handling of sidebar item category inconsistencies + add warning message * Update snapshot Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Handle plugin option inconsistencies * improve doc for new sidebarCollapsible doc options * remove warning in fixSidebarItemInconsistencies as it will be annoyed for versioned sites, as "collapsed" is already persisted in sidebar json files Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
b38c35a36d
commit
24156efcfb
27 changed files with 487 additions and 109 deletions
|
@ -46,6 +46,8 @@ export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'> = {
|
|||
versions: {},
|
||||
editCurrentVersion: false,
|
||||
editLocalizedFiles: false,
|
||||
sidebarCollapsible: true,
|
||||
sidebarCollapsed: true,
|
||||
};
|
||||
|
||||
const VersionOptionsSchema = Joi.object({
|
||||
|
@ -77,6 +79,8 @@ export const OptionsSchema = Joi.object({
|
|||
sidebarItemsGenerator: Joi.function().default(
|
||||
() => DEFAULT_OPTIONS.sidebarItemsGenerator,
|
||||
),
|
||||
sidebarCollapsible: Joi.boolean().default(DEFAULT_OPTIONS.sidebarCollapsible),
|
||||
sidebarCollapsed: Joi.boolean().default(DEFAULT_OPTIONS.sidebarCollapsed),
|
||||
numberPrefixParser: Joi.alternatives()
|
||||
.try(
|
||||
Joi.function(),
|
||||
|
@ -116,8 +120,32 @@ export const OptionsSchema = Joi.object({
|
|||
|
||||
export function validateOptions({
|
||||
validate,
|
||||
options,
|
||||
options: userOptions,
|
||||
}: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
|
||||
let options = userOptions;
|
||||
|
||||
if (options.sidebarCollapsible === false) {
|
||||
// When sidebarCollapsible=false and sidebarCollapsed=undefined, we don't want to have the inconsistency warning
|
||||
// We let options.sidebarCollapsible become the default value for options.sidebarCollapsed
|
||||
if (typeof options.sidebarCollapsed === 'undefined') {
|
||||
options = {
|
||||
...options,
|
||||
sidebarCollapsed: false,
|
||||
};
|
||||
}
|
||||
if (options.sidebarCollapsed) {
|
||||
console.warn(
|
||||
chalk.yellow(
|
||||
'The docs plugin config is inconsistent. It does not make sense to use sidebarCollapsible=false and sidebarCollapsed=true at the same time. sidebarCollapsed=false will be ignored.',
|
||||
),
|
||||
);
|
||||
options = {
|
||||
...options,
|
||||
sidebarCollapsed: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove homePageId before end of 2020
|
||||
// "slug: /" is better because the home doc can be different across versions
|
||||
if (options.homePageId) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue