-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Adds extra elements to RSS items. #6707
Changes from 5 commits
bb1bf77
8c2ae61
bbc4171
0171fe1
21b1dca
e5d24c7
0ea5df3
b4daee6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -112,24 +112,7 @@ Type: `RSSFeedItem[] (required)` | |||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
A list of formatted RSS feed items. See [Astro's RSS items documentation](https://docs.astro.build/en/guides/rss/#generating-items) for usage examples to choose the best option for you. | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
When providing a formatted RSS item list, see the `RSSFeedItem` type reference below: | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
```ts | ||||||||||||||||||||||||||||||||||
type RSSFeedItem = { | ||||||||||||||||||||||||||||||||||
/** Link to item */ | ||||||||||||||||||||||||||||||||||
link: string; | ||||||||||||||||||||||||||||||||||
/** Title of item */ | ||||||||||||||||||||||||||||||||||
title: string; | ||||||||||||||||||||||||||||||||||
/** Publication date of item */ | ||||||||||||||||||||||||||||||||||
pubDate: Date; | ||||||||||||||||||||||||||||||||||
/** Item description */ | ||||||||||||||||||||||||||||||||||
description?: string; | ||||||||||||||||||||||||||||||||||
/** Full content of the item, should be valid HTML */ | ||||||||||||||||||||||||||||||||||
content?: string; | ||||||||||||||||||||||||||||||||||
/** Append some other XML-valid data to this item */ | ||||||||||||||||||||||||||||||||||
customData?: string; | ||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||
When providing a formatted RSS item list, see the [`RSSFeedItem` type reference below](#rssfeeditem). | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
### drafts | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
@@ -202,6 +185,112 @@ export const get = () => rss({ | |||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
## `RSSFeedItem` | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really like how well you've restructured the docs and how well you explained this |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
An `RSSFeedItem` is a single item in the list of items in your feed. It represents a story, with `link`, `title` and `pubDate` fields. There are further optional fields defined below. You can also check the definitions for the fields in the [RSS spec](https://validator.w3.org/feed/docs/rss2.html#ltpubdategtSubelementOfLtitemgt). | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
An example feed item might look like: | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
```js | ||||||||||||||||||||||||||||||||||
const item = { | ||||||||||||||||||||||||||||||||||
title: "Alpha Centauri: so close you can touch it", | ||||||||||||||||||||||||||||||||||
link: "/blog/alpha-centuari", | ||||||||||||||||||||||||||||||||||
pubDate: new Date("2023-06-04"), | ||||||||||||||||||||||||||||||||||
description: "Alpha Centauri is a triple star system, containing Proxima Centauri, the closest star to our sun at only 4.24 light-years away.", | ||||||||||||||||||||||||||||||||||
categories: ["stars", "space"] | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
### `title` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `string (required)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
The `<title>` attribute of the item in the feed. | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
### `link` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `string (required)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
The `<link>` attribute of the item in the feed containing the URL of the item on the web. | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
### `pubDate` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `Date (required)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Indicates when the item was published. | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
### `description` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `string (optional)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
If the item is complete within itself, that is you are publishing the full content of the item in the feed, the `description` field may contain the full text (entity-encoded HTML is permitted). If the item is a stub, then the `description` may contain a synopsis of the item. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I read a bit of backstory on this item, and it appears that the standard is terrible. 😅 In terms of describing this field, it is either one or the other, and if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, RSS is old and a mess! And feed readers have inconsistent implementations. Such fun! |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
### `content` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `string (optional)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
If you want to supply both a short description and also the full content in an item, set the `content` field to the full, encoded text. See the [recommendations from the RSS spec for how to use and differentiate between `description` and `content`](https://www.rssboard.org/rss-profile#namespace-elements-content-encoded). | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Something like this maybe? I prefer to start these descriptions by stating what they are, vs a "if you're doing this..." |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
### `categories` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `string[] (optional)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
If you use tags or categories to categorize your content, you can add them as the `categories` field. They will be output as multiple `<category>` elements. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
### `author` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `string (optional)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Useful for multi-author blogs, the `author` field provides the email address of the person who wrote the item. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It seems a little odd to me that author is an email address, and not just a name. So I'm just commenting on that here! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, but that's what the spec says. 🤷♂️ |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
### `commentsUrl` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `string (optional)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
The `commentsUrl` defines a URL of a web page that contains comments on the item. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
### `source` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `object (optional)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Items that are republished from other publications may define a `source` which defines the `title` and `url` of the original feed in which it was published. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I also think an example (choose one that makes sense, formatted properly!) would make sense here. |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
#### `title` | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I'm wondering if this is helpful, especially as a heading that might show up in Algolia if someone searches for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, thanks. |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `string (required)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
If you define a `source` you must define that source's `title`. It is the name of the original feed in which the item was published. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
#### `url` | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `string (required)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
If you define a `source` you must also define that source's `url` which identifies the URL of the original feed in which the item was published. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
### `enclosure` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `object (optional)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Items that include media as part of the feed, like a podcast, can define an `enclosure` which is made of three required fields, a `url`, `length`, and `type`. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I also think an example would be helpful here! Note, if the URL is from your own site, do you still need to use a full URL here? This is just an example. Adjust to make this correct! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The RSS spec says that you do need this to be a full URL. However, we can treat this like |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
#### `url` | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `string (required)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
The `url` field for the `enclosure` defines a URL where the media can be found. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
If you only need to use e.g. |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
#### `length` | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `number (required)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
The `length` field defines the size of the file found at the `url` in bytes. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
#### `type` | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Type: `string (required)` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
The `type` field defines the MIME type for the media item found at the `url`. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
## `rssSchema` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
When using content collections, you can configure your collection schema to enforce expected [`RSSFeedItem`](#items) properties. Import and apply `rssSchema` to ensure that each collection entry produces a valid RSS feed item: | ||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,18 @@ export const web1FeedItemWithContent = { | |
...web1FeedItem, | ||
content: `<h1>${web1FeedItem.title}</h1><p>${web1FeedItem.description}</p>`, | ||
}; | ||
export const web1FeedItemWithAllData = { | ||
...web1FeedItem, | ||
categories: ['web1', 'history'], | ||
author: '[email protected]', | ||
commentsUrl: 'http://example.com/comments', | ||
source: { | ||
url: 'http://example.com/source', | ||
title: 'The Web 1.0 blog', | ||
}, | ||
enclosure: { | ||
url: 'http://example.com/podcast.mp3', | ||
length: 256, | ||
type: 'audio/mpeg', | ||
}, | ||
}; |
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: the link name doesn't need to address the position in the page.