Files
blog.terrible.dev/src/TerribleDev.Blog.Web/Extensions/IPostExtensions.cs
Tommy Parnell 3b9c978b92 fix some issues
2022-03-18 15:36:57 -04:00

35 lines
1.0 KiB
C#

using Microsoft.SyndicationFeed;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TerribleDev.Blog.Web.Models;
namespace TerribleDev.Blog.Web
{
public static class IPostExtensions
{
public static SyndicationItem ToSyndicationItem(this Post x)
{
Uri.TryCreate(x.CanonicalUrl, UriKind.Absolute, out var url);
var syn = new SyndicationItem()
{
Title = x.Title,
Description = x.Content.Content.ToString(),
Id = url.ToString(),
Published = x.PublishDate,
};
syn.AddLink(new SyndicationLink(url));
return syn;
}
public static ISet<string> ToNormalizedTagList(this Post x)
{
if(x.tags == null)
{
return new HashSet<string>();
}
return new HashSet<string>(x.tags.Where(a => !string.IsNullOrWhiteSpace(a)).Select(a => a.ToLower()));
}
}
}