rss中的图像使用ColdFusion和CFFeed [英] Images in rss feed using ColdFusion and CFFeed
问题描述
我有一个脚本生成一个xml文件与ColdFusion及其 CFFeed
标签。它工作相当不错,除了图像。我知道你必须使用封装在 CDATA
中的图像以显示它。我不确定是否已正确设置,因为图片未显示在我的Google阅读器/ Feedly Feed中。以下是代码:
< cfquery datasource =dataname =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#')>
<!---这里让我们清理,并确保所有的值都是XML兼容--->
< 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>
<!---生成Feed并将其保存到文件和变量。 --->
< cffeed action =createname =#RssStruct#overwrite =truexmlVar =myXMLoutputFile =Feed.xml/>`
看起来你已经为 ; description>
元素。您尝试过简单地将代码放在< description>
中吗?
>
< 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] .description ='<![CDATA [< img src =https://www.url.com/assets/Photos/photo/#id# .jpg> #body#]]>'/>
您是否尝试过使用< enclosure>
$ b b $ b
length - 必需。定义媒体文件的长度(以字节为单位)
type - 必需。定义媒体文件的类型
url - 必需。定义媒体文件的URL
一个例子是这样的(你需要确定图像的大小, :
< enclosure url =https://www.url.com/assets/Photos/photo/#id# .jpglength =#ImageLength#type =image / jpeg/>
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" />`
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" />
这篇关于rss中的图像使用ColdFusion和CFFeed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!