forked from dotnet-foundation/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FixedAtomParser.cs
32 lines (31 loc) · 1.4 KB
/
FixedAtomParser.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
using Microsoft.SyndicationFeed;
using Microsoft.SyndicationFeed.Atom;
using System.Collections.Generic;
using System.Linq;
namespace DotnetFoundationWeb
{
// See https://github.com/dotnet/SyndicationFeedReaderWriter/issues/31
public class FixedAtomParser : AtomParser
{
public override IAtomEntry CreateEntry(ISyndicationContent content)
{
// Remove author and contributor entries if they don't contain an email or name
ICollection<ISyndicationContent> children = (ICollection<ISyndicationContent>)content.Fields;
ISyndicationContent author = children.FirstOrDefault(x => x.Name == AtomContributorTypes.Author);
if (author != null
&& author.Fields.FirstOrDefault(x => x.Name == "name")?.Value == null
&& author.Fields.FirstOrDefault(x => x.Name == "email")?.Value == null)
{
children.Remove(author);
}
ISyndicationContent contributor = children.FirstOrDefault(x => x.Name == AtomContributorTypes.Contributor);
if (contributor != null
&& contributor.Fields.FirstOrDefault(x => x.Name == "name")?.Value == null
&& contributor.Fields.FirstOrDefault(x => x.Name == "email")?.Value == null)
{
children.Remove(contributor);
}
return base.CreateEntry(content);
}
}
}