RSS Feed NuGet Package for Optimizely CMS 12+

Wednesday, July 12, 2023 | World CMS Addons
Surjit

Surjit Bharath

Director of Hidden Foundry

Optimizely Most Valued Professional (OMVP), Subject Matter Expert (SME), CMS and Commerce certified

Contact Me

Usage

I was asked how our company website served our thoughts via an RSS feed and asked if they also could have this functionality. The functionality is quite straightforward so I decided to wrap it up in a nuget package and share it.

Simply goto your site homepage and add /rss to the end.

In the case of Hidden Foundry, it would be https://www.hiddenfoundry.com/rss

 

Configuration

The package is located here: https://nuget.optimizely.com/package/?id=HiddenFoundry.Optimizely.RssFeed

and you can install it via package manager:

Install-Package HiddenFoundry.Optimizely.RssFeed

 

Implement AddRssFeed in the Startup.cs in the ConfigureServices method. Below is an example of all the options you can configure.

services.AddRssFeed<ArticlePage>(o =>
{
     o.ParentRelativeUrl = "/thoughts/";
     o.FeedTitle = "Hidden Foundry Thoughts";
     o.FeedDescription = "Technical and Strategy thoughts from Hidden Foundry";
     o.ContentPropertyName = "ListingText";
     o.AuthorName = "Surjit Bharath";
     o.AuthorEmail = "[email protected]";
     o.AuthorUri = "https://world.optimizely.com/System/Users-and-profiles/Community-Profile-Card/?userId=33c8dc2f-782b-e811-8122-70106faab5f1";
});

 

The Rss feed is served by an mvc controller so make sure you have the routing setup too. You may have a custom variation of it but the most common way is this:

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
});

 

Configuration Breakdown

You must specific a page type. It can be a specific CMS page or a general one that inherits from IContent such as PageData.

services.AddRssFeed<ArticlePage>(o =>

 

 

ParentRelativeUrl is the only field that is required. This points to the parent page of your collection of pages. The addon will attempt to convert this url into a Content Reference in order to grab the pages underneath.

o.ParentRelativeUrl = "/thoughts/";

 

 

This sets the Title and Description of the feed respectively on the rss feed itself.

o.FeedTitle = "Hidden Foundry Thoughts";
o.FeedDescription = "Technical and Strategy thoughts from Hidden Foundry";

 

 

You can specify here what property on the page will populate the description of each page on the rss feed. The default value is SeoDescription. However in the example, we have a custom field called ListingText.

o.TitlePropertyName = "Title"
o.ContentPropertyName = "ListingText";

 

 

Author details are populated here but they are set for every page in the RSS Feed. If you require custom logic because for example you may have different authors for multiple pages then you can override the syndicationitemservice. Please read below for some examples.

o.AuthorName = "Surjit Bharath";
o.AuthorEmail = "[email protected]";
o.AuthorUri = "https://world.optimizely.com/System/Users-and-profiles/Community-Profile-Card/?userId=33c8dc2f-782b-e811-8122-70106faab5f1";

 

 

Implementing your own custom logic

As with every client, all logic that ends up on the RSS feed will come from different places in the cms structure. There are a selection of interfaces you can override that will allow you intercept and inject code that caters for your own needs.

 

Called by the Rss Controller and is responsible for orchestration for the other services. This one you would least likely to override.

services.AddSingleton<IRssService, RssService<T>>();

 

Responsible for loading pages / categories from a repository. The default implementation pulls from ContentLoader

services.AddSingleton<IPageLoader, DefaultPageLoader>();

 

This class converts a page into a syndication item. You would most likely override this one as you may want to pull data from different places and additionally you may want to populate the Syndication Item with more meta data.

services.AddSingleton<ISyndicationItemFactory, DefaultSyndicationItemFactory>();

 

Ensure the SyndicationFeed itself is setup correct and sets the Title and Description.

services.AddSingleton<ISyndicationFeedFactory, DefaultSyndicationFeedFactory>();

 

 

For example, the DefaultPageLoader is a class thats responsible for pulling pages via ContentLoader. If instead you didn't want to use ContentLoader and you instead wanted to Search & Navigation. Then you would intercept the IPageLoader and replace it with your own implementation of it.

services.Replace(Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Singleton<IPageLoader, FindPageLoader>());

 

The while piece is fairly customizable but if there's a component you feel does need changing or feature adding then please don't hesistate to reach out to me.

;