gorilla / feeds

Package gorilla/feeds is a golang rss/atom generator library
https://gorilla.github.io
BSD 3-Clause "New" or "Revised" License
735 stars 149 forks source link

Adding custom fields? #25

Closed CodeMonk closed 5 years ago

CodeMonk commented 8 years ago

I'm creating some custom feeds for my nissan leaf, and, I need to add fields to the rss I generate. The full spec of the tags is here. But, in a nutshell, I just need to add carwings:something tags to the feed. Here's an example -- sorry for the japanese, it's from the url above:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:carwings="http://www.nissan.co.jp/dtd/carwings.dtd">
  <channel>
    <title>日産WEBサイト更新情報:NISSAN Topics</title>
    <link>http://rss.nissan.co.jp/</link>
    <description>日産自動車の最新情報をお届けします。</description>
    <language>ja</language>
    <copyright>Copyright NISSAN MOTOR CO.,LTD. 2005 All Rights  Reserved.</copyright>
    <lastBuildDate>Wed, 25 Oct 2006 12:18:36 +0900</lastBuildDate>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs> 
    <item>
    <title>エクストレイル X-TRAIL JAM情報更新</title>
    <carwings:readtitle>エクストレイル ジャム 情報更新</carwings:readtitle>
    <description>X-TRAIL JAM IN TOKYO DOMEのチケット一般発売開始!!</description>
    <carwings:readtext>エクストレイル ジャム 東京ドームのチケット、一般販売開始。</carwings:readtext>
    <carwings:itemimage>http://eplus.jp/sys/web/irg/2006x-trail/images/topmain.jpg</carwings:itemimage>
    <carwings:data><![CDATA[
    <body>エクストレイル<br><img src="http://lab.nissan-carwings.com/CWC/images/x-trail.jpg"></body>
    ]]>
    </carwings:data>
    <carwings:lat>35.70568</carwings:lat>
    <carwings:lon>139.75187</carwings:lon>
    <link>http://blog.nissan.co.jp/X-TRAIL/?rss</link>
    <guid>http://blog.nissan.co.jp/X-TRAIL/?rss</guid>
    <carwings:link>http://www.nissan.co.jp/EVENT/....../coupon.html</carwings:link>
    <category>コンテンツ</category>
    <pubDate>Mon, 16 Oct 2006 20:15:02 +0900</pubDate>
    </item>
  </channel>
</rss>

I'm happy to extend gorilla feeds to add the fields, but, I can't figure out an easy way to do it. Thoughts? I'd hate to have to write a new library when yours is so close!

Thanks in advance,

-Dave

metal3d commented 8 years ago

:+1:

As I explained in my comment #33 I need to add "wfw" namespace to link comments feeds.

I guess that we can find way to extend Feed and Item to be able to add custom entries. I will take a look on what can be done, if there is a pure Go method and if a PR must be proposed.

elithrar commented 8 years ago

My understanding of XML namespaces in Go is that there's some history: https://github.com/golang/go/issues/13400

A 'cheat' way might just to be wrap the output/modify it to add the namespace statically.

metal3d commented 8 years ago

I agree if we only need to add a namespace. But we need to add "tags" in items. The better is to be able to add custom item entries and one or more namespaces on the root element. I didn't checked how to override Item and Feed elements but I think that having the possibility to declare some custom namespaces and item properties should be the way to go.

I see something like that:


feed := Feed{
    // ... append title, author and so on
}
// add a namespace (name, dtd link, feed type that can be RSS, ATOM or ALL)
feed.AddNameSpace("wfw", "http://...", RSS)

item := Item{
    Title: "...",
    Description: "...",
    CustomFields : []CustomFields{
         {Name:"wfw", Value:"link to comment field", For: RSS}
    },
}

// add item
feed.Items = append(feed.Items, item)

What I should do is to:

sourav-babajob commented 7 years ago

Can we add custom fields to the ITEM ??

elithrar commented 7 years ago

Can you show an example of what you want to change? The Item aligns with the RSS and Atom data models. On Thu, Oct 13, 2016 at 7:23 AM sourav-babajob notifications@github.com wrote:

Can we add custom fields to the ITEM ??

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/gorilla/feeds/issues/25#issuecomment-253527231, or mute the thread https://github.com/notifications/unsubscribe-auth/AABIcLZUKVjiSLi0cp8Ob5zmrQRfQcCRks5qzj41gaJpZM4GGkTT .

sourav-babajob commented 7 years ago

@elithrar Currently the library creates the below ATOM FEED ( Item ) in my case

<entry>
<title>Driver</title>
<updated>2016-09-11T20:45:17+05:30</updated>
<id>2146289956</id>
<content type="html">
description
</content>
<link href="http://xyz.com/"/>
<author>
<name>ZYZ</name>
</author>
</entry>

I want to add custom tags in the Item struct like and

The current Item struct allows ->

type Item struct {
    Title       string
    Link        *Link
    Author      *Author
    Description string // used as description in rss, summary in atom
    Id          string // used as guid in rss, id in atom
    Updated     time.Time
    Created     time.Time
}
metal3d commented 7 years ago

@elithrar Check #33 comment I opened. I need that tag inside an item:

<wfw:commentRss>http://linuxfr.org/nodes/108491/comments.atom</wfw:commentRss>

Atom allows to add xml tags after we've added a namespace. At this time we can't.

elithrar commented 7 years ago

https://github.com/golang/go/issues/13400 seems to be unresolved.

On Fri, Oct 21, 2016 at 5:46 AM Patrice Ferlet notifications@github.com wrote:

@elithrar https://github.com/elithrar Check #33 https://github.com/gorilla/feeds/issues/33 comment I opened. I need that tag inside an item:

wfw:commentRsshttp://linuxfr.org/nodes/108491/comments.atom/wfw:commentRss

Atom allows to add xml tags after we've added a namespace. At this time we can't.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gorilla/feeds/issues/25#issuecomment-255369280, or mute the thread https://github.com/notifications/unsubscribe-auth/AABIcFZbxppeQFv_P7K21ViZ3B2LKFGJks5q2LQZgaJpZM4GGkTT .

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.