From 4ce41566c4b6f536f8e2ea5c87458076bafd710d Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 13 Mar 2023 14:36:18 -0400 Subject: [PATCH 1/3] fix: preserve self-closing tags in customData --- packages/astro-rss/src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/astro-rss/src/index.ts b/packages/astro-rss/src/index.ts index 35bf5f6136fd..7764b5d132c5 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 { ? 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') { From e9dc5527df8c42cb6205235a9e40644a81fca67c Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 13 Mar 2023 14:36:30 -0400 Subject: [PATCH 2/3] test: self-closing tags preserved --- packages/astro-rss/test/rss.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/astro-rss/test/rss.test.js b/packages/astro-rss/test/rss.test.js index d519d19cabfa..be4362a34531 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 = + ''; + 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, From 931a0df249ded9c9bb335ff58ce5329616a0262c Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 13 Mar 2023 14:38:12 -0400 Subject: [PATCH 3/3] chore: changeset --- .changeset/lazy-elephants-relate.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lazy-elephants-relate.md diff --git a/.changeset/lazy-elephants-relate.md b/.changeset/lazy-elephants-relate.md new file mode 100644 index 000000000000..7e9095dbb8eb --- /dev/null +++ b/.changeset/lazy-elephants-relate.md @@ -0,0 +1,5 @@ +--- +'@astrojs/rss': patch +--- + +Preserve self-closing tags in `customData` option