mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 11:36:53 +02:00
feat(v2): docs plugin initial work (#1327)
* feat(v2): pluginify docs * feat(v2): implement docs plugin * fix(v2): fix bugs in docs plugin for translation and versioning
This commit is contained in:
parent
c33e874e1c
commit
a70d9b6720
32 changed files with 576 additions and 371 deletions
72
packages/docusaurus-plugin-content-docs/src/order.js
Normal file
72
packages/docusaurus-plugin-content-docs/src/order.js
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.
|
||||
*/
|
||||
|
||||
// Build the docs meta such as next, previous, category and sidebar.
|
||||
module.exports = function createOrder(allSidebars = {}) {
|
||||
const order = {};
|
||||
|
||||
Object.keys(allSidebars).forEach(sidebarId => {
|
||||
const sidebar = allSidebars[sidebarId];
|
||||
|
||||
const ids = [];
|
||||
const categoryOrder = [];
|
||||
const subCategoryOrder = [];
|
||||
const indexItems = ({items, categoryLabel, subCategoryLabel}) => {
|
||||
items.forEach(item => {
|
||||
switch (item.type) {
|
||||
case 'category':
|
||||
indexItems({
|
||||
items: item.items,
|
||||
categoryLabel: categoryLabel || item.label,
|
||||
subCategoryLabel: categoryLabel && item.label,
|
||||
});
|
||||
break;
|
||||
case 'ref':
|
||||
case 'link':
|
||||
// Refs and links should not be shown in navigation.
|
||||
break;
|
||||
case 'doc':
|
||||
ids.push(item.id);
|
||||
categoryOrder.push(categoryLabel);
|
||||
subCategoryOrder.push(subCategoryLabel);
|
||||
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,
|
||||
category: categoryOrder[i],
|
||||
subCategory: subCategoryOrder[i],
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
return order;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue