yogthos / clj-rss

a library for generating RSS feeds
64 stars 16 forks source link

Attributes to items #23

Open wildwestrom opened 3 years ago

wildwestrom commented 3 years ago

I was just looking at this feed, https://hnrss.org/newest. There's an attribute to their guid tag called isPermaLink. I'd like to replicate that on my feed but it seems like the current API does not support this.

How might I go about adding this?

Example:

<item>
    <title></title>
    <description></description>
    <pubDate>Wed, 20 Oct 2021 19:47:33 +0000</pubDate>
    <link></link>
    <dc:creator>gmays</dc:creator>
    <comments>https://news.ycombinator.com/item?id=28935333</comments>
    <guid isPermaLink="false">https://news.ycombinator.com/item?id=28935333</guid>
</item>

(deftest test-attrs
  (is (= "<?xml version=\"1.0\" encoding=\"UTF-8\"?><rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"><channel><atom:link href=\"http://foo/bar\" rel=\"self\" type=\"application/rss+xml\"/><title>Foo</title><link>http://foo/bar</link><description>some channel</description><generator>clj-rss</generator><item><title>test</title><guid isPermaLink="false">http://foo/bar</guid></item></channel></rss>"
         (channel-xml {:title "Foo" :link "http://foo/bar" :description "some channel"}
                      {:title "test"
                       ;; How do we want to do this?
                       :guid "http://foo/bar"}))))
yogthos commented 3 years ago

There's no support for the guid tag at the moment, but I'd be open for a PR to add the functionality. It looks like the tag gets generated, but doesn't have the isPermaLink attribute set:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <atom:link href="http://foo/bar" rel="self" type="application/rss+xml"/>
    <title>Foo</title>
    <link>http://foo/bar</link>
    <description>some channel</description>
    <generator>clj-rss</generator>
    <item>
      <title>test</title>
      <guid>http://foo/bar</guid>
    </item>
  </channel>
</rss>

Should just be possible to add a bit of additional processing here to inject the attribute when the tag is generated.

yogthos commented 3 years ago

actually, looks like this should do the trick assuming isPermalink is always set to false. Might be easiest to add :guid-permalink as a separate tag to handle the other case if needed.