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
Drafts filtering behavior, configuration, flags, and docs needs cleanup. #7324
Comments
Thanks for sharing this @bradobro! Totally agree on conventions. This was a strong feature at launch that was slowly neglected by new features (content collections and sitemaps namely). We have a roadmap discussion repo where we propose ideas like this. I invite you to start a discussion there with the Proposal template! Should fit the background and proposal (which I see as goals) nicely. |
Thanks for opening such a detailed issue! @bholmesdev shared some insights into the history of this feature, and after discussing with the team we definitely agree that it's time to revisit |
Hey @natemoo-re and @bholmesdev thanks for the response. Travel has taken my attention from this a bit. Would you still like my comments about this feature in an existing discussion (or start one as @bholmesdev mentioned)? |
Draft posts show up in the sitemap with higher versions. There was a fix for filtering in general: withastro/astro#7263 But it didn't seem to fix drafts. There is a broader discussion for how to handle drafts: withastro/astro#7324
Draft posts show up in the sitemap with higher versions. There was a fix for filtering in general: withastro/astro#7263 But it didn't seem to fix drafts. There is a broader discussion for how to handle drafts: withastro/astro#7324
After much discussion with the team, we've made the decision to deprecate the Drafts were introduced back before Astro 1.0, when Astro was purely a static site generator and Despite this deprecation, we understand the need for previewing unpublished content. There is an ongoing roadmap discussion about supporting preview deployments for headless CMSs. Hopefully whatever eventual API emerges from that discussion can also accommodate local content. In the meantime, manually filtering your Content Collection posts using this approach is a perfectly valid way to implement drafts in userland. await getCollection("post", ({ data }) => import.meta.env.DEV || !data?.draft)) |
@bradobro if you'd like to start a dedicated discussion on our roadmap for what the future of draft support specifically could look like, we'd love to continue this conversation over there! Really appreciate the thought you've already put into this. |
What version of
astro
are you using?2.6.1
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
pnpm
What operating system are you using?
Mac
What browser are you using?
Firefox
Describe the Bug
This may simply be a problem with my understanding of the behavior or a clarification in the docs.
Background
I've looked at #440 and the docs regarding the
build --drafts
flag and the markdown.drafts configuration.It looks to me like:
--drafts
flag isn't wired in to code yetmarkdown.drafts
flag. AFAICT it's ignored by the collections API, the stock blog template, and other 3rd party templates (my stackblitz example only demonstrates that the draft pages are built whether or not the flag is present).Astro's collection API is a nice addition, and it prevents 1000 ad-hoc almost compatible similar implementations from sprouting up. The idea of having items in a collection that aren't ready for production (drafts) seems like a good thing to have a convention around.
Proposal
This will take some discussion, but to start the discussion, I propose that:
When an item is marked
draft
it is included in the by default inastro dev
and excluded by default inastro build
, which can be overridden byconfig.markdown.drafts
, which can be overridden by the--drafts
flag.When drafts are excluded, they're excluded everywhere. They don't exist--not their empty folders, their html, nor their RSS feeds. This prevents accidental info leaks and other embarrassments.
This behavior should be implemented in the collections API.
Next Steps
All those assertions are debatable, but I think form a good starting point. If we can agree on behavior and api, I'd be willing to submit a PR.
35055
Link to Minimal Reproducible Example
https://stackblitz.com/github/bradobro/astro-test-drafts?file=README.md
Participation
The text was updated successfully, but these errors were encountered: