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

@astrojs/rss includes drafts in output #5505

Closed
1 task done
SeanMcP opened this issue Dec 1, 2022 · 2 comments · Fixed by #5612
Closed
1 task done

@astrojs/rss includes drafts in output #5505

SeanMcP opened this issue Dec 1, 2022 · 2 comments · Fixed by #5612
Labels
- P2: has workaround Bug, but has workaround (priority) help wanted Please help with this issue!

Comments

@SeanMcP
Copy link

SeanMcP commented Dec 1, 2022

What version of astro are you using?

1.6.12

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

When an item is marked as a draft in the frontmatter, it is still included in the XML output. You can see this behavior in the default blog example.

They should be excluded by default, and ideally added based on integration configuration or build flags.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-exbbav?file=src%2Fpages%2Fblog%2Ffirst-post.md,dist%2Frss.xml&on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.
@matthewp matthewp added the - P3: minor bug An edge case that only affects very specific usage (priority) label Dec 1, 2022
@equt
Copy link
Contributor

equt commented Dec 9, 2022

I'm also looking into this issue and trying to figure out how it could be better. But to make it more intuitive, we might have to change how currently @astrojs/rss currently integrates with the main codebase.

Currently, there's no way for the RSS generator to get the metadata from the source.

items: RSSFeedItem[] | GlobResult;

Also, due to how @astrojs/rss is used, it could nor access the Astro config unless it parses it manually.

Are there any design considerations here? Is there any possibility of moving it into the integrations in the main config?

@delucis
Copy link
Member

delucis commented Dec 10, 2022

As a workaround, you can filter out the draft items from your import.meta.glob result before passing them to the RSS function:

import rss from '@astrojs/rss';

const postImportResult = import.meta.glob('../posts/**/*.md', { eager: true });
const posts = Object.values(postImportResult).filter(
  post => !post.frontmatter.draft
);

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,
  }))
});

Should also be fairly simple to add this logic to the RSS package directly:

  1. Include draft in the mapGlobResult return here:

    return {
    link: url,
    title: frontmatter.title,
    pubDate: frontmatter.pubDate,
    description: frontmatter.description,
    customData: frontmatter.customData,
    };

  2. Then filter out items with draft: true, maybe here:

    items = await mapGlobResult(items);

@delucis delucis added - P2: has workaround Bug, but has workaround (priority) help wanted Please help with this issue! and removed - P3: minor bug An edge case that only affects very specific usage (priority) labels Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) help wanted Please help with this issue!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants