forked from atlsecsrv-com/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlogFeedItem.cs
56 lines (51 loc) · 1.89 KB
/
BlogFeedItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Microsoft.SyndicationFeed;
using Microsoft.SyndicationFeed.Atom;
using Microsoft.SyndicationFeed.Rss;
using Statiq.Common;
using System;
using System.Collections.Generic;
using System.Linq;
namespace DotnetFoundationWeb
{
public class BlogFeedItem
{
public string Title { get; }
public string Link { get; }
public string Description { get; }
public DateTimeOffset Published { get; }
public bool Recent { get; }
public IDictionary<string, string> Links { get; }
public string Author { get; }
public BlogFeedItem(ISyndicationItem item, DateTimeOffset recent, Uri website)
{
Title = item.Title;
ISyndicationLink firstLink = item.Links.FirstOrDefault(x => x.RelationshipType == RssLinkTypes.Alternate);
if (firstLink != null)
{
Link = firstLink.Uri.IsAbsoluteUri ? firstLink.Uri.AbsoluteUri : new Uri(website, firstLink.Uri).AbsoluteUri;
}
else
{
Link = item.Id;
}
Published = item.Published != default ? item.Published : item.LastUpdated;
Recent = Published > recent;
Description = item.Description;
Links = item.Links
.Where(x => !string.IsNullOrEmpty(x.MediaType))
.GroupBy(x => x.MediaType)
.Select(x => x.First())
.ToDictionary(x => x.MediaType, x => x.Uri.ToString());
ISyndicationPerson person = item.Contributors.FirstOrDefault(x => x.RelationshipType == "author");
if (person != null)
{
Author = person.Name ?? person.Email;
}
AtomEntry atom = item as AtomEntry;
if (atom != null && !string.IsNullOrEmpty(atom.Summary))
{
Description = atom.Summary;
}
}
}
}