Skip to content

Commit

Permalink
refactor: rename "canonicalUrl" to "site"
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed May 5, 2022
1 parent 4ebccf8 commit 69ba844
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions packages/astro-rss/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
});
```
Expand All @@ -47,7 +47,7 @@ rss({
// `<description>` field in output xml
description: 'A humble Astronaut’s guide to the stars',
// provide a base URL for RSS <item> links
canonicalUrl: import.meta.env.SITE,
site: import.meta.env.SITE,
// list of `<item>`s in output xml
items: import.meta.glob('./**/*.md'),
// (optional) absolute path to XSL stylesheet in your project
Expand All @@ -71,7 +71,7 @@ Type: `string (required)`

The `<description>` attribute of your RSS feed's output xml.

### canonicalUrl
### site

Type: `string (required)`

Expand Down
8 changes: 4 additions & 4 deletions packages/astro-rss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +90,7 @@ export default async function getRSS(rssOptions: RSSOptions) {

/** Generate RSS 2.0 feed */
export async function generateRSS({ rssOptions, items }: GenerateRSSArgs): Promise<string> {
const { canonicalUrl } = rssOptions;
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"?>`;
Expand All @@ -109,7 +109,7 @@ export async function generateRSS({ rssOptions, items }: GenerateRSSArgs): Promi
// title, description, customData
xml += `<title><![CDATA[${rssOptions.title}]]></title>`;
xml += `<description><![CDATA[${rssOptions.description}]]></description>`;
xml += `<link>${createCanonicalURL(canonicalUrl).href}</link>`;
xml += `<link>${createCanonicalURL(site).href}</link>`;
if (typeof rssOptions.customData === 'string') xml += rssOptions.customData;
// items
for (const result of items) {
Expand All @@ -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 += `<link>${itemLink}</link>`;
xml += `<guid>${itemLink}</guid>`;
if (result.description) xml += `<description><![CDATA[${result.description}]]></description>`;
Expand Down
10 changes: 5 additions & 5 deletions packages/astro-rss/test/rss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -34,7 +34,7 @@ describe('rss', () => {
title,
description,
items: [phpFeedItem, web1FeedItem],
canonicalUrl,
site,
});

chai.expect(body).to.equal(validXmlResult);
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('rss', () => {
title,
description,
items: globResult,
canonicalUrl,
site,
});

chai.expect(body).to.equal(validXmlResult);
Expand All @@ -95,7 +95,7 @@ describe('rss', () => {
title,
description,
items: globResult,
canonicalUrl,
site,
})
).to.be.rejected;
});
Expand All @@ -118,7 +118,7 @@ describe('rss', () => {
title,
description,
items: globResult,
canonicalUrl,
site,
})
).to.be.rejected;
});
Expand Down

0 comments on commit 69ba844

Please sign in to comment.