Skip to content

Commit

Permalink
chore(v2): use single method Lodash packages in docs plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Simek committed Apr 3, 2020
1 parent 2b4dbc3 commit 0d9b9f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
5 changes: 4 additions & 1 deletion packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"globby": "^10.0.1",
"import-fresh": "^3.2.1",
"loader-utils": "^1.2.3",
"lodash": "^4.17.15",
"lodash.groupby": "^4.6.0",
"lodash.flatmap": "^4.5.0",
"lodash.pick": "^4.4.0",
"lodash.pickby": "^4.6.0",
"shelljs": "^0.8.3"
},
"peerDependencies": {
Expand Down
29 changes: 15 additions & 14 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import _ from 'lodash';
import groupBy from 'lodash.groupby';
import pick from 'lodash.pick';
import pickBy from 'lodash.pickby';
import globby from 'globby';
import fs from 'fs-extra';
import path from 'path';
Expand Down Expand Up @@ -101,13 +103,13 @@ export default function pluginContentDocs(
const {include} = options;
let globPattern = include.map(pattern => `${docsDir}/${pattern}`);
if (versioning.enabled) {
const docsGlob = _.flatten(
include.map(pattern =>
const docsGlob = include
.map(pattern =>
versionsNames.map(
versionName => `${versionedDir}/${versionName}/${pattern}`,
),
),
);
)
.reduce((a, b) => a.concat(b), []);
const sidebarsGlob = versionsNames.map(
versionName => `${versionedSidebarsDir}/${versionName}-sidebars.json`,
);
Expand Down Expand Up @@ -149,11 +151,11 @@ export default function pluginContentDocs(

// Metadata for versioned docs.
if (versioning.enabled) {
const versionedGlob = _.flatten(
include.map(pattern =>
const versionedGlob = include
.map(pattern =>
versionsNames.map(versionName => `${versionName}/${pattern}`),
),
);
)
.reduce((a, b) => a.concat(b), []);
const versionedFiles = await globby(versionedGlob, {
cwd: versionedDir,
});
Expand Down Expand Up @@ -338,7 +340,7 @@ export default function pluginContentDocs(
// If versioning is enabled, we cleverly chunk the generated routes
// to be by version and pick only needed base metadata.
if (versioning.enabled) {
const docsMetadataByVersion = _.groupBy(
const docsMetadataByVersion = groupBy(
Object.values(content.docsMetadata),
'version',
);
Expand All @@ -358,13 +360,12 @@ export default function pluginContentDocs(
const neededSidebars: Set<string> =
content.versionToSidebars[version] || new Set();
const docsBaseMetadata: DocsBaseMetadata = {
docsSidebars: _.pick(
docsSidebars: pick(
content.docsSidebars,
Array.from(neededSidebars),
),
permalinkToSidebar: _.pickBy(
content.permalinkToSidebar,
sidebar => neededSidebars.has(sidebar),
permalinkToSidebar: pickBy(content.permalinkToSidebar, sidebar =>
neededSidebars.has(sidebar),
),
version,
};
Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus-plugin-content-docs/src/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import _ from 'lodash';
import flatMap from 'lodash.flatmap';
import fs from 'fs-extra';
import importFresh from 'import-fresh';
import {
Expand Down Expand Up @@ -106,12 +106,12 @@ function normalizeItem(item: SidebarItemRaw): SidebarItem[] {
];
}
if (isCategoryShorthand(item)) {
return _.flatMap(normalizeCategoryShorthand(item), normalizeItem);
return flatMap(normalizeCategoryShorthand(item), normalizeItem);
}
switch (item.type) {
case 'category':
assertIsCategory(item);
return [{...item, items: _.flatMap(item.items, normalizeItem)}];
return [{...item, items: flatMap(item.items, normalizeItem)}];
case 'link':
assertIsLink(item);
return [item];
Expand All @@ -134,7 +134,7 @@ function normalizeSidebar(sidebars: SidebarRaw): Sidebar {
? sidebar
: normalizeCategoryShorthand(sidebar);

acc[sidebarId] = _.flatMap(normalizedSidebar, normalizeItem);
acc[sidebarId] = flatMap(normalizedSidebar, normalizeItem);

return acc;
},
Expand Down

0 comments on commit 0d9b9f5

Please sign in to comment.