From 6bb8da366013bbc99d79c217ffcceb25c43d9412 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 29 Jul 2019 19:17:40 +0100 Subject: [PATCH] Squash a bunch of bugs --- PolyFeed/FeedBuilder.cs | 21 +++++++++++++-------- PolyFeed/SubstitutionLexer.cs | 4 ++-- examples/twitter.toml | 8 ++++---- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/PolyFeed/FeedBuilder.cs b/PolyFeed/FeedBuilder.cs index 17c5a9e..ea2429d 100644 --- a/PolyFeed/FeedBuilder.cs +++ b/PolyFeed/FeedBuilder.cs @@ -15,16 +15,17 @@ namespace PolyFeed { public class FeedBuilder { - StringBuilder result = new StringBuilder(); + MemoryStream stream = new MemoryStream(); XmlWriter xml = null; AtomFeedWriter feed = null; public FeedBuilder() { - xml = XmlWriter.Create(result, new XmlWriterSettings() { + xml = XmlWriter.Create(stream, new XmlWriterSettings() { Indent = true, - IndentChars = "\t" + Encoding = new UTF8Encoding(false), + WriteEndDocumentOnClose = true }); - feed = new AtomFeedWriter(xml); + feed = new AtomFeedWriter(xml, null, new AtomFormatter() { UseCDATA = true }); } public async Task AddSource(FeedSource source) { @@ -36,6 +37,7 @@ namespace PolyFeed // Write the header await feed.WriteGenerator("Polyfeed", "https://github.com/sbrl/PolyFeed.git", Program.GetProgramVersion()); await feed.WriteId(source.Feed.Url); + await feed.Write(new SyndicationLink(new Uri(source.Feed.Url), AtomLinkTypes.Self)); string lastModified = response.Headers.Get("last-modified"); if (string.IsNullOrWhiteSpace(lastModified)) await feed.WriteUpdated(DateTimeOffset.Now); @@ -86,12 +88,14 @@ namespace PolyFeed string url = source.Entries.Url.Attribute == string.Empty ? urlNode.InnerText : urlNode.Attributes[source.Entries.Url.Attribute].DeEntitizeValue; - - SyndicationItem nextItem = new SyndicationItem() { - Id = new Uri(new Uri(source.Feed.Url), new Uri(url)).ToString(), + Uri entryUri = new Uri(new Uri(source.Feed.Url), new Uri(url)); + AtomEntry nextItem = new AtomEntry() { + Id = entryUri.ToString(), Title = ReferenceSubstitutor.Replace(source.Entries.Title, nextNode), Description = ReferenceSubstitutor.Replace(source.Entries.Content, nextNode), + ContentType = "html" }; + nextItem.AddLink(new SyndicationLink(entryUri, AtomLinkTypes.Alternate)); if (source.Entries.Published != null) { nextItem.Published = DateTime.Parse( @@ -130,7 +134,8 @@ namespace PolyFeed await feed.Flush(); xml.WriteEndDocument(); xml.Flush(); - return result.ToString(); + xml.Close(); + return Encoding.UTF8.GetString(stream.ToArray()); } } } diff --git a/PolyFeed/SubstitutionLexer.cs b/PolyFeed/SubstitutionLexer.cs index 8240cc7..c914d22 100644 --- a/PolyFeed/SubstitutionLexer.cs +++ b/PolyFeed/SubstitutionLexer.cs @@ -24,8 +24,8 @@ namespace PolyFeed AddRules(new List>() { new LexerRule(SubstitutionToken.Text, @"[^{}]+"), new LexerRule(SubstitutionToken.Identifier, @"[^{}]+"), - new LexerRule(SubstitutionToken.BraceOpen, @"\{"), - new LexerRule(SubstitutionToken.BraceClose, @"\}"), + new LexerRule(SubstitutionToken.BraceOpen, @"\{+"), + new LexerRule(SubstitutionToken.BraceClose, @"\}+"), }); } diff --git a/examples/twitter.toml b/examples/twitter.toml index 95fc8fd..a81a87b 100644 --- a/examples/twitter.toml +++ b/examples/twitter.toml @@ -1,7 +1,7 @@ [feed] -output = "CrossCodeLea-Twitter.atom" +output = "euruicimages-Twitter.atom" -url = "https://mobile.twitter.com/CrossCodeLea" +url = "https://mobile.twitter.com/euruicimages" source_type = "html" @@ -12,8 +12,8 @@ logo_url = { selector = ".avatar img", attribute = "src" } [entries] selector = ".tweet" -title = "Tweet by {.username}" -content = "{.tweet-social-context}
{.avatar}{.fullname}
{.tweet-content}" +title = "Tweet by {{.username}} {{.tweet-social-context}}" +content = "

{.avatar}{.fullname}:

\n{.tweet-text}" url = { selector = ".metadata a", attribute = "href" }