Skip to content

Commit

Permalink
RSS support.
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenferguson committed Mar 10, 2020
1 parent 4a5ddd8 commit 244baaa
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
12 changes: 12 additions & 0 deletions SpeedWagon.Web.UI/Controllers/HomeController.cs
Expand Up @@ -39,11 +39,23 @@ public async Task<IActionResult> Index()
if (model.Content.Type == "Home")
{
return await Home(site);
}
else if (model.Content.Type == "Rssfeed")
{
return await Rss(site);
}

return View(model.Content.View(), site);
}

public async Task<IActionResult> Rss(Site site)
{
Response.ContentType = "application/rss+xml";
RssFeed rssFeed = new RssFeed(site);
rssFeed.Posts = await this._speedWagon.SearchService.Search(new Dictionary<string, string>() { { "Type", "Post" } });
return View(rssFeed.Content.View(), rssFeed);
}

public async Task<IActionResult> Home(Site site)
{
HomePage homePage = new HomePage(site);
Expand Down
16 changes: 16 additions & 0 deletions SpeedWagon.Web.UI/Models/Page/RssFeed.cs
@@ -0,0 +1,16 @@
using SpeedWagon.Runtime.Models;
using System.Collections.Generic;

namespace SpeedWagon.Web.UI.Models.Page
{
public class RssFeed : Site
{
public RssFeed(Site site) : base(site) {

this.Home = site.Home;
this.TopNavigation = site.TopNavigation;
}

public IEnumerable<SearchResult> Posts { get; set; }
}
}
4 changes: 3 additions & 1 deletion SpeedWagon.Web.UI/Views/Partials/Footer.cshtml
Expand Up @@ -13,7 +13,7 @@
</span>
</a>
</li>

<li class="list-inline-item">
<a href="https://www.linkedin.com/in/darrenferguson/">
<span class="fa-stack fa-lg">
Expand All @@ -22,6 +22,8 @@
</span>
</a>
</li>


</ul>
<p class="copyright text-muted">Copyright &copy; @(Model.Home.GetValue<string>("Title")) @DateTime.UtcNow.Year. Powered by <a href="https://github.com/darrenferguson/speedwagon">SpeedWagon</a></p>
</div>
Expand Down
11 changes: 6 additions & 5 deletions SpeedWagon.Web.UI/Views/Post.cshtml
Expand Up @@ -5,11 +5,12 @@
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">

<p><em>
Posted by
@Model.Content.CreatorName
on @Model.Content.CreateDate.ToString("d MMMM yyyy")
</em>
<p>
<em>
Posted by
@Model.Content.CreatorName
on @Model.Content.CreateDate.ToString("d MMMM yyyy")
</em>
</p>

@(Html.Raw(Model.Content.GetValue<string>("Content")))
Expand Down
29 changes: 29 additions & 0 deletions SpeedWagon.Web.UI/Views/RssFeed.cshtml
@@ -0,0 +1,29 @@
@model SpeedWagon.Web.UI.Models.Page.RssFeed
@using SpeedWagon.Runtime.Models
@{
Layout = null;

string date = String.Format("{0:MM/dd/yyyy hh:mm tt}", DateTime.UtcNow);
}
<rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>@(Model.Home.GetValue<string>("Title"))</title>
<link>@Model.Content.WebUrl()</link>
<description>@(Model.Home.GetValue<string>("Description"))</description>
<language>en-gb</language>
<lastBuildDate>@date</lastBuildDate>
<items>
@foreach (SearchResult post in Model.Posts)
{
<item>
<title>@(post.Content.GetValue<string>("Title"))</title>

<description>@(post.Content.GetValue<string>("Description"))</description>
<guid>@post.Content.WebUrl()</guid>
<pubDate>@(String.Format("{0:MM/dd/yyyy hh:mm tt}", Model.Content.UpdateDate))</pubDate>
</item>
}
</items>

</channel>
</rss>

0 comments on commit 244baaa

Please sign in to comment.