Adding tags to RSS feeds

This commit is contained in:
Sebastien Ros
2014-02-05 10:28:24 -08:00
parent 94189a58c7
commit 83df0ebdf0
3 changed files with 33 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
using System.Linq;
using System.Xml.Linq;
using Orchard.ContentManagement;
using Orchard.Core.Feeds;
using Orchard.Core.Feeds.Models;
using Orchard.Environment.Extensions;
using Orchard.Tags.Models;
namespace Orchard.Tags.Feeds {
[OrchardFeature("Orchard.Tags.Feeds")]
public class TagsFeedItemBuilder : IFeedItemBuilder {
public void Populate(FeedContext context) {
foreach (var feedItem in context.Response.Items.OfType<FeedItem<ContentItem>>()) {
// add to known formats
if (context.Format == "rss") {
// adding tags to the rss item
var tagsPart = feedItem.Item.As<TagsPart>();
if (tagsPart != null) {
tagsPart.CurrentTags.ToList().ForEach(x =>
feedItem.Element.Add(new XElement("category", x)));
}
}
}
}
}
}

View File

@@ -10,3 +10,8 @@ Features:
Description: The tags module is providing basic tagging for arbitrary content types.
Dependencies: Settings, Orchard.jQuery
Category: Navigation
Orchard.Tags.Feeds:
Name: Tags Feeds
Description: Adds tags to the RSS feeds.
Dependencies: Orchard.Tags, Feeds
Category: Syndication

View File

@@ -67,6 +67,7 @@
<ItemGroup>
<Compile Include="AdminMenu.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Feeds\TagsFeedItemBuilder.cs" />
<Compile Include="Migrations.cs" />
<Compile Include="Models\ContentTagRecord.cs" />
<Compile Include="Models\TagsPartRecord.cs" />