withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
45.59k stars 2.39k forks source link

The RSS spec does not require an item title, but astrojs/rss does #9577

Closed robmen closed 8 months ago

robmen commented 8 months ago

Astro Info

Astro                    v4.0.8
Node                     v20.10.0
System                   Windows (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

The RSS specification calls out that the item title is optional if the item description is present:

All elements of an item are optional, however at least one of title or description must be present. -- https://cyber.harvard.edu/rss/rss.html#hrelementsOfLtitemgt

However the rss() in astro requires an title:

08:49:48 λ src/pages/blog/rss.xml.js
08:49:48   └─ /blog/rss.xml[RSS] Invalid or missing options:
Invalid input (items)
The `items` property requires properly typed `title`, `pubDate`, and `link` keys.
Check your collection's schema, and visit https://docs.astro.build/en/guides/rss/#generating-items for more info.

What's the expected result?

Do not require a title element for RSS items if a description element is present.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-aoal5a?file=src%2Fcontent%2Fblog%2Fpost-only-desc.md

Participation

bluwy commented 8 months ago

All elements of an item are optional, however at least one of title or description must be present. -- cyber.harvard.edu/rss/rss.html#hrelementsOfLtitemgt

If I understand this correctly, it means that if an item has no elements (because it's optional), then at least a title or description needs to exist. It doesn't mean that on a proper formed item with title, link, and description, you can choose either a title or description to exist.

Plus I think it's fair for Astro to enforce some defaults here to generate a better RSS feed. pubDate is also optional per the spec, but Astro enforces it. So I'm leaning towards this not being an issue.

robmen commented 8 months ago

If I understand this correctly, it means that if an item has no elements (because it's optional), then at least a title or description needs to exist.

Correct.

It doesn't mean that on a proper formed item with title, link, and description, you can choose either a title or description to exist.

This is not correct. The designer of the RSS specifications, Dave Winer - @scripting, regularly calls out that RSS items should not require titles. It is an important distinction he makes.

Title-less RSS items allow one to build a (for lack of a better word) "micro-blogging" site like Twitter or Bluesky. In fact, Bluesky already produces RSS feeds for users and they do not have titles.

I hit this issue when attempting to build a textcasting system using Astro. Textcasting is a (IMHO) honorable effort by @scripting to reboot blogging and personal publication. Title-less posts are specifically called out twice:

Titles are optional. Any post can have a title, or not. If you're writing something like a quick social media post, there's no need for a title. But if you're writing something longer, you might need one. It must be up to the writer to decide if a post gets a title. https://textcasting.org/#1683634956000 ... For example, there was a time when the leading feed reader app required posts to have titles, and the leading microblogging site said they couldn't have them. That meant not only didn't they share data, they couldn't. https://textcasting.org/#1670873252000

Please do not close this as a non-issue. I really hope that rss() would be capable of following the RSS spec.

scripting commented 8 months ago

You don't have to go by what I say, it's very clear in the RSS 2.0 spec.

All elements of an item are optional, however at least one of title or description must be present.

It was put there so that writers could choose whether an item required a title or not. The idea was to empower the writer, as it is with textcasting, as you note.

florian-lefebvre commented 8 months ago

This happens at https://github.com/withastro/astro/blob/main/packages/astro-rss/src/schema.ts#L3

robmen commented 8 months ago

I guessed that was the problem. Unfortunately, my Zod-fu is not strong enough to know how to represent "at least one of" across multiple fields.

I am interested in the solution because I have a similar case in my own config.ts.

In my config.ts, I made all the fields .optional() and gave up on the validation. 😢 I suppose that could be an option here, but I expect you all know much more about Zod than I do and might know a way to maintain the validation.

bluwy commented 8 months ago

I took another look at the spec, and I think I was confused between a "channel" and an "item" where both have overlapping sub-elements that are required/optional. So I suppose we can loosen up the schema for "item" in Astro today. But on top of allowing either title and description, we should also make pubDate and link optional, and adjust the error message.