diff options
author | 2023-03-13 17:34:23 -0400 | |
---|---|---|
committer | 2023-03-13 17:34:23 -0400 | |
commit | 400ef26c998a586b29c2f3931e63c1c5801d3bea (patch) | |
tree | cba2b363f228f29f35f4123a8a63716a1d8a1b1d | |
parent | 43daac7a9b4cc793369bbeb3f722f8de9d8f64c8 (diff) | |
download | astro-400ef26c998a586b29c2f3931e63c1c5801d3bea.tar.gz astro-400ef26c998a586b29c2f3931e63c1c5801d3bea.tar.zst astro-400ef26c998a586b29c2f3931e63c1c5801d3bea.zip |
[RSS] Fix: Preserve self-closing tags in `customData` (#6538)
* fix: preserve self-closing tags in customData
* test: self-closing tags preserved
* chore: changeset
-rw-r--r-- | .changeset/lazy-elephants-relate.md | 5 | ||||
-rw-r--r-- | packages/astro-rss/src/index.ts | 8 | ||||
-rw-r--r-- | packages/astro-rss/test/rss.test.js | 17 |
3 files changed, 29 insertions, 1 deletions
diff --git a/.changeset/lazy-elephants-relate.md b/.changeset/lazy-elephants-relate.md new file mode 100644 index 000000000..7e9095dbb --- /dev/null +++ b/.changeset/lazy-elephants-relate.md @@ -0,0 +1,5 @@ +--- +'@astrojs/rss': patch +--- + +Preserve self-closing tags in `customData` option diff --git a/packages/astro-rss/src/index.ts b/packages/astro-rss/src/index.ts index 35bf5f613..7764b5d13 100644 --- a/packages/astro-rss/src/index.ts +++ b/packages/astro-rss/src/index.ts @@ -142,7 +142,13 @@ async function generateRSS(rssOptions: ValidatedRSSOptions): Promise<string> { ? rssOptions.items : rssOptions.items.filter((item) => !item.draft); - const xmlOptions = { ignoreAttributes: false }; + const xmlOptions = { + ignoreAttributes: false, + // Avoid correcting self-closing tags to standard tags + // when using `customData` + // https://github.com/withastro/astro/issues/5794 + suppressEmptyNode: true, + }; const parser = new XMLParser(xmlOptions); const root: any = { '?xml': { '@_version': '1.0', '@_encoding': 'UTF-8' } }; if (typeof rssOptions.stylesheet === 'string') { diff --git a/packages/astro-rss/test/rss.test.js b/packages/astro-rss/test/rss.test.js index d519d19ca..be4362a34 100644 --- a/packages/astro-rss/test/rss.test.js +++ b/packages/astro-rss/test/rss.test.js @@ -92,6 +92,23 @@ describe('rss', () => { chai.expect(body).xml.to.equal(validXmlWithXSLStylesheet); }); + it('should preserve self-closing tags on `customData`', async () => { + const customData = + '<atom:link href="https://example.com/feed.xml" rel="self" type="application/rss+xml"/>'; + const { body } = await rss({ + title, + description, + items: [], + site, + xmlns: { + atom: 'http://www.w3.org/2005/Atom', + }, + customData, + }); + + chai.expect(body).to.contain(customData); + }); + it('should filter out entries marked as `draft`', async () => { const { body } = await rss({ title, |