-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Conversation
Hi @cindygu4! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
✔️ Deploy preview for docusaurus-2 ready! 🔨 Explore the source changes: 0e25e50 🔍 Inspect the deploy logs: https://app.netlify.com/sites/docusaurus-2/deploys/5fce73e329a32a0007acd389 😎 Browse the preview: https://deploy-preview-3842--docusaurus-2.netlify.app |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to make the type
property optional in packages/docusaurus-plugin-content-blog/src/types.ts
, depending on how this plugin gets used with/without the schema. We should also update the documentation in website/docs/blog.md
and website/docs/using-plugins.md
(and possibly the versioned copies, though I'm not sure how those updates are handled in this repository).
expect(value).toEqual({ | ||
...userOptions, | ||
feedOptions: {type: ['rss', 'atom']}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be added to DEFAULT_OPTIONS
or userOptions
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I tried what you suggested when trying to resolve the issue with this unit test. However, it won't pass the test unless we add feedOptions: {type: ['rss', 'atom']}
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why exactly this test does not pass?
I can't tell you if I can't see the code, but what I'm sure of is that we 100% want to put default options in the DEFAULT_OPTIONS
constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now added type: 'all'
into DEFAULT_OPTIONS.feedOptions
and this test passes. I think it would still make sense to have this line of code here since it would convert type: 'all'
into the array (['rss', 'atom']
) right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cindygu4 I'd rather have type: ['rss', 'atom']
and allow the validation to work with arrays syntax, so that the default options are not "transformed"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion @slorber! @vikhramt007 and I have implemented the feature using the type: ['rss', 'atom']
as the default and allowed the validation to work with arrays. It now passes all of the unit tests :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, almost looks good
Use DEFAULT_OPTIONS to be consistent with the way we handle other default options
}) | ||
.empty(undefined) | ||
.empty(null) | ||
.default(['rss', 'atom']), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use DEFAULT_OPTIONS.feedOptions.type
, similarly to how we handle default options in other places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
I've tried setting DEFAULT_OPTIONS.feedOptions.type
to 'all'
as well as ['rss', 'atom']
and both give me these errors
Also, setting DEFAULT_OPTIONS.feedOptions.type
to ['rss', 'atom']
also gives me an additional error [ValidationError: "feedOptions.type" does not match any of the allowed types]
.
Do you have any suggestions as to how to resolve these? The only way I've found to make it work is by adding the empty() and default() methods within the Joi object.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't debug remotely code that I can't fully see, You'd rather commit your failed attempt and ask a new review.
Also, setting DEFAULT_OPTIONS.feedOptions.type to ['rss', 'atom'] also gives me an additional error [ValidationError: "feedOptions.type" does not match any of the allowed types].
You should make the validator accept an array for this to work, currently it only accept strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok yeah, I'll make another commit with the failed attempt.
Also: if we enable these feeds by default, is it still possible to disable them? As @nickmccurdy mentioned we should also add/update appropriate doc for this |
committing a failed attempt for review
Thanks, but it looks like the docs are still outdated (see #3842 (review)) |
- allow validation to work with arrays syntax - using DEFAULT_OPTIONS.feedOptions.type instead
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-3842--docusaurus-2.netlify.app/classic/ |
Size Change: +16 B (0%) Total Size: 154 kB ℹ️ View Unchanged
|
- added documentation for feedOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that looks good to me, just a few details left to ensure that we can still disable the feeds
feedOptions: {type: ['rss', 'atom'], title: 'title'}, | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
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?
website/docs/blog.md
Outdated
@@ -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. |
There was a problem hiding this comment.
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?
Merging master to check unit tests
- 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
thanks, LGTM 👍 seems it was not a bad idea to add a test for disabling the feed 😉 |
Motivation
As #3720 said, Docusaurus 2 extracts the blog into a separate plugin which means that blogs aren't enabled by default. However, feeds should probably be enabled by default in blog plugin.
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Locally tested using
yarn build:v2
to see if/blog/rss.xml
and/blog/atom.xml
exist when no type is specified. Created 2 unit tests inpluginOptionSchema.test.ts
and passed all unit tests.Related PRs
No