From d25d4b08f6378b793e9f157ce2a3fed8e443d279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Tue, 28 Jul 2020 14:28:14 +0200 Subject: [PATCH] fix(v2): remove buggy routesLoaded + deprecate routesLoaded lifecycle (#3141) * remove bad deletion of docs / if conflicting with a page * deprecate routesLoaded --- .../src/index.ts | 20 ------------------- packages/docusaurus-types/src/index.d.ts | 2 +- .../docusaurus/src/server/plugins/index.ts | 9 +++++++++ website/docs/lifecycle-apis.md | 9 --------- 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index 8d6cde8c37..120d584534 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -68,9 +68,6 @@ export default function pluginContentDocs( context: LoadContext, options: PluginOptions, ): Plugin { - const homePageDocsRoutePath = - options.routeBasePath === '' ? '/' : options.routeBasePath; - if (options.admonitions) { options.remarkPlugins = options.remarkPlugins.concat([ [admonitions, options.admonitions], @@ -487,23 +484,6 @@ Available document ids= ); }, - async routesLoaded(routes) { - const homeDocsRoutes = routes.filter( - (routeConfig) => routeConfig.path === homePageDocsRoutePath, - ); - - // Remove the route for docs home page if there is a page with the same path (i.e. docs). - if (homeDocsRoutes.length > 1) { - const docsHomePageRouteIndex = routes.findIndex( - (route) => - route.component === options.docLayoutComponent && - route.path === homePageDocsRoutePath, - ); - - delete routes[docsHomePageRouteIndex!]; - } - }, - configureWebpack(_config, isServer, utils) { const {getBabelLoader, getCacheLoader} = utils; const {rehypePlugins, remarkPlugins} = options; diff --git a/packages/docusaurus-types/src/index.d.ts b/packages/docusaurus-types/src/index.d.ts index 334035005e..cc607086d7 100644 --- a/packages/docusaurus-types/src/index.d.ts +++ b/packages/docusaurus-types/src/index.d.ts @@ -138,7 +138,7 @@ export interface Plugin { content: T; actions: PluginContentLoadedActions; }): void; - routesLoaded?(routes: RouteConfig[]): void; + routesLoaded?(routes: RouteConfig[]): void; // TODO remove soon, deprecated (alpha-60) postBuild?(props: Props): void; postStart?(props: Props): void; configureWebpack?( diff --git a/packages/docusaurus/src/server/plugins/index.ts b/packages/docusaurus/src/server/plugins/index.ts index 73029e67c1..814961da10 100644 --- a/packages/docusaurus/src/server/plugins/index.ts +++ b/packages/docusaurus/src/server/plugins/index.ts @@ -15,6 +15,7 @@ import { RouteConfig, } from '@docusaurus/types'; import initPlugins, {InitPlugin} from './init'; +import chalk from 'chalk'; const DefaultPluginId = 'default'; @@ -144,6 +145,14 @@ export async function loadPlugins({ return null; } + // TODO remove this deprecated lifecycle soon + // deprecated since alpha-60 + console.error( + chalk.red( + 'plugin routesLoaded lifecycle is deprecated. If you think we should keep this lifecycle, please open a Github issue with your usecase', + ), + ); + return plugin.routesLoaded(pluginsRouteConfigs); }), ); diff --git a/website/docs/lifecycle-apis.md b/website/docs/lifecycle-apis.md index b4397fe748..11cdda37c1 100644 --- a/website/docs/lifecycle-apis.md +++ b/website/docs/lifecycle-apis.md @@ -275,10 +275,6 @@ export default function friendsPlugin(context, options) { } ``` -## `async routesLoaded(routes)` - -Plugins can modify the routes that were generated by all plugins. `routesLoaded` is called after `contentLoaded` hook. - ## `configureWebpack(config, isServer, utils)` Modifies the internal webpack config. If the return value is a JavaScript object, it will be merged into the final config using [`webpack-merge`](https://github.com/survivejs/webpack-merge). If it is a function, it will be called and receive `config` as the first argument and an `isServer` flag as the argument argument. @@ -574,11 +570,6 @@ module.exports = function (context, opts) { // `actions` are set of functional API provided by Docusaurus (e.g. addRoute) }, - async routesLoaded(routes) { - // The routesLoaded hook is done after contentLoaded hook is done. - // This can be useful if you need to change any route. - }, - async postBuild(props) { // After docusaurus finish. },