Does JFeed support RSS images?

﹥>﹥吖頭↗ 提交于 2020-01-02 20:11:09

问题


I've had a look at JFeed's readme and it doesn't mention anyway to get to an RSS item's image:

JFeedItem properties

* item.title
* item.link
* item.description
* item.updated
* item.id

Does anyone know a way to parse these images?


回答1:


Short answer "No".

There is no default jFeed support for "image" access for RSS (or "icon"/"logo" access for ATOM).

That said you could always extend the library to support feed images. For example in jrss.js you could add:

var image = jQuery('image', xml).eq(0);

this.image = new Object();
this.image.url = jQuery(image).find('url:first').text();
this.image.title = jQuery(image).find('title:first').text();
this.image.link = jQuery(image).find('link:first').text();

From an RSS feed you would then be able to access:

feed.image.url

But this only facilitates accessing the graphic for the entire feed and not individual items.

To support individual item images you would need to extend jFeed to allow it to support attributes in some way.

For example to support RSS 2.0 enclosures you could fold the attributes into elements, so you would be able to access something like:

item.enclosure.url

In jrss.js you could add something like:

jQuery('item', xml).each( function() {

    var item = new JFeedItem();

    item.title = jQuery(this).find('title').eq(0).text();
    item.link = jQuery(this).find('link').eq(0).text();
    item.description = jQuery(this).find('description').eq(0).text();
    item.updated = jQuery(this).find('pubDate').eq(0).text();
    item.id = jQuery(this).find('guid').eq(0).text();

    item.enclosure = new Object();

    var enc = jQuery(this).find('enclosure');

    item.enclosure.url = jQuery(enc).attr('url');
    item.enclosure.length = jQuery(enc).attr('length');
    item.enclosure.type = jQuery(enc).attr('type');

    feed.items.push(item);
});

I'm tired and making this up as I go along, can you tell? ;)



来源:https://stackoverflow.com/questions/2544543/does-jfeed-support-rss-images

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!