Giter Site home page Giter Site logo

rsscore's Introduction

Snickler.RSSCore: ASPNETCore Middleware for generating RSS Feeds

NuGet

This library was created in order to provide a way to easily generate RSS feeds on the fly via an ASP.NET Core Middleware.

Targets

Currently supports:

  • ASPNET Core 1.1 (netstandard1.3)
  • ASPNET Core 2.x (netstandard2.0)

Getting Started

Add the NuGet package to your project(s). Utilize the namespaces: Snickler.RSSCore.Models, Snickler.RSSCore.Providers, and Snickler.RSSCore.Extensions.

Create an RSS Provider

Create a provider class that implements IRSSProvider and returns a list of RSSItem objects via the RetrieveSyndicationItems method.

public class SomeRSSProvider: IRSSProvider
{
    public Task<IList<RSSItem>> RetrieveSyndicationItems()
        {
            IList<RSSItem> syndicationList = new List<RSSItem>();
            var rssItem1 = new RSSItem()
            {
                Content = "Sample Content 1",
                PermaLink = new Uri("http://www.sampleaddress.com/sample-1"),
                LinkUri = new Uri("http://www.sampleaddress.com/Item.aspx?Id=423"),
                LastUpdated = DateTime.Now,
                PublishDate = DateTime.Now,
                Title = "Sample Title 1",
            };

            rssItem1.Categories.Add(".NET");
            rssItem1.Authors.Add("[email protected]");

            syndicationList.Add(synd1);

            return Task.FromResult(syndicationList);
        }
}

RSS Feed Configuration

Add your provider to the service registration in ConfigureServices with the AddRSSFeed extension

       public void ConfigureServices(IServiceCollection services)
        {
            services.AddRSSFeed<SomeRSSProvider>();
            services.AddMvc();
        }

Set the options for your RSS Feed in Configure with UseRSSFeed

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseRssFeed("/feed", new RSSFeedOptions
            {
                Title = "Snickler's Super Awesome RSS Feed",
                Copyright = "2018",
                Description = "The Best and Most Awesome RSS Feed Content",
                ManagingEditor = "[email protected]",
                Webmaster = "[email protected]",
                Url = new Uri("http://someaddress.com")
            });
        }

Optional RSS Caching Configuration

By default, MemoryCache is used to cache the feed for 1 day. To be able to update the cache duration or cache key, add a new instance of the MemoryCacheProvider to the Caching property within the RSSFeedOptions class.

            app.UseRssFeed("/feed", new RSSFeedOptions
            {
                Title = "Snickler's Super Awesome RSS Feed",
                Copyright = "2018",
                Description = "The Best and Most Awesome RSS Feed Content",
                ManagingEditor = "[email protected]",
                Webmaster = "[email protected]",
                Url = new Uri("http://someaddress.com"),
                Caching = new MemoryCacheProvider 
                {
                    CacheDuration = TimeSpan.FromDays(5),
                    CacheKey = "SomeSuperAwesomeCacheKey"
                }
            });

With this example setup, you'll be able to access the feed at http://whateverurl.com/feed

Example Project

An example project is located within the .sln file in the source.

rsscore's People

Contributors

snickler avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.