From 69ba84400b3a0ef585a18c28921b6ac5a28dae2b Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 5 May 2022 17:39:09 -0400 Subject: [PATCH] refactor: rename "canonicalUrl" to "site" --- packages/astro-rss/README.md | 6 +++--- packages/astro-rss/src/index.ts | 8 ++++---- packages/astro-rss/test/rss.test.js | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/astro-rss/README.md b/packages/astro-rss/README.md index 58120a05a894..931e9200b718 100644 --- a/packages/astro-rss/README.md +++ b/packages/astro-rss/README.md @@ -29,7 +29,7 @@ export const get = () => rss({ title: 'Buzz’s Blog', description: 'A humble Astronaut’s guide to the stars', // pull in the "site" from your project's astro.config - canonicalUrl: import.meta.env.SITE, + site: import.meta.env.SITE, items: import.meta.glob('./blog/**/*.md'), }); ``` @@ -47,7 +47,7 @@ rss({ // `` field in output xml description: 'A humble Astronaut’s guide to the stars', // provide a base URL for RSS links - canonicalUrl: import.meta.env.SITE, + site: import.meta.env.SITE, // list of ``s in output xml items: import.meta.glob('./**/*.md'), // (optional) absolute path to XSL stylesheet in your project @@ -71,7 +71,7 @@ Type: `string (required)` The `` attribute of your RSS feed's output xml. -### canonicalUrl +### site Type: `string (required)` diff --git a/packages/astro-rss/src/index.ts b/packages/astro-rss/src/index.ts index 80a75d87be08..5f7e63b892a6 100644 --- a/packages/astro-rss/src/index.ts +++ b/packages/astro-rss/src/index.ts @@ -13,7 +13,7 @@ type RSSOptions = { * We recommend "import.meta.env.SITE" to pull in the "site" * from your project's astro.config. */ - canonicalUrl: string; + site: string; /** * List of RSS feed items to render. Accepts either: * a) list of RSSFeedItems @@ -90,7 +90,7 @@ export default async function getRSS(rssOptions: RSSOptions) { /** Generate RSS 2.0 feed */ export async function generateRSS({ rssOptions, items }: GenerateRSSArgs): Promise { - const { canonicalUrl } = rssOptions; + const { site } = rssOptions; let xml = ``; if (typeof rssOptions.stylesheet === 'string') { xml += ``; @@ -109,7 +109,7 @@ export async function generateRSS({ rssOptions, items }: GenerateRSSArgs): Promi // title, description, customData xml += `<![CDATA[${rssOptions.title}]]>`; xml += ``; - xml += `${createCanonicalURL(canonicalUrl).href}`; + xml += `${createCanonicalURL(site).href}`; if (typeof rssOptions.customData === 'string') xml += rssOptions.customData; // items for (const result of items) { @@ -118,7 +118,7 @@ export async function generateRSS({ rssOptions, items }: GenerateRSSArgs): Promi // If the item's link is already a valid URL, don't mess with it. const itemLink = isValidURL(result.link) ? result.link - : createCanonicalURL(result.link, canonicalUrl).href; + : createCanonicalURL(result.link, site).href; xml += `${itemLink}`; xml += `${itemLink}`; if (result.description) xml += ``; diff --git a/packages/astro-rss/test/rss.test.js b/packages/astro-rss/test/rss.test.js index 9227b44ddb63..9962e83f94fe 100644 --- a/packages/astro-rss/test/rss.test.js +++ b/packages/astro-rss/test/rss.test.js @@ -6,7 +6,7 @@ chai.use(chaiPromises); const title = 'My RSS feed'; const description = 'This sure is a nice RSS feed'; -const canonicalUrl = 'https://example.com'; +const site = 'https://example.com'; const phpFeedItem = { link: '/php', @@ -34,7 +34,7 @@ describe('rss', () => { title, description, items: [phpFeedItem, web1FeedItem], - canonicalUrl, + site, }); chai.expect(body).to.equal(validXmlResult); @@ -71,7 +71,7 @@ describe('rss', () => { title, description, items: globResult, - canonicalUrl, + site, }); chai.expect(body).to.equal(validXmlResult); @@ -95,7 +95,7 @@ describe('rss', () => { title, description, items: globResult, - canonicalUrl, + site, }) ).to.be.rejected; }); @@ -118,7 +118,7 @@ describe('rss', () => { title, description, items: globResult, - canonicalUrl, + site, }) ).to.be.rejected; });