-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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(content-docs): draft docs excluded from build & sidebars #6457
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-6457--docusaurus-2.netlify.app/ |
Thanks @jodyheavener 👍 will review this asap but I'm busy trying to complete another pr |
6f2a685
to
e5a7e06
Compare
@slorber Any chances this could be shipped soon :) ? |
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 nice 👍
Is having 2 booleans the best frontmatter model?
Is "unlisted" the best term? Maybe hidden or secret can also be nice?
Can you add tests to the _dogfooding
folder please so that we can review this more easily?
https://docusaurus.io/tests/docs
- autogen: normal doc + draft + unlisted
- explicit sidebar: normal doc + draft + unlisted
I'd also like to have cases covering draft/unlisted on category link / index docs (explicit or autogen)
What if autogen + category/index.md
has draft: true
for example? We should probably "erase" the link from the sidebar category in this case (+ tests 😉 )
We want feature parity with docs and blog, and keep PRs small.
Maybe it is better to split this in 2: one PR for draft, one for unlisted?
Later we'll add another PR for unlisted on both blog + docs?
For "unlisted" we need to figure out sitemaps + noIndex + eventually find a way to remove links for navbar/footer.... there are more edge cases to consider and more code to write 😉 I think docs drafts can land sooner so it's worth it to split this
packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts
Outdated
Show resolved
Hide resolved
packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/draft.md
Outdated
Show resolved
Hide resolved
packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts
Outdated
Show resolved
Hide resolved
packages/docusaurus-plugin-content-docs/src/sidebars/processor.ts
Outdated
Show resolved
Hide resolved
533b849
to
d9039c2
Compare
c6b0996
to
06dce4c
Compare
@slorber Thanks for your review, and apologies for the delay in updates! I went ahead and removed the whole Also, I added a couple dogfooding tests (hope I did this correctly), one explicitly in the sidebar, and one through the auto-gen sidebar, just keep in mind that they will only be visible locally :) |
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'm not quite sure what the semantic of draft
is. If we are to totally ignore it in production, I think we should just filter it out upfront and completely pretend it doesn't exist.
packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts
Outdated
Show resolved
Hide resolved
06dce4c
to
3baa532
Compare
3baa532
to
94300f4
Compare
@Josh-Cena Thanks for the review! I renamed everything from As for your point about filtering draft docs out earlier so we don't need to filter them out of the sidebar: I have spent some time playing with this and it seems like the problem is that you wouldn't be able to keep the doc referenced in a sidebar config while it's in draft. For example, in my dogfooding setup I have a draft doc that is manually defined in the sidebar, but when I build I get:
Which makes sense since Docusaurus doesn't know about this doc anymore in production as it was filtered out. Do you see a way around this? (My most recent push is going to fail because of this build failure - I will revert the commits if we decide not to go this route) |
# Conflicts: # packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap
We have to keep the draft in the list so that we can keep the fail-fast behavior of the sidebar when a doc id typo is met => we don't want to filter all unknown docIds from the sidebar, but we want to filter only draft ids (so we need to know which docs exactly are drafts Also knowing which docids are draft might be useful in other places like filtering navbar items |
…t early filtering
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.
LGTM now 👍
Any opinion before I merge next week?
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.
Some random thoughts:
useLayoutVersion
anduseLayoutSidebar
may returnnull
as well, if the entire version / entire sidebar are drafts? What should be the UX here?- Need some more docs
IMHO inferring a category full of drafts as a draft is already a quite fancy edge-case. If this becomes a feature that users clearly rely on, maybe we can have first class support to mark a category as draft, but current code is good enough? Also if a category is full of drafts, then drafts will be removed, it will then be empty and empty categories are filered. IE a sidebar full of draft is not filtered, but may end-up being entirely empty: Eventually we could filter the sidebar and also navbar items of type "docSidebar"? Not sure it's worth implementing today, but we can see if someone come up with a need for that, and maybe we'll allow adding a For versions, it's already possible to filter versions in the config file with IMHO this PR is good enough in current state. Added the filtering to dogfood a bit but it's not 100% related to draft frontmatter. Now if you want to add navbar items filtering for docSidebar + docsVersion in another PRs I'm fine with that 👍 |
I was mainly talking about the |
# Conflicts: # packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts
👍 Seems good enough for now
Agree, but the blog feature does not document that either outside the ref API so I did the same for consistency We could also add a draft feature to md pages and maybe created a dedicated guide to describe better this feature that would work on all 3 content plugins? (later it could also document "unlisted") Or do we add a section to each guide (or a small admonition tip?) As this doc change spans across multiple content plugins, let's do this in another PR after we decide what's best |
Motivation
The
plugin-content-docs
plugin does not currently provide a way for documents to be worked on while remaining hidden to visitors of the site. Its sibling plugin,plugin-content-blog
provides this via thedraft
frontmatter property, which excludes the blog post from builds. This PR aims to reach parity with the blog plugin and introduce this functionality as well.draft
Use case:
Marking a document with
draft: true
...Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
First, create a new document with any content you wish. Add this document to a sidebar manually (or set up a sidebar to auto generate). This document should be visible in development and production builds.
To test
draft
...draft: true
to the document's frontmatter, and save it.Related PRs
Closes #3417
🗺 I looked into how this impacts the sitemaps plugin, and for
draft
no extra work is necessary as these documents are already filtered out inroutes.ts
, preventing their page from being created and passing the route down to the plugin.