Skip to content

Commit

Permalink
Edit: make RSS canonicalUrl required (#453)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
bholmesdev and sarah11918 authored May 5, 2022
1 parent b0b6889 commit cb3684b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/pages/en/guides/rss.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ yarn add @astrojs/rss
pnpm i @astrojs/rss
```

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.
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).

> 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).
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.

Now, import the `rss` helper from the `@astrojs/rss` package and call with the following parameters:
Next, import the `rss` helper from the `@astrojs/rss` package and call with the following parameters:

```js
// src/pages/rss.xml.js
Expand All @@ -36,6 +38,9 @@ export const get = () => rss({
title: 'Buzz’s Blog',
// `<description>` field in output xml
description: 'A humble Astronaut’s guide to the stars',
// base URL for RSS <item> links
// SITE will use "site" from your project's astro.config.
site: import.meta.env.SITE,
// list of `<item>`s in output xml
// simple example: generate items for every md file in /src/pages
// see "Generating items" section for required frontmatter and advanced use cases
Expand Down Expand Up @@ -64,6 +69,7 @@ import rss from '@astrojs/rss';
export const get = () => rss({
title: 'Buzz’s Blog',
description: 'A humble Astronaut’s guide to the stars',
site: import.meta.env.SITE,
items: import.meta.glob('./blog/**/*.md'),
});
```
Expand All @@ -86,6 +92,7 @@ const posts = Object.values(postImportResult);
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.frontmatter.slug,
title: post.frontmatter.title,
Expand Down

0 comments on commit cb3684b

Please sign in to comment.