docusaurus/website/_dogfooding/docs-tests-sidebars.js
Joshua Chen eaacb0e98a
feat(theme-classic, plugin-docs): sidebar item level-specific className + allow customization (#5642)
* Initial work

* Complete function

* Avoid duplication

* More dedupe

* Make everything constants

* Change casing & docs
2021-10-07 16:59:02 +02:00

73 lines
1.6 KiB
JavaScript

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = {
sidebar: [
{
type: 'doc',
id: 'index',
className: 'red',
label: 'Index',
},
{
type: 'category',
label: 'section',
collapsible: false,
items: ['index', 'more-test'],
},
{
type: 'category',
label: 'Huge sidebar category',
items: generateHugeSidebarItems(4),
},
{
type: 'link',
label: 'External link',
href: 'https://github.com/facebook/docusaurus',
className: 'red',
},
{
type: 'category',
label: 'TOC tests',
className: 'red',
items: [
{
type: 'autogenerated',
dirName: 'toc',
},
],
},
],
};
function generateHugeSidebarItems() {
const maxLevel = 4;
const linksCount = 5;
const categoriesCount = 5;
function generateRecursive(maxLevel, currentLevel = 0) {
if (currentLevel === maxLevel) {
return [];
}
const linkItems = [...Array(linksCount).keys()].map((index) => ({
type: 'link',
href: '/',
label: `Link ${index} (level ${currentLevel + 1})`,
}));
const categoryItems = [...Array(categoriesCount).keys()].map((index) => ({
type: 'category',
label: `Category ${index} (level ${currentLevel + 1})`,
items: generateRecursive(maxLevel, currentLevel + 1),
}));
return [...linkItems, ...categoryItems];
}
return generateRecursive(maxLevel);
}