Skip to content

Instantly share code, notes, and snippets.

@james-dibble
Last active August 29, 2015 14:12
Show Gist options
  • Save james-dibble/587f72e96036a1046d11 to your computer and use it in GitHub Desktop.
Save james-dibble/587f72e96036a1046d11 to your computer and use it in GitHub Desktop.
A basic implementation of an Umbraco SurfaceController that returns RSS feeds
using System;
using System.Linq;
using System.ServiceModel.Syndication;
using System.Web.Mvc;
using JamesDibble.ApplicationFramework.Web.Rss;
using Umbraco.Web;
using Umbraco.Web.Mvc;
public class SyndicationController : SurfaceController
{
public ActionResult RssFeed()
{
var feed = BuildFeed();
return this.RssResult(feed);
}
public ActionResult AtomFeed()
{
var feed = BuildFeed();
return this.AtomResult(feed);
}
private SyndicationFeed BuildFeed()
{
var feedItems = this.Umbraco.TypedContent(/* ID of the root content node */).Children;
var items = blogs.Select(this.CreateItem).OrderByDescending(i => i.PublishDate);
var feed = new SyndicationFeed(
"Feed Name",
"Feed Description",
new Uri("http://mywebsite.com/feed"),
items)
{
Language = "en-gb",
LastUpdatedTime = DateTime.Now
};
return feed;
}
private SyndicationItem CreateItem(IPublishedContent item)
{
var syndicationItem = new SyndicationItem
{
Title = SyndicationContent.CreatePlaintextContent(item.GetPropertyValue<string>("title")),
Summary = SyndicationContent.CreateHtmlContent(item.GetPropertyValue<string>("abstract")),
PublishDate = item.GetPropertyValue<DateTime>("date")
};
syndicationItem.AddPermalink(/* Link to the content item */);
syndicationItem.Authors.Add(new SyndicationPerson(/* Get the author of the content item */));
return syndicationItem;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment