Skip to content

Commit 8d115a9

Browse files
authored
feat(core): add new plugin allContentLoaded lifecycle (#9931)
1 parent d02b96f commit 8d115a9

7 files changed

Lines changed: 787 additions & 224 deletions

File tree

packages/docusaurus-plugin-debug/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function pluginDebug({
3030
return '../src/theme';
3131
},
3232

33-
async contentLoaded({actions: {createData, addRoute}, allContent}) {
33+
async allContentLoaded({actions: {createData, addRoute}, allContent}) {
3434
const allContentPath = await createData(
3535
// Note that this created data path must be in sync with
3636
// metadataPath provided to mdx-loader.

packages/docusaurus-types/src/plugin.d.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import type {RouteConfig} from './routing';
1818

1919
export type PluginOptions = {id?: string} & {[key: string]: unknown};
2020

21-
export type PluginConfig =
21+
export type PluginConfig<Content = unknown> =
2222
| string
2323
| [string, PluginOptions]
24-
| [PluginModule, PluginOptions]
25-
| PluginModule
24+
| [PluginModule<Content>, PluginOptions]
25+
| PluginModule<Content>
2626
| false
2727
| null;
2828

@@ -110,7 +110,9 @@ export type Plugin<Content = unknown> = {
110110
contentLoaded?: (args: {
111111
/** The content loaded by this plugin instance */
112112
content: Content; //
113-
/** Content loaded by ALL the plugins */
113+
actions: PluginContentLoadedActions;
114+
}) => Promise<void> | void;
115+
allContentLoaded?: (args: {
114116
allContent: AllContent;
115117
actions: PluginContentLoadedActions;
116118
}) => Promise<void> | void;
@@ -183,8 +185,10 @@ export type LoadedPlugin = InitializedPlugin & {
183185
readonly content: unknown;
184186
};
185187

186-
export type PluginModule = {
187-
(context: LoadContext, options: unknown): Plugin | Promise<Plugin>;
188+
export type PluginModule<Content = unknown> = {
189+
(context: LoadContext, options: unknown):
190+
| Plugin<Content>
191+
| Promise<Plugin<Content>>;
188192
validateOptions?: <T, U>(data: OptionValidationContext<T, U>) => U;
189193
validateThemeConfig?: <T>(data: ThemeConfigValidationContext<T>) => T;
190194

packages/docusaurus/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"devDependencies": {
108108
"@docusaurus/module-type-aliases": "3.0.0",
109109
"@docusaurus/types": "3.0.0",
110+
"@total-typescript/shoehorn": "^0.1.2",
110111
"@types/detect-port": "^1.3.3",
111112
"@types/react-dom": "^18.2.7",
112113
"@types/react-router-config": "^5.0.7",

packages/docusaurus/src/server/plugins/__tests__/__snapshots__/plugins.test.ts.snap

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)