summaryrefslogtreecommitdiff
path: root/packages/astro-rss/src
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2022-05-05 18:03:25 -0400
committerGravatar GitHub <noreply@github.com> 2022-05-05 18:03:25 -0400
commit0efaf110fceba149cd41cbaa0f37311e6887cdec (patch)
treedcdb0b7b2ca89e024b57e66640ecaf7fc5044157 /packages/astro-rss/src
parent9b98633cc826c764cfd4aa4bf600ba973c17a8b9 (diff)
downloadastro-0efaf110fceba149cd41cbaa0f37311e6887cdec.tar.gz
astro-0efaf110fceba149cd41cbaa0f37311e6887cdec.tar.zst
astro-0efaf110fceba149cd41cbaa0f37311e6887cdec.zip
Fix: make RSS canonicalUrl required (#3301)
* chore: make canonicalUrl required * docs: explain env variable on required canonicalUrl * refactor: rename "canonicalUrl" to "site" * chore: changeset
Diffstat (limited to 'packages/astro-rss/src')
-rw-r--r--packages/astro-rss/src/index.ts22
1 files changed, 8 insertions, 14 deletions
diff --git a/packages/astro-rss/src/index.ts b/packages/astro-rss/src/index.ts
index c9e53f8ce..5f7e63b89 100644
--- a/packages/astro-rss/src/index.ts
+++ b/packages/astro-rss/src/index.ts
@@ -9,6 +9,12 @@ type RSSOptions = {
/** (required) Description of the RSS Feed */
description: string;
/**
+ * Specify the base URL to use for RSS feed links.
+ * We recommend "import.meta.env.SITE" to pull in the "site"
+ * from your project's astro.config.
+ */
+ site: string;
+ /**
* List of RSS feed items to render. Accepts either:
* a) list of RSSFeedItems
* b) import.meta.glob result. You can only glob ".md" files within src/pages/ when using this method!
@@ -22,11 +28,6 @@ type RSSOptions = {
stylesheet?: string | boolean;
/** Specify custom data in opening of file */
customData?: string;
- /**
- * Specify the base URL to use for RSS feed links.
- * Defaults to "site" in your project's astro.config
- */
- canonicalUrl?: string;
};
type RSSFeedItem = {
@@ -43,7 +44,6 @@ type RSSFeedItem = {
};
type GenerateRSSArgs = {
- site: string;
rssOptions: RSSOptions;
items: RSSFeedItem[];
};
@@ -76,19 +76,12 @@ function mapGlobResult(items: GlobResult): Promise<RSSFeedItem[]> {
}
export default async function getRSS(rssOptions: RSSOptions) {
- const site = rssOptions.canonicalUrl ?? (import.meta as any).env.SITE;
- if (!site) {
- throw new Error(
- `RSS requires a canonical URL. Either add a "site" to your project's astro.config, or supply the canonicalUrl argument.`
- );
- }
let { items } = rssOptions;
if (isGlobResult(items)) {
items = await mapGlobResult(items);
}
return {
body: await generateRSS({
- site,
rssOptions,
items,
}),
@@ -96,7 +89,8 @@ export default async function getRSS(rssOptions: RSSOptions) {
}
/** Generate RSS 2.0 feed */
-export async function generateRSS({ site, rssOptions, items }: GenerateRSSArgs): Promise<string> {
+export async function generateRSS({ rssOptions, items }: GenerateRSSArgs): Promise<string> {
+ const { site } = rssOptions;
let xml = `<?xml version="1.0" encoding="UTF-8"?>`;
if (typeof rssOptions.stylesheet === 'string') {
xml += `<?xml-stylesheet href="${rssOptions.stylesheet}" type="text/xsl"?>`;