fix(v2): remove buggy routesLoaded + deprecate routesLoaded lifecycle (#3141)

* remove bad deletion of docs / if conflicting with a page

* deprecate routesLoaded
This commit is contained in:
Sébastien Lorber 2020-07-28 14:28:14 +02:00 committed by GitHub
parent ac757e9dff
commit d25d4b08f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 30 deletions

View file

@ -68,9 +68,6 @@ export default function pluginContentDocs(
context: LoadContext,
options: PluginOptions,
): Plugin<LoadedContent | null, typeof PluginOptionSchema> {
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;

View file

@ -138,7 +138,7 @@ export interface Plugin<T, U = unknown> {
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?(

View file

@ -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);
}),
);

View file

@ -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 <build> finish.
},