mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 19:46:57 +02:00
chore: prepare for docs sidebar
This commit is contained in:
parent
2141e6ea90
commit
b477863a30
9 changed files with 350 additions and 2 deletions
34
lib/load/docs/order.js
Normal file
34
lib/load/docs/order.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
// build the docs meta such as next, previous, category and sidebar
|
||||
module.exports = function createOrder(allSidebars = {}) {
|
||||
const order = {};
|
||||
if (!allSidebars) {
|
||||
return order;
|
||||
}
|
||||
Object.keys(allSidebars).forEach(sidebar => {
|
||||
const categories = allSidebars[sidebar];
|
||||
|
||||
let ids = [];
|
||||
const categoryOrder = [];
|
||||
Object.keys(categories).forEach(category => {
|
||||
ids = ids.concat(categories[category]);
|
||||
for (let i = 0; i < categories[category].length; i++) {
|
||||
categoryOrder.push(category);
|
||||
}
|
||||
});
|
||||
|
||||
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,
|
||||
category: categoryOrder[i]
|
||||
};
|
||||
}
|
||||
});
|
||||
return order;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue