Skip to content

Commit cb3684b

Browse files
Edit: make RSS canonicalUrl required (#453)
* edit: make RSS canonicalUrl required * refactor: rename "canonicalUrl" to "site" * import and use ImportMetaEnv component (#454) @bholmesdev - please check this, and adjust as necessary to get it to render properly. This might require fiddling, but the ideas are: 1. Where ever you're seeing {{}} in the preview render instead of import.meta.env, then you need to import (I've done) and use (I've done) this component instead of typing the phrase out directly. The rest of the expression can be passed as the`path=" "` attribute, and it will be formatted as code. 2. This component must be inside an HTML element, and can't be written inside regular Markdown. I've tried the simplest version first (just <p> tags around the line it's in). If this isn't sufficient, or screws up the rest of the rendering, then you'll have to "work your way out" converting larger and larger chunks to HTML until you have the rendering you need. (Or, you figure out whether it's ABSOLUTELY NECESSARY to write the phrase import.meta.env. Dealer's choice.) Hope this helps. Co-authored-by: Ben Holmes <[email protected]> * fix: slay import.meta.env demon the cheap way * chore: remove unused import Co-authored-by: Sarah Rainsberger <[email protected]>
1 parent b0b6889 commit cb3684b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/pages/en/guides/rss.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ yarn add @astrojs/rss
2121
pnpm i @astrojs/rss
2222
```
2323

24-
Then, ensure you've [configured a `site`](/en/reference/configuration-reference/#site) in your project's `astro.config`. We will use this to generate links in your RSS feed.
24+
Then, ensure you've [configured a `site`](/en/reference/configuration-reference/#site) in your project's `astro.config`. You will use this to generate links in your RSS feed [via the `SITE` environment variable](/en/guides/environment-variables/#default-environment-variables).
25+
26+
> Note: The `SITE` environment variable only exists in the latest Astro 1.0 beta. Either upgrade to the latest version of Astro (`astro@latest`), or write your `site` manually if this isn't possible (see examples below).
2527
2628
Now, let's generate our first RSS feed! Create an `rss.xml.js` file under your `src/pages/` directory. `rss.xml` will be the output URL, so feel free to rename this if you prefer.
2729

28-
Now, import the `rss` helper from the `@astrojs/rss` package and call with the following parameters:
30+
Next, import the `rss` helper from the `@astrojs/rss` package and call with the following parameters:
2931

3032
```js
3133
// src/pages/rss.xml.js
@@ -36,6 +38,9 @@ export const get = () => rss({
3638
title: 'Buzz’s Blog',
3739
// `<description>` field in output xml
3840
description: 'A humble Astronaut’s guide to the stars',
41+
// base URL for RSS <item> links
42+
// SITE will use "site" from your project's astro.config.
43+
site: import.meta.env.SITE,
3944
// list of `<item>`s in output xml
4045
// simple example: generate items for every md file in /src/pages
4146
// see "Generating items" section for required frontmatter and advanced use cases
@@ -64,6 +69,7 @@ import rss from '@astrojs/rss';
6469
export const get = () => rss({
6570
title: 'Buzz’s Blog',
6671
description: 'A humble Astronaut’s guide to the stars',
72+
site: import.meta.env.SITE,
6773
items: import.meta.glob('./blog/**/*.md'),
6874
});
6975
```
@@ -86,6 +92,7 @@ const posts = Object.values(postImportResult);
8692
export const get = () => rss({
8793
title: 'Buzz’s Blog',
8894
description: 'A humble Astronaut’s guide to the stars',
95+
site: import.meta.env.SITE,
8996
items: posts.map((post) => ({
9097
link: post.frontmatter.slug,
9198
title: post.frontmatter.title,

0 commit comments

Comments
 (0)