Skip to content

Commit

Permalink
feat(preset-classic): guard against unknown keys in options (#5831)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena authored Oct 30, 2021
1 parent adbc02e commit 9247332
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 43 deletions.
34 changes: 18 additions & 16 deletions packages/docusaurus-preset-classic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,42 @@ export default function preset(
const {themeConfig} = siteConfig;
const {algolia, googleAnalytics, gtag} = themeConfig as Partial<ThemeConfig>;
const isProd = process.env.NODE_ENV === 'production';
const {debug, docs, blog, pages, sitemap, theme, ...rest} = opts;

const themes: PluginConfig[] = [];
themes.push(makePluginConfig('@docusaurus/theme-classic', opts.theme));
themes.push(makePluginConfig('@docusaurus/theme-classic', theme));
if (algolia) {
themes.push(require.resolve('@docusaurus/theme-search-algolia'));
}

const plugins: PluginConfig[] = [];
if (opts.docs !== false) {
plugins.push(
makePluginConfig('@docusaurus/plugin-content-docs', opts.docs),
);
if (docs !== false) {
plugins.push(makePluginConfig('@docusaurus/plugin-content-docs', docs));
}
if (opts.blog !== false) {
plugins.push(
makePluginConfig('@docusaurus/plugin-content-blog', opts.blog),
);
if (blog !== false) {
plugins.push(makePluginConfig('@docusaurus/plugin-content-blog', blog));
}
if (opts.pages !== false) {
plugins.push(
makePluginConfig('@docusaurus/plugin-content-pages', opts.pages),
);
if (pages !== false) {
plugins.push(makePluginConfig('@docusaurus/plugin-content-pages', pages));
}
if (isProd && googleAnalytics) {
plugins.push(require.resolve('@docusaurus/plugin-google-analytics'));
}
if (opts.debug || (typeof opts.debug === 'undefined' && !isProd)) {
if (debug || (debug === undefined && !isProd)) {
plugins.push(require.resolve('@docusaurus/plugin-debug'));
}
if (isProd && gtag) {
plugins.push(require.resolve('@docusaurus/plugin-google-gtag'));
}
if (isProd && opts.sitemap !== false) {
plugins.push(makePluginConfig('@docusaurus/plugin-sitemap', opts.sitemap));
if (isProd && sitemap !== false) {
plugins.push(makePluginConfig('@docusaurus/plugin-sitemap', sitemap));
}
if (Object.keys(rest).length > 0) {
throw new Error(
`Unrecognized keys ${Object.keys(rest).join(
', ',
)} found in preset-classic configuration. The allowed keys are debug, docs, blog, pages, sitemap, theme. Check the documentation: https://docusaurus.io/docs/presets#docusauruspreset-classic for more information on how to configure individual plugins.`,
);
}

return {themes, plugins};
Expand Down
18 changes: 9 additions & 9 deletions website/docs/presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ This is especially useful when some plugins and themes are intended to be used t

The classic preset that is usually shipped by default to new Docusaurus website. It is a set of plugins and themes.

| Themes | Plugins |
| ---------------------------------- | ------------------------------------- |
| `@docusaurus/theme-classic` | `@docusaurus/plugin-content-docs` |
| `@docusaurus/theme-search-algolia` | `@docusaurus/plugin-content-blog` |
| | `@docusaurus/plugin-content-pages` |
| | `@docusaurus/plugin-debug` |
| | `@docusaurus/plugin-google-analytics` |
| | `@docusaurus/plugin-google-gtag` |
| | `@docusaurus/plugin-sitemap` |
| Themes | Plugins |
| --- | --- |
| [`@docusaurus/theme-classic`](./api/themes/theme-configuration.md) | [`@docusaurus/plugin-content-docs`](./api/plugins/plugin-content-docs.md) |
| [`@docusaurus/theme-search-algolia`](./api/themes/theme-search-algolia.md) | [`@docusaurus/plugin-content-blog`](./api/plugins/plugin-content-blog.md) |
| | [`@docusaurus/plugin-content-pages`](./api/plugins/plugin-content-pages.md) |
| | [`@docusaurus/plugin-debug`](./api/plugins/plugin-debug.md) |
| | [`@docusaurus/plugin-google-analytics`](./api/plugins/plugin-google-analytics.md) |
| | [`@docusaurus/plugin-google-gtag`](./api/plugins/plugin-google-gtag.md) |
| | [`@docusaurus/plugin-sitemap`](./api/plugins/plugin-sitemap.md) |

To specify plugin options individually, you can provide the necessary fields to certain plugins, i.e. `customCss` for `@docusaurus/theme-classic`, pass them in the preset field, like this:

Expand Down
18 changes: 9 additions & 9 deletions website/versioned_docs/version-2.0.0-beta.7/presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ This is especially useful when some plugins and themes are intended to be used t

The classic preset that is usually shipped by default to new Docusaurus website. It is a set of plugins and themes.

| Themes | Plugins |
| ---------------------------------- | ------------------------------------- |
| `@docusaurus/theme-classic` | `@docusaurus/plugin-content-docs` |
| `@docusaurus/theme-search-algolia` | `@docusaurus/plugin-content-blog` |
| | `@docusaurus/plugin-content-pages` |
| | `@docusaurus/plugin-debug` |
| | `@docusaurus/plugin-google-analytics` |
| | `@docusaurus/plugin-google-gtag` |
| | `@docusaurus/plugin-sitemap` |
| Themes | Plugins |
| --- | --- |
| [`@docusaurus/theme-classic`](./api/themes/theme-configuration.md) | [`@docusaurus/plugin-content-docs`](./api/plugins/plugin-content-docs.md) |
| [`@docusaurus/theme-search-algolia`](./api/themes/theme-search-algolia.md) | [`@docusaurus/plugin-content-blog`](./api/plugins/plugin-content-blog.md) |
| | [`@docusaurus/plugin-content-pages`](./api/plugins/plugin-content-pages.md) |
| | [`@docusaurus/plugin-debug`](./api/plugins/plugin-debug.md) |
| | [`@docusaurus/plugin-google-analytics`](./api/plugins/plugin-google-analytics.md) |
| | [`@docusaurus/plugin-google-gtag`](./api/plugins/plugin-google-gtag.md) |
| | [`@docusaurus/plugin-sitemap`](./api/plugins/plugin-sitemap.md) |

To specify plugin options individually, you can provide the necessary fields to certain plugins, i.e. `customCss` for `@docusaurus/theme-classic`, pass them in the preset field, like this:

Expand Down
18 changes: 9 additions & 9 deletions website/versioned_docs/version-2.0.0-beta.8/presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ This is especially useful when some plugins and themes are intended to be used t

The classic preset that is usually shipped by default to new Docusaurus website. It is a set of plugins and themes.

| Themes | Plugins |
| ---------------------------------- | ------------------------------------- |
| `@docusaurus/theme-classic` | `@docusaurus/plugin-content-docs` |
| `@docusaurus/theme-search-algolia` | `@docusaurus/plugin-content-blog` |
| | `@docusaurus/plugin-content-pages` |
| | `@docusaurus/plugin-debug` |
| | `@docusaurus/plugin-google-analytics` |
| | `@docusaurus/plugin-google-gtag` |
| | `@docusaurus/plugin-sitemap` |
| Themes | Plugins |
| --- | --- |
| [`@docusaurus/theme-classic`](./api/themes/theme-configuration.md) | [`@docusaurus/plugin-content-docs`](./api/plugins/plugin-content-docs.md) |
| [`@docusaurus/theme-search-algolia`](./api/themes/theme-search-algolia.md) | [`@docusaurus/plugin-content-blog`](./api/plugins/plugin-content-blog.md) |
| | [`@docusaurus/plugin-content-pages`](./api/plugins/plugin-content-pages.md) |
| | [`@docusaurus/plugin-debug`](./api/plugins/plugin-debug.md) |
| | [`@docusaurus/plugin-google-analytics`](./api/plugins/plugin-google-analytics.md) |
| | [`@docusaurus/plugin-google-gtag`](./api/plugins/plugin-google-gtag.md) |
| | [`@docusaurus/plugin-sitemap`](./api/plugins/plugin-sitemap.md) |

To specify plugin options individually, you can provide the necessary fields to certain plugins, i.e. `customCss` for `@docusaurus/theme-classic`, pass them in the preset field, like this:

Expand Down

0 comments on commit 9247332

Please sign in to comment.