mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-23 03:29:11 +02:00
Add initial implementation of sidebar keys
This commit is contained in:
parent
222a077d85
commit
3a5010a83a
9 changed files with 349 additions and 34 deletions
|
@ -8,6 +8,7 @@
|
|||
/**
|
||||
* @typedef {import('@docusaurus/plugin-content-docs').SidebarsConfig} SidebarsConfig
|
||||
* @typedef {import('@docusaurus/plugin-content-docs/lib/sidebars/types').SidebarItemConfig} SidebarItemConfig
|
||||
* @typedef {import('@docusaurus/plugin-content-docs/lib/sidebars/types').SidebarItemCategoryConfig} SidebarItemCategoryConfig
|
||||
*/
|
||||
|
||||
/** @type {SidebarsConfig} */
|
||||
|
@ -63,7 +64,8 @@ const sidebars = {
|
|||
items: [
|
||||
{
|
||||
type: 'link',
|
||||
label: 'Link ',
|
||||
label: 'Link',
|
||||
key: 'link-key-1',
|
||||
href: 'https://docusaurus.io',
|
||||
},
|
||||
],
|
||||
|
@ -76,6 +78,7 @@ const sidebars = {
|
|||
{
|
||||
type: 'link',
|
||||
label: 'Link ',
|
||||
key: 'link-key-2',
|
||||
href: 'https://docusaurus.io',
|
||||
},
|
||||
],
|
||||
|
@ -182,14 +185,16 @@ function generateHugeSidebarItems() {
|
|||
/**
|
||||
* @param {number} maxLevel
|
||||
* @param {number} currentLevel
|
||||
* @param {string} parentKey
|
||||
* @returns {SidebarItemConfig[]}
|
||||
*/
|
||||
function generateRecursive(maxLevel, currentLevel = 0) {
|
||||
function generateRecursive(maxLevel, currentLevel = 0, parentKey = 'ROOT') {
|
||||
if (currentLevel === maxLevel) {
|
||||
return [
|
||||
{
|
||||
type: 'link',
|
||||
href: '/',
|
||||
key: `link-${parentKey}-maxLevel`,
|
||||
label: `Link (level ${currentLevel + 1})`,
|
||||
},
|
||||
];
|
||||
|
@ -198,14 +203,23 @@ function generateHugeSidebarItems() {
|
|||
const linkItems = Array.from(Array(linksCount).keys()).map((index) => ({
|
||||
type: 'link',
|
||||
href: '/',
|
||||
key: `link-${parentKey}-${index}`,
|
||||
label: `Link ${index} (level ${currentLevel + 1})`,
|
||||
}));
|
||||
|
||||
const categoryItems = Array.from(Array(categoriesCount).keys()).map(
|
||||
/**
|
||||
* @returns {SidebarItemCategoryConfig}
|
||||
*/
|
||||
(index) => ({
|
||||
type: 'category',
|
||||
label: `Category ${index} (level ${currentLevel + 1})`,
|
||||
items: generateRecursive(maxLevel, currentLevel + 1),
|
||||
key: `category-${parentKey}-${index}`,
|
||||
items: generateRecursive(
|
||||
maxLevel,
|
||||
currentLevel + 1,
|
||||
`${parentKey}-${index}`,
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue