Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
OzakIOne committed Feb 9, 2024
1 parent db5e50e commit 4414a5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions packages/docusaurus-plugin-content-docs/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,20 @@ export const useAllDocsData = (): {[pluginId: string]: GlobalPluginData} =>
}
| undefined) ?? StableEmptyObject;

export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
usePluginData('docusaurus-plugin-content-docs', pluginId, {
failfast: true,
}) as GlobalPluginData;
export const useDocsData = (pluginId: string | undefined): GlobalPluginData => {
try {
return usePluginData('docusaurus-plugin-content-docs', pluginId, {
failfast: true,
}) as GlobalPluginData;
} catch (error) {
throw new Error(
`You are using a feature of the Docusaurus docs plugin, but this plugin does not seem to be enabled${
pluginId === 'Default' ? '' : ` (pluginId=${pluginId}`
}`,
{cause: error as Error},
);
}
};

// TODO this feature should be provided by docusaurus core
export function useActivePlugin(
Expand Down Expand Up @@ -143,16 +153,9 @@ export function useActiveVersion(
export function useActiveDocContext(
pluginId: string | undefined,
): ActiveDocContext {
try {
const data = useDocsData(pluginId);
const {pathname} = useLocation();
return getActiveDocContext(data, pathname);
} catch (error) {
throw new Error(
'It seems that you are using a doc plugin feature while the doc plugin seems to be disabled in `docusaurus.config.js`.',
error as Error,
);
}
const data = useDocsData(pluginId);
const {pathname} = useLocation();
return getActiveDocContext(data, pathname);
}
/**
* Useful to say "hey, you are not on the latest docs version, please switch"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/blog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ Don't forget to delete the existing homepage at `./src/pages/index.js` or else t

:::warning

Don't forget to delete element of type doc in `docusaurus.config.js` in the navbar for example or else Docusaurus will crash.
If you disable the docs plugin, don't forget to delete references to the docs plugin elsewhere in your configuration file. Notably, make sure to remove the docs-related navbar items.

:::

Expand Down

0 comments on commit 4414a5f

Please sign in to comment.