diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/pluginOptionSchema.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/pluginOptionSchema.test.ts index 4390ab7b6dd7..d51736c00495 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/pluginOptionSchema.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/pluginOptionSchema.test.ts @@ -82,6 +82,34 @@ test('should convert all feed type to array with other feed type', () => { }); }); +test('should accept null type and return same', () => { + const {value, error} = PluginOptionSchema.validate({ + feedOptions: {type: null}, + }); + expect(value).toEqual({ + ...DEFAULT_OPTIONS, + feedOptions: {type: null}, + }); + expect(error).toBe(undefined); +}); + +test('should contain array with rss + atom for missing feed type', () => { + const {value} = PluginOptionSchema.validate({ + feedOptions: {}, + }); + expect(value).toEqual(DEFAULT_OPTIONS); +}); + +test('should have array with rss + atom, title for missing feed type', () => { + const {value} = PluginOptionSchema.validate({ + feedOptions: {title: 'title'}, + }); + expect(value).toEqual({ + ...DEFAULT_OPTIONS, + feedOptions: {type: ['rss', 'atom'], title: 'title'}, + }); +}); + describe('blog sidebar', () => { test('should accept 0 sidebar count', () => { const userOptions = {blogSidebarCount: 0}; diff --git a/packages/docusaurus-plugin-content-blog/src/pluginOptionSchema.ts b/packages/docusaurus-plugin-content-blog/src/pluginOptionSchema.ts index 25b36e4eda6c..fe396f180b39 100644 --- a/packages/docusaurus-plugin-content-blog/src/pluginOptionSchema.ts +++ b/packages/docusaurus-plugin-content-blog/src/pluginOptionSchema.ts @@ -14,7 +14,7 @@ import { } from '@docusaurus/utils-validation'; export const DEFAULT_OPTIONS = { - feedOptions: {}, + feedOptions: {type: ['rss', 'atom']}, beforeDefaultRehypePlugins: [], beforeDefaultRemarkPlugins: [], admonitions: {}, @@ -76,12 +76,20 @@ export const PluginOptionSchema = Joi.object({ DEFAULT_OPTIONS.beforeDefaultRehypePlugins, ), feedOptions: Joi.object({ - type: Joi.alternatives().conditional( - Joi.string().equal('all', 'rss', 'atom'), - { - then: Joi.custom((val) => (val === 'all' ? ['rss', 'atom'] : [val])), - }, - ), + type: Joi.alternatives() + .try( + Joi.array().items(Joi.string()), + Joi.alternatives().conditional( + Joi.string().equal('all', 'rss', 'atom'), + { + then: Joi.custom((val) => + val === 'all' ? ['rss', 'atom'] : [val], + ), + }, + ), + ) + .allow(null) + .default(DEFAULT_OPTIONS.feedOptions.type), title: Joi.string().allow(''), description: Joi.string().allow(''), copyright: Joi.string(), diff --git a/packages/docusaurus-plugin-content-blog/src/types.ts b/packages/docusaurus-plugin-content-blog/src/types.ts index 159ecd64afc1..4d1864b4ac11 100644 --- a/packages/docusaurus-plugin-content-blog/src/types.ts +++ b/packages/docusaurus-plugin-content-blog/src/types.ts @@ -51,7 +51,7 @@ export interface PluginOptions { truncateMarker: RegExp; showReadingTime: boolean; feedOptions: { - type: [FeedType]; + type?: [FeedType] | null; title?: string; description?: string; copyright: string; diff --git a/website/docs/blog.md b/website/docs/blog.md index bdca2a9f0b60..1906ee69f71a 100644 --- a/website/docs/blog.md +++ b/website/docs/blog.md @@ -89,11 +89,11 @@ Or this. ## Feed -You can generate RSS/ Atom feed by passing feedOptions. +You can generate RSS/Atom feed by passing feedOptions. By default, RSS and Atom feeds are generated. To disable feed generation, set `feedOptions.type` to `null`. ```ts feedOptions?: { - type: 'rss' | 'atom' | 'all'; + type?: 'rss' | 'atom' | 'all' | null; title?: string; description?: string; copyright: string;