Skip to content

Commit

Permalink
feat(core): add new plugin allContentLoaded lifecycle (#9931)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Mar 8, 2024
1 parent d02b96f commit 8d115a9
Show file tree
Hide file tree
Showing 7 changed files with 787 additions and 224 deletions.
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-debug/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function pluginDebug({
return '../src/theme';
},

async contentLoaded({actions: {createData, addRoute}, allContent}) {
async allContentLoaded({actions: {createData, addRoute}, allContent}) {
const allContentPath = await createData(
// Note that this created data path must be in sync with
// metadataPath provided to mdx-loader.
Expand Down
16 changes: 10 additions & 6 deletions packages/docusaurus-types/src/plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import type {RouteConfig} from './routing';

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

export type PluginConfig =
export type PluginConfig<Content = unknown> =
| string
| [string, PluginOptions]
| [PluginModule, PluginOptions]
| PluginModule
| [PluginModule<Content>, PluginOptions]
| PluginModule<Content>
| false
| null;

Expand Down Expand Up @@ -110,7 +110,9 @@ export type Plugin<Content = unknown> = {
contentLoaded?: (args: {
/** The content loaded by this plugin instance */
content: Content; //
/** Content loaded by ALL the plugins */
actions: PluginContentLoadedActions;
}) => Promise<void> | void;
allContentLoaded?: (args: {
allContent: AllContent;
actions: PluginContentLoadedActions;
}) => Promise<void> | void;
Expand Down Expand Up @@ -183,8 +185,10 @@ export type LoadedPlugin = InitializedPlugin & {
readonly content: unknown;
};

export type PluginModule = {
(context: LoadContext, options: unknown): Plugin | Promise<Plugin>;
export type PluginModule<Content = unknown> = {
(context: LoadContext, options: unknown):
| Plugin<Content>
| Promise<Plugin<Content>>;
validateOptions?: <T, U>(data: OptionValidationContext<T, U>) => U;
validateThemeConfig?: <T>(data: ThemeConfigValidationContext<T>) => T;

Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"devDependencies": {
"@docusaurus/module-type-aliases": "3.0.0",
"@docusaurus/types": "3.0.0",
"@total-typescript/shoehorn": "^0.1.2",
"@types/detect-port": "^1.3.3",
"@types/react-dom": "^18.2.7",
"@types/react-router-config": "^5.0.7",
Expand Down

This file was deleted.

Loading

0 comments on commit 8d115a9

Please sign in to comment.