Images in rss feed using ColdFusion and CFFeed

喜欢而已 提交于 2019-12-24 08:44:17

问题


I have a script that generates an xml file with ColdFusion and its CFFeed tag. It works pretty good except for images. I understand that you have to use encapsulate the image in CDATA in order to display it. I am not sure if I have set it up correctly because the images are not showing up in my Google Reader / Feedly feed. Here is the code:

<cfquery datasource="data" name="queryT">
SELECT *
FROM qTable
WHERE ... 
ORDER BY...
</cfquery> 

<cfset RssStruct                = StructNew() />
<cfset RssStruct.link           = "https://www.url.com" />
<cfset RssStruct.title          = "sitename" />
<cfset RssStruct.description    = "url Blog" />
<cfset RssStruct.image.url      = 'https://www.url.com/assets/img/ns.png' />
<cfset RssStruct.image.title    = 'Site Name' />
<cfset RssStruct.image.link     = 'https://www.url.com' />
<cfset RssStruct.pubDate        = Now() />
<cfset RssStruct.version        = "rss_2.0" />
<cfset RssStruct.item           = ArrayNew(1) />
<cfset threadlist               = "">
<cfset index                    = 1>

<cfloop query="queryT">
    <cfif listcontains( threadlist , '#id#' ) eq 0>
        <cfset threadlist = ListAppend(threadlist, '#id#')>
             <!--- Here let's clean up and ensure that all values are XML Compliant --->
            <cfset RssStruct.item[index]                    = StructNew() />
            <cfset RssStruct.item[index].guid               = structNew() />
            <cfset RssStruct.item[index].guid.isPermaLink   ="YES" />
            <cfset RssStruct.item[index].guid.value         = 'https://www.url.com/page.cfm?itemid=#queryT.id#' />
            <cfset RssStruct.item[index].pubDate            = createDate(year(Posted), month(Posted), day(Posted)) />
            <cfset RssStruct.item[index].title              = xmlFormat(#title#) />
            <cfset RssStruct.item[index].Body               = xmlFormat(#Body#) />
            <cfset RssStruct.item[index].description        = StructNew() />
            <cfset RssStruct.item[index].description.value  = '<![CDATA[ <img src="https://www.url.com/assets/Photos/photo/#id#.jpg"> #body#  ]]>' />
            <cfset RssStruct.item[index].link               = 'https://www.url.com/page.cfm?item=#queryT.id#' /><br>
        <cfset index = index + 1>
    </cfif>
</cfloop>

<!--- Generate the feed and save it to a file and variable. --->

<cffeed action="create" name="#RssStruct#" overwrite="true" xmlVar="myXML" outputFile = "Feed.xml"  />`

回答1:


It looks like you have created a structure for the <description> element under the item. Have you tried simply putting your code in the <description> instead?

Instead of this:

        <cfset RssStruct.item[index].description        = StructNew() />
        <cfset RssStruct.item[index].description.value  = '<![CDATA[ <img src="https://www.url.com/assets/Photos/photo/#id#.jpg"> #body#  ]]>' />

Try this:

        <cfset RssStruct.item[index].description  = '<![CDATA[ <img src="https://www.url.com/assets/Photos/photo/#id#.jpg"> #body#  ]]>' />

Have you tried using the <enclosure> element of the item instead?

Definition and Usage

The element allows a media-file to be included with an item.

Attributes

length - Required. Defines the length (in bytes) of the media file

type - Required. Defines the type of media file

url - Required. Defines the URL to the media file

An example would be something like (you will need to determine the size of the image in bytes):

<enclosure url="https://www.url.com/assets/Photos/photo/#id#.jpg" length="#ImageLength#" type="image/jpeg" />


来源:https://stackoverflow.com/questions/15734840/images-in-rss-feed-using-coldfusion-and-cffeed

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