-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
fix: filter out draft item from glob result #5612
Conversation
🦋 Changeset detectedLatest commit: a138bdc The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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 @equt.
Could we make this configurable via an option to the rss()
function? Or perhaps follow the top-level markdown.drafts
option although not sure we can easily access that in this context.
I know some people like to do stuff like include drafts when running astro dev
to test stuff out, but exclude them in astro build
, so making this configurable would support that use case.
Agree with that, but I can't figure out a way to get that option in the top-level config unless we parse the 🤔 How about we take a step back instead? Rather than filtering for the user, we expose the import rss from '@astrojs/rss';
const postImportResult = import.meta.glob('../posts/**/*.md', { eager: true });
const posts = Object.values(postImportResult);
export const get = () => rss({
title: 'Buzz’s Blog',
description: 'A humble Astronaut’s guide to the stars',
site: import.meta.env.SITE,
items: posts.map((post) => ({
link: post.url,
title: post.frontmatter.title,
pubDate: post.frontmatter.pubDate,
})).filter((post) => {
switch (import.meta.env.MODE) {
case 'production':
return !post.draft
default:
return true
}
})
}); |
There's really no need to expose anything in const postImportResult = import.meta.glob('./posts/**/*.{md,mdx}', { eager: true });
const posts = Object.values(postImportResult).filter((post) => import.meta.env.DEV || !post.frontmatter.draft); If anything, I'd personally prefer const posts = (await getCollection('blog', ({ data }) => {
return import.meta.env.DEV || !data.draft
})); |
Indeed, we don't need to expose the
Considering the markdown integration has already hardcoded this, I guess most users will just go with it.
We have to do something by default. Users who have put the |
Fair enough if we can’t get the top-level Markdown config option. In that case I’d still suggest adding an option to the import rss from '@astrojs/rss';
export const get = () => rss(
drafts: true, // Include drafts
// other options ...
}); |
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.
Nice! LGTM — thanks @equt 🙌
Would love a second opinion from the core team on whether this is in fact a major bump (the safe choice) or if we can get away with calling this a bug fix.
@@ -28,6 +28,8 @@ type RSSOptions = { | |||
stylesheet?: string | boolean; | |||
/** Specify custom data in opening of file */ | |||
customData?: string; | |||
/** Whether to include drafts or not */ | |||
drafts?: boolean; |
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.
nit: I'd prefer the name includeDrafts
for naming a boolean option
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 like this but it would then be inconsistent with our own markdown config which uses drafts: true
to build draft files as pages.
I guess we could also rename the markdown flag in the future although markdown.includeDrafts
is a less obvious home run in terms of naming.
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.
Fair enough! I personally didn't make the connection between the markdown config and the RSS config, so the different naming didn't bother me. I'm okay keeping it as drafts
if it makes documentation easier.
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.
Left a nit on naming, but I'm happy with this PR's final draft
!
To be a good semver samaritan, I'd stick with a major
for this one. We could switch the default of includeDrafts
to true
if we want to merge as a patch. Still, we'd probably flip back to false
soon after for a major release, so that doesn't seem appealing to me.
@fflaten Great point on Content Collections! I think the RSS integration will see some changes as content collections are more widely adopted. A loose set of ideas:
import { rssSchema } from '@astrojs/rss';
const blog = defineCollection({
schema: {
...rssSchema,
/* other properties you may want */
}
}); Excited to work on this more with the community! |
This looks great! One quick note on the semver question - this should either be a The second option is backwards compatible, but since it's really a new feature instead of a bug fix it's better to avoid using a |
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.
Approving the README on behalf of Astro Docs Maintainers! 🥳
Changes
draft
in the Markdown/MDX frontmatterTesting
A corresponding test has been added to ensure that any Markdown/MDX has
draft: true
in its frontmatter will be ignored, and a missing one orfalse
will not.Docs
I'm not sure if this is a new feature or just a fix. Maybe we should add a note in the RSS doc?
/cc @withastro/maintainers-docs