Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add new plugin allContentLoaded lifecycle #9931

Merged
merged 8 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading