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

Conversation

cindygu4
Copy link
Contributor

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 in pluginOptionSchema.test.ts and passed all unit tests.

Related PRs

No

@facebook-github-bot
Copy link
Contributor

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!

@netlify
Copy link

netlify bot commented Nov 29, 2020

✔️ Deploy preview for docusaurus-2 ready!
Built without sensitive environment variables

🔨 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

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Nov 29, 2020
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@cindygu4 cindygu4 changed the title feat(v2): enables feeds by default in blog plugin feat(v2): enable feeds by default in blog plugin Nov 29, 2020
Copy link
Contributor

@nickserv nickserv left a 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).

Comment on lines 50 to 53
expect(value).toEqual({
...userOptions,
feedOptions: {type: ['rss', 'atom']},
});
Copy link
Contributor

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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes

Copy link
Contributor Author

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

Copy link
Collaborator

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

Copy link
Contributor Author

@cindygu4 cindygu4 Nov 30, 2020

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?

Copy link
Collaborator

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"

Copy link
Contributor Author

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 :)

Copy link
Collaborator

@slorber slorber left a 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']),
Copy link
Collaborator

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

Copy link
Contributor Author

@cindygu4 cindygu4 Nov 30, 2020

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
Screen Shot 2020-11-30 at 9 19 12 AM
Screen Shot 2020-11-30 at 9 23 20 AM

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!

Copy link
Collaborator

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

Copy link
Contributor Author

@cindygu4 cindygu4 Nov 30, 2020

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.

@slorber
Copy link
Collaborator

slorber commented Nov 30, 2020

Also: if we enable these feeds by default, is it still possible to disable them?
Can we be sure that passing null or something can actually disable the feeds with a test?

As @nickmccurdy mentioned we should also add/update appropriate doc for this

committing a failed attempt for review
@nickserv
Copy link
Contributor

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
@github-actions
Copy link

github-actions bot commented Dec 4, 2020

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 57
🟢 Accessibility 99
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-3842--docusaurus-2.netlify.app/classic/

@github-actions
Copy link

github-actions bot commented Dec 4, 2020

Size Change: +16 B (0%)

Total Size: 154 kB

ℹ️ View Unchanged
Filename Size Change
website/build/blog/2017/12/14/introducing-docusaurus/index.html 20.7 kB -2 B (0%)
website/build/docs/introduction/index.html 180 B 0 B
website/build/index.html 5.82 kB -1 B
website/build/main.********.js 109 kB +19 B (0%)
website/build/styles.********.css 17.5 kB 0 B

compressed-size-action

- added documentation for feedOptions
Copy link
Collaborator

@slorber slorber left a 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'},
});
});

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?

@@ -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?

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
@cindygu4 cindygu4 requested a review from slorber December 7, 2020 18:40
@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Dec 10, 2020
@slorber
Copy link
Collaborator

slorber commented Dec 10, 2020

thanks, LGTM 👍

seems it was not a bad idea to add a test for disabling the feed 😉

@slorber slorber merged commit 0b05806 into facebook:master Dec 10, 2020
@slorber slorber linked an issue Dec 10, 2020 that may be closed by this pull request
@slorber slorber added the pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. label Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

V2: Enable feeds by default in blog plugin
4 participants