mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 00:57:53 +02:00
chore: move to monorepo (#1297)
* chore: move to monorepo * lint all js file * simplify circleCI * fix failing tests * fix tests due to folder rename * fix test since v1 website is renamed
This commit is contained in:
parent
6b1d2e8c9c
commit
1f91d19a8c
619 changed files with 12713 additions and 26817 deletions
88
packages/docusaurus-1.x/lib/server/readCategories.js
Normal file
88
packages/docusaurus-1.x/lib/server/readCategories.js
Normal file
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
// returns data broken up into categories for a sidebar
|
||||
function readCategories(sidebar, allMetadata, languages) {
|
||||
const allCategories = {};
|
||||
|
||||
// Go through each language that might be defined.
|
||||
languages
|
||||
.filter(lang => lang.enabled)
|
||||
.map(lang => lang.tag)
|
||||
.forEach(language => {
|
||||
// Get all related metadata for the current sidebar and specific to the language.
|
||||
const metadatas = Object.values(allMetadata)
|
||||
.filter(
|
||||
metadata =>
|
||||
metadata.sidebar === sidebar && metadata.language === language,
|
||||
)
|
||||
.sort((a, b) => a.order - b.order);
|
||||
|
||||
// Define the correct order of categories.
|
||||
const sortedCategories = _.uniq(
|
||||
metadatas.map(metadata => metadata.category),
|
||||
);
|
||||
|
||||
const metadatasGroupedByCategory = _.chain(metadatas)
|
||||
.groupBy(metadata => metadata.category)
|
||||
.mapValues(categoryItems => {
|
||||
// Process subcategories.
|
||||
const metadatasGroupedBySubcategory = _.groupBy(
|
||||
categoryItems,
|
||||
item => item.subcategory,
|
||||
);
|
||||
const result = [];
|
||||
const seenSubcategories = new Set();
|
||||
// categoryItems can be links or subcategories. Handle separately.
|
||||
categoryItems.forEach(item => {
|
||||
// Has no subcategory.
|
||||
if (item.subcategory == null) {
|
||||
result.push({
|
||||
type: 'LINK',
|
||||
item,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const {subcategory} = item;
|
||||
// Subcategory has been processed, we can skip it.
|
||||
if (seenSubcategories.has(subcategory)) {
|
||||
return;
|
||||
}
|
||||
|
||||
seenSubcategories.add(subcategory);
|
||||
const subcategoryLinks = metadatasGroupedBySubcategory[
|
||||
subcategory
|
||||
].map(subcategoryItem => ({
|
||||
type: 'LINK',
|
||||
item: subcategoryItem,
|
||||
}));
|
||||
result.push({
|
||||
type: 'SUBCATEGORY',
|
||||
title: subcategory,
|
||||
children: subcategoryLinks,
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
})
|
||||
.value();
|
||||
|
||||
const categories = sortedCategories.map(category => ({
|
||||
type: 'CATEGORY',
|
||||
title: category,
|
||||
children: metadatasGroupedByCategory[category],
|
||||
}));
|
||||
allCategories[language] = categories;
|
||||
});
|
||||
|
||||
return allCategories;
|
||||
}
|
||||
|
||||
module.exports = readCategories;
|
Loading…
Add table
Add a link
Reference in a new issue