Using the blog's description in RSS feeds

This commit is contained in:
Sebastien Ros
2014-04-01 15:49:26 -07:00
parent 9dcb790d27
commit 782012849a
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Routing;
using System.Xml.Linq;
using JetBrains.Annotations;
using Orchard.Blogs.Models;
using Orchard.ContentManagement;
using Orchard.Core.Feeds;
using Orchard.Core.Feeds.Models;
using Orchard.Mvc.Extensions;
using Orchard.Services;
namespace Orchard.Blogs.Feeds {
public class BlogPartFeedItemBuilder : IFeedItemBuilder {
private IContentManager _contentManager;
public BlogPartFeedItemBuilder(IContentManager contentManager) {
_contentManager = contentManager;
}
public void Populate(FeedContext context) {
var containerIdValue = context.ValueProvider.GetValue("containerid");
if (containerIdValue == null)
return;
var containerId = (int)containerIdValue.ConvertTo(typeof(int));
var container = _contentManager.Get(containerId);
if (container == null) {
return;
}
if (container.ContentType != "Blog") {
return;
}
var blog = container.As<BlogPart>();
if (context.Format == "rss") {
context.Response.Element.SetElementValue("description", blog.Description);
}
else {
context.Builder.AddProperty(context, null, "description", blog.Description);
}
}
}
}

View File

@@ -72,6 +72,7 @@
<Compile Include="Drivers\BlogArchivesPartDriver.cs" />
<Compile Include="Drivers\RemoteBlogPublishingDriver.cs" />
<Compile Include="Drivers\RecentBlogPostsPartDriver.cs" />
<Compile Include="Feeds\BlogPartFeedItemBuilder.cs" />
<Compile Include="Handlers\BlogArchivesPartHandler.cs" />
<Compile Include="Handlers\RecentBlogPostsPartHandler.cs" />
<Compile Include="Models\BlogArchivesPart.cs" />