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(v2): enable feeds by default in blog plugin #3842

Merged
merged 7 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ test('should convert all feed type to array with other feed type', () => {
});
});

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'},
});
});

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good

Can you please add a test to ensure that type: null leads to type: null after validation? To ensure it's not using default values as a fallback?

describe('blog sidebar', () => {
test('should accept 0 sidebar count', () => {
const userOptions = {blogSidebarCount: 0};
Expand Down
21 changes: 14 additions & 7 deletions packages/docusaurus-plugin-content-blog/src/pluginOptionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@docusaurus/utils-validation';

export const DEFAULT_OPTIONS = {
feedOptions: {},
feedOptions: {type: ['rss', 'atom']},
beforeDefaultRehypePlugins: [],
beforeDefaultRemarkPlugins: [],
admonitions: {},
Expand Down Expand Up @@ -76,12 +76,19 @@ 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],
),
},
),
)
.default(DEFAULT_OPTIONS.feedOptions.type),
title: Joi.string().allow(''),
description: Joi.string().allow(''),
copyright: Joi.string(),
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-blog/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface PluginOptions {
truncateMarker: RegExp;
showReadingTime: boolean;
feedOptions: {
type: [FeedType];
type?: [FeedType];
title?: string;
description?: string;
copyright: string;
Expand Down
4 changes: 2 additions & 2 deletions website/docs/blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we now generate feeds by default, can you document how to disable the feed generation?


```ts
feedOptions?: {
type: 'rss' | 'atom' | 'all';
type?: 'rss' | 'atom' | 'all' | null;
title?: string;
description?: string;
copyright: string;
Expand Down