dylang / node-rss

RSS feed generator for Node.
https://npmjs.org/package/rss
MIT License
999 stars 133 forks source link

how to add media:content? #93

Open ralyodio opened 4 years ago

ralyodio commented 4 years ago

There doesn't seem to be a way to add media:content

<media:content url="https://thedailyshitter.com/content/images/2020/03/money-business-material-cash-bank-currency-629802-pxhere.com-2-.jpg" medium="image"/>

deanshelton913 commented 4 years ago
rssInstance({
custom_elements: [
              {
                  'media:content': [
                      {
                          _attr: {
                              type: 'application/x-shockwave-flash',
                              medium: 'video',
                              isDefault: 'true',
                              expression: 'full',
                              duration: '117',
                              url: 'https:,//www.youtube.com/v/XnZ_J3l_0z4',
                              src: your url
                          }
                      },})

something like this should work, yeah?

FerrariAndrea commented 1 year ago

The same need here,

This is my solution:

  const feedOptions = {
   title: '...',
   description: "...",
   site_url: '...',
   feed_url: `...`,
   image_url: `...`,
   pubDate: new Date(),
   copyright: `...`,
   custom_namespaces: {
        media: "http://search.yahoo.com/mrss/",
    }
  };

  const feed = new RSS(feedOptions);

Important code part that you need to add:

custom_namespaces: {
media: "http://search.yahoo.com/mrss/",
}

Then in your item:

 feed.item({
     title: "...",
     description:  "...",
     url:  "...",
     date:  "...",
     author: "...",
     custom_elements: [
      {
        'media:content': [
            {
                _attr: {
                    medium: 'image',
                    URL:  "<YOUR IMAGE URL>"
                }
            }]
      }]
    }); 

Result in the feed:

<media:content medium="image" url="<YOUR IMAGE URL>"> </media:content>

I test with Google RSS feed reader and it is working now!

I think you should write down in your documentation a similar example, it is really useful! Nowadays images in the feed have 80% of relevance.

(thx to https://github.com/dylang/node-rss/issues/19#issuecomment-627416273 for the option configuration part)