mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 16:17:25 +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
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {OptionsSchema, DEFAULT_OPTIONS} from '../options';
|
||||
import {OptionsSchema, DEFAULT_OPTIONS, validateOptions} from '../options';
|
||||
import {normalizePluginOptions} from '@docusaurus/utils-validation';
|
||||
import {DefaultSidebarItemsGenerator} from '../sidebarItemsGenerator';
|
||||
import {
|
||||
|
@ -13,11 +13,22 @@ import {
|
|||
DisabledNumberPrefixParser,
|
||||
} from '../numberPrefix';
|
||||
import {GlobExcludeDefault} from '@docusaurus/utils';
|
||||
import {PluginOptions} from '../types';
|
||||
|
||||
// the type of remark/rehype plugins is function
|
||||
const markdownPluginsFunctionStub = () => {};
|
||||
const markdownPluginsObjectStub = {};
|
||||
|
||||
function testValidateOptions(options: Partial<PluginOptions>) {
|
||||
return validateOptions({
|
||||
options: {
|
||||
...DEFAULT_OPTIONS,
|
||||
...options,
|
||||
},
|
||||
validate: normalizePluginOptions,
|
||||
});
|
||||
}
|
||||
|
||||
describe('normalizeDocsPluginOptions', () => {
|
||||
test('should return default options for undefined user options', async () => {
|
||||
const {value, error} = await OptionsSchema.validate({});
|
||||
|
@ -58,6 +69,8 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
label: 'world',
|
||||
},
|
||||
},
|
||||
sidebarCollapsible: false,
|
||||
sidebarCollapsed: false,
|
||||
};
|
||||
const {value, error} = await OptionsSchema.validate(userOptions);
|
||||
expect(value).toEqual(userOptions);
|
||||
|
@ -230,4 +243,30 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
`"\\"versions.current.hey\\" is not allowed"`,
|
||||
);
|
||||
});
|
||||
|
||||
test('should handle sidebarCollapsed option inconsistencies', () => {
|
||||
expect(
|
||||
testValidateOptions({
|
||||
...DEFAULT_OPTIONS,
|
||||
sidebarCollapsible: true,
|
||||
sidebarCollapsed: undefined,
|
||||
}).sidebarCollapsed,
|
||||
).toEqual(true);
|
||||
|
||||
expect(
|
||||
testValidateOptions({
|
||||
...DEFAULT_OPTIONS,
|
||||
sidebarCollapsible: false,
|
||||
sidebarCollapsed: undefined,
|
||||
}).sidebarCollapsed,
|
||||
).toEqual(false);
|
||||
|
||||
expect(
|
||||
testValidateOptions({
|
||||
...DEFAULT_OPTIONS,
|
||||
sidebarCollapsible: false,
|
||||
sidebarCollapsed: true,
|
||||
}).sidebarCollapsed,
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue