mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-13 16:23:34 +02:00
misc(v2): remove legacy from docs
This commit is contained in:
parent
e3f25b2a45
commit
54e9e025d8
34 changed files with 24 additions and 24 deletions
72
packages/docusaurus-plugin-content-docs/src/order.ts
Normal file
72
packages/docusaurus-plugin-content-docs/src/order.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {
|
||||
Sidebar,
|
||||
SidebarItem,
|
||||
SidebarItemDoc,
|
||||
SidebarItemCategory,
|
||||
Order,
|
||||
} from './types';
|
||||
|
||||
// Build the docs meta such as next, previous, category and sidebar.
|
||||
export default function createOrder(allSidebars: Sidebar = {}): Order {
|
||||
const order: Order = {};
|
||||
|
||||
Object.keys(allSidebars).forEach(sidebarId => {
|
||||
const sidebar = allSidebars[sidebarId];
|
||||
|
||||
const ids: string[] = [];
|
||||
const indexItems = ({items}: {items: SidebarItem[]}) => {
|
||||
items.forEach(item => {
|
||||
switch (item.type) {
|
||||
case 'category':
|
||||
indexItems({
|
||||
items: (item as SidebarItemCategory).items,
|
||||
});
|
||||
break;
|
||||
case 'ref':
|
||||
case 'link':
|
||||
// Refs and links should not be shown in navigation.
|
||||
break;
|
||||
case 'doc':
|
||||
ids.push((item as SidebarItemDoc).id);
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown item type: ${item.type}. Item: ${JSON.stringify(item)}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
indexItems({items: sidebar});
|
||||
|
||||
// eslint-disable-next-line
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
const id = ids[i];
|
||||
let previous;
|
||||
let next;
|
||||
|
||||
if (i > 0) {
|
||||
previous = ids[i - 1];
|
||||
}
|
||||
|
||||
if (i < ids.length - 1) {
|
||||
next = ids[i + 1];
|
||||
}
|
||||
|
||||
order[id] = {
|
||||
previous,
|
||||
next,
|
||||
sidebar: sidebarId,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
return order;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue