Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
PaulaBean
committed
Oct 16, 2014
1 parent
493a63f
commit 134af1b
Showing
6 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Web.Mvc; | ||
using System.Xml; | ||
using System.Xml.Linq; | ||
using TheDailyWtf.Models; | ||
|
||
namespace TheDailyWtf | ||
{ | ||
public sealed class RssArticlesResult : ActionResult | ||
{ | ||
private readonly IEnumerable<ArticleModel> articles; | ||
|
||
public RssArticlesResult(IEnumerable<ArticleModel> articles) | ||
{ | ||
if (articles == null) | ||
throw new ArgumentNullException("articles"); | ||
|
||
this.articles = articles; | ||
} | ||
|
||
public override void ExecuteResult(ControllerContext context) | ||
{ | ||
var response = context.HttpContext.Response; | ||
response.ContentEncoding = Encoding.UTF8; | ||
response.ContentType = "application/rss+xml"; | ||
|
||
var dc = XNamespace.Get("http://purl.org/dc/elements/1.1/"); | ||
var slash = XNamespace.Get("http://purl.org/rss/1.0/modules/slash/"); | ||
var wfw = XNamespace.Get("http://wellformedweb.org/CommentAPI/"); | ||
|
||
var xdoc = new XDocument( | ||
new XElement("rss", | ||
new XAttribute("version", "2.0"), | ||
new XAttribute(XNamespace.Xmlns + "dc", dc), | ||
new XAttribute(XNamespace.Xmlns + "slash", slash), | ||
new XAttribute(XNamespace.Xmlns + "wfw", wfw), | ||
new XElement("channel", | ||
new XElement("title", "The Daily WTF"), | ||
new XElement("link", "http://thedailywtf.com/"), | ||
new XElement("description", "Curious Perversions in Information Technology"), | ||
this.articles.Select(a => new XElement("item", | ||
new XElement("author", a.Author.Name), | ||
new XElement("title", a.RssTitle), | ||
new XElement("link", a.Url), | ||
new XElement("category", a.Series.Title), | ||
new XElement("pubDate", a.PublishedDate.Value.ToUniversalTime().ToString("r")), | ||
new XElement("guid", a.Id), | ||
new XElement("description", ""), | ||
new XElement(slash + "comments", a.CoalescedCommentCount), | ||
new XElement("comments", a.CommentsUrl) | ||
)) | ||
) | ||
) | ||
); | ||
|
||
using (var writer = XmlWriter.Create(response.OutputStream, new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = false, NewLineChars = "" })) | ||
{ | ||
xdoc.WriteTo(writer); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
User-agent: * | ||
Disallow: /Resources/ | ||
Disallow: /Admin/ | ||
Disallow: /Comments/AddComment.aspx | ||
Disallow: /Comments/EditComment.aspx | ||
Disallow: /Comments/DeleteComment.aspx |