Skip to content

Commit

Permalink
Update: remove deprecated getStaticPaths helper from RSS page (with…
Browse files Browse the repository at this point in the history
…astro#679)

Co-authored-by: Chris Swithinbank <[email protected]>
  • Loading branch information
bholmesdev and delucis authored Jun 3, 2022
1 parent a0cf158 commit 347976f
Showing 1 changed file with 5 additions and 51 deletions.
56 changes: 5 additions & 51 deletions src/pages/en/guides/rss.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ i18nReady: true

Astro supports fast, automatic RSS feed generation for blogs and other content websites. For more information about RSS feeds in general, see [aboutfeeds.com](https://aboutfeeds.com/).

## Using `@astrojs/rss` (recommended)
## Setting up `@astrojs/rss`

The `@astrojs/rss` package provides helpers for generating RSS feeds using [API endpoints](/en/core-concepts/astro-pages/#non-html-pages). This unlocks both static builds _and_ on-demand generation when using an [SSR adapter](/en/guides/server-side-rendering/#enabling-ssr-in-your-project).

Expand Down Expand Up @@ -51,13 +51,13 @@ export const get = () => rss({
});
```

### Generating `items`
## Generating `items`

The `items` field accepts either:
1. [An `import.meta.glob(...)` result](#1-importmetaglob-result) **(only use this for `.md` files within the `src/pages/` directory!)**
2. [A list of RSS feed objects](#2-list-of-rss-feed-objects), each with a `link`, `title`, `pubDate`, and optional `description` and `customData` fields.

#### 1. `import.meta.glob` result
### 1. `import.meta.glob` result

We recommend this option as a convenient shorthand for `.md` files under `src/pages/`. Each post should have a `title`, `pubDate`, and optional `description` and `customData` fields in its frontmatter. If this isn't possible, or you'd prefer to generate this frontmatter in code, [see option 2](#2-list-of-rss-feed-objects).

Expand All @@ -77,7 +77,7 @@ export const get = () => rss({

See [Vite's glob import documentation](https://vitejs.dev/guide/features.html#glob-import) for more on this import syntax.

#### 2. List of RSS feed objects
### 2. List of RSS feed objects

We recommend this option for `.md` files outside of the `pages` directory. This is common when generating routes [via `getStaticPaths`](/en/reference/api-reference/#getstaticpaths).

Expand All @@ -102,7 +102,7 @@ export const get = () => rss({
});
```

### Adding a stylesheet
## Adding a stylesheet

You can style your RSS feed for a more pleasant user experience when viewing the file in your browser.

Expand All @@ -117,49 +117,3 @@ rss({
```

If you don't have an RSS stylesheet in mind, we recommend the [Pretty Feed v3 default stylesheet](https://github.com/genmon/aboutfeeds/blob/main/tools/pretty-feed-v3.xsl), which you can download from GitHub and save into your project's `public/` directory.

## Using `getStaticPaths()`

> **Note:** This method has been deprecated, and will be removed before the official `v1.0.0` release. Please use `@astrojs/rss` instead.
You can also create an RSS feed from any Astro page that uses a `getStaticPaths()` function for routing. Only dynamic routes can use `getStaticPaths()` today (see [Routing](/en/core-concepts/routing/)).

Create an RSS Feed by calling the `rss()` function that is passed as an argument to `getStaticPaths()`. This will create an `rss.xml` file in your final build (or whatever you specify using `dest`) based on the data that you provide using the `items` array.

```js
// Example: /src/pages/posts/[...page].astro
// Place this function inside your Astro component script.
export async function getStaticPaths({rss}) {
const allPosts = await Astro.glob('../post/*.md');
const sortedPosts = allPosts.sort((a, b) => Date.parse(b.frontmatter.date) - Date.parse(a.frontmatter.date));
// Generate an RSS feed from this collection
rss({
// The RSS Feed title, description, and custom metadata.
title: 'Don’s Blog',
// See "Adding a stylesheet" section below
stylesheet: true,
description: 'An example blog on Astro',
customData: `<language>en-us</language>`,
// The list of items for your RSS feed, sorted.
items: sortedPosts.map(item => ({
title: item.frontmatter.title,
description: item.frontmatter.description,
link: item.url,
pubDate: item.frontmatter.date,
})),
// Optional: Customize where the file is written to.
// Otherwise, defaults to "/rss.xml"
dest: '/my/custom/feed.xml',
});
// Return your paths
return [...];
}
```

Note: RSS feeds will **not** be built during development when using this method.

### Adding a stylesheet

When using the `getStaticPaths` method to RSS, we will optionally generate a stylesheet for you. Pass `stylesheet: true` as an option to pull in the [Pretty Feed](https://github.com/genmon/aboutfeeds/blob/main/tools/pretty-feed-v3.xsl) XSL stylesheet.

If you'd like to use a custom XSL stylesheet, you can pass a string value like `stylesheet: '/my-custom-stylesheet.xsl'`. This file should be in your `public/` directory (in this case, `/public/my-custom-stylesheet.xsl`).

0 comments on commit 347976f

Please sign in to comment.