mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
feat(v2): enable feeds by default in blog plugin (#3842)
* feat: enables feeds by default in blog * feat(v2): enable feeds by default committing a failed attempt for review * feat(v2): enable feeds by default in blog plugin - allow validation to work with arrays syntax - using DEFAULT_OPTIONS.feedOptions.type instead * feat(v2): enable feeds by default in blog plugin - added documentation for feedOptions * feat(v2): enable feeds by default in blog plugin - modified implementation to allow feeds to be disable without error - added unit test to ensure type: null leads to type: null after validation - added documentation to explain how to disable feed generation
This commit is contained in:
parent
dd8f3257a8
commit
0b05806593
4 changed files with 46 additions and 10 deletions
|
@ -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};
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -51,7 +51,7 @@ export interface PluginOptions {
|
|||
truncateMarker: RegExp;
|
||||
showReadingTime: boolean;
|
||||
feedOptions: {
|
||||
type: [FeedType];
|
||||
type?: [FeedType] | null;
|
||||
title?: string;
|
||||
description?: string;
|
||||
copyright: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue