Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dc:creator #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/__tests__/__snapshots__/rss2.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ exports[`rss 2.0 should generate a valid feed 1`] = `
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<dc:creator><![CDATA[Joe Smith, Name Only]]></dc:creator>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure url=\\"https://example.com/hello-world.jpg\\" length=\\"0\\" type=\\"image/jpg\\"/>
Expand Down Expand Up @@ -66,6 +67,7 @@ exports[`rss 2.0 should generate a valid feed with audio 1`] = `
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<dc:creator><![CDATA[Joe Smith, Name Only]]></dc:creator>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure url=\\"https://example.com/hello-world.jpg\\" length=\\"0\\" type=\\"image/jpg\\"/>
Expand All @@ -79,6 +81,7 @@ exports[`rss 2.0 should generate a valid feed with audio 1`] = `
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<dc:creator><![CDATA[Joe Smith]]></dc:creator>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure length=\\"12665\\" type=\\"image/jpg\\" url=\\"https://example.com/hello-world.jpg\\"/>
Expand All @@ -92,6 +95,7 @@ exports[`rss 2.0 should generate a valid feed with audio 1`] = `
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<dc:creator><![CDATA[Joe Smith]]></dc:creator>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure length=\\"12665\\" type=\\"image/jpg\\" url=\\"https://example.com/hello-world.jpg\\"/>
Expand All @@ -105,6 +109,7 @@ exports[`rss 2.0 should generate a valid feed with audio 1`] = `
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<dc:creator><![CDATA[Joe Smith]]></dc:creator>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure length=\\"12665\\" type=\\"audio/mpeg\\" url=\\"https://example.com/hello-world.mp3\\"/>
Expand Down Expand Up @@ -142,6 +147,7 @@ exports[`rss 2.0 should generate a valid feed with enclosure 1`] = `
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<dc:creator><![CDATA[Joe Smith, Name Only]]></dc:creator>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure url=\\"https://example.com/hello-world.jpg\\" length=\\"0\\" type=\\"image/jpg\\"/>
Expand All @@ -155,6 +161,7 @@ exports[`rss 2.0 should generate a valid feed with enclosure 1`] = `
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<dc:creator><![CDATA[Joe Smith]]></dc:creator>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure length=\\"12665\\" type=\\"image/jpg\\" url=\\"https://example.com/hello-world.jpg\\"/>
Expand All @@ -168,6 +175,7 @@ exports[`rss 2.0 should generate a valid feed with enclosure 1`] = `
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<dc:creator><![CDATA[Joe Smith]]></dc:creator>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure length=\\"12665\\" type=\\"image/jpg\\" url=\\"https://example.com/hello-world.jpg\\"/>
Expand Down Expand Up @@ -205,6 +213,7 @@ exports[`rss 2.0 should generate a valid feed with image properties 1`] = `
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<dc:creator><![CDATA[Joe Smith, Name Only]]></dc:creator>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure url=\\"https://example.com/hello-world.jpg\\" length=\\"0\\" type=\\"image/jpg\\"/>
Expand All @@ -218,6 +227,7 @@ exports[`rss 2.0 should generate a valid feed with image properties 1`] = `
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<dc:creator><![CDATA[Joe Smith]]></dc:creator>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure length=\\"12665\\" type=\\"image/jpg\\" url=\\"https://example.com/hello-world.jpg\\"/>
Expand Down Expand Up @@ -254,6 +264,7 @@ exports[`rss 2.0 should generate a valid feed with video 1`] = `
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<dc:creator><![CDATA[Joe Smith]]></dc:creator>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure url=\\"https://example.com/hello-world.mp4\\" length=\\"0\\" type=\\"video/mp4\\"/>
Expand Down
1 change: 1 addition & 0 deletions src/rss2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export default (ins: Feed) => {
if (Array.isArray(entry.author)) {
item.author = [];
entry.author.map((author: Author) => {
item["dc:creator"] = { _cdata: author.name };
if (author.email && author.name) {
item.author.push({ _text: author.email + " (" + author.name + ")" });
}
Comment on lines 159 to 163

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
entry.author.map((author: Author) => {
item["dc:creator"] = { _cdata: author.name };
if (author.email && author.name) {
item.author.push({ _text: author.email + " (" + author.name + ")" });
}
item["dc:creator"] = [];
entry.author.map((author: Author) => {
if (author.email && author.name) {
item.author.push({ _text: author.email + " (" + author.name + ")" });
} else if (author.name) {
isDublinCore = true;
item["dc:creator"].push({ _cdata: author.name });
}

And up above:

  let isDublinCore = false;

And down below:

  if (isDublinCore) {
    base.rss._attributes["xmlns:dc"] = "http://purl.org/dc/elements/1.1/";
  }

Expand Down