Skip to content

Instantly share code, notes, and snippets.

@chrisdpeters
Last active March 17, 2020 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdpeters/1848689 to your computer and use it in GitHub Desktop.
Save chrisdpeters/1848689 to your computer and use it in GitHub Desktop.
Aggregating RSS Feeds with Delicious, Yahoo! Pipes, FeedBurner, and CFML
<!--- URL to RSS feed --->
<cfparam name="arguments.articlesRss" type="url">
<!--- URL to Delicious page --->
<cfparam name="arguments.articlesUrl" type="url">
<!--- Number of items to display from feed --->
<cfparam name="arguments.numToDisplay" type="numeric" default="10">
<!--- Note: we are breaking the convention of data access in the view here so that we can cache this partial --->
<cfset articles = articles(arguments.articlesRss)>
<cfoutput>
<div id="community-articles">
<h3>
#Replace(articles.title, "ColdFusion on Wheels ", "")#
<a href="#arguments.articlesRss#" class="image">#imageTag(source="feed-icon-14x14.png", alt="Articles Feed")#</a>
</h3>
<p>#HtmlEditFormat(articles.description)#</p>
<dl>
<cfloop from="1" to="#arguments.numToDisplay#" index="i">
<dt>
<a href="#articles.item[i].link#">#articles.item[i].title#</a>
<span class="date">(discovered&nbsp;#Replace(timeAgoInWords(articles.item[i].pubDate), " ", "&nbsp;", "all")#&nbsp;ago)</span>
</a>
</dt>
<dd>#articles.item[i].description.value#</dd>
</cfloop>
</dl>
<h4>Read More Articles</h4>
<ul class="calls-to-action">
<li class="delicious"><a href="#arguments.articlesUrl#">All Articles on Delicious</a></li>
<li class="feed"><a href="#arguments.articlesRss#" title="Articles Feed"><abbr title="Really Simple Syndication">RSS</abbr> Feed</a></li>
</ul>
</div>
</cfoutput>
<cffeed name="articles" source="#arguments.rssUrl#">
<cffunction name="articles" hint="Fetches latest article data from specified RSS feed.">
<cfargument name="rssUrl" type="string" hint="URL of RSS feed to check.">
<cfset var loc = {}>
<!--- Design mode will not cache, so let's store data in session to keep FeedBurner happy --->
<cfif get("environment") is "design">
<cfif not StructKeyExists(session, "articles")>
<cffeed name="session.articles" source="#arguments.rssUrl#">
</cfif>
<cfset loc.articles = session.articles>
<!--- This is cached in production mode --->
<cfelse>
<cffeed name="loc.articles" source="#arguments.rssUrl#">
</cfif>
<cfreturn loc.articles>
</cffunction>
#includePartial(
partial="articles",
articlesRss=articlesRss,
articlesUrl=articlesUrl,
numToDisplay=5,
cache=5
)#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment