1
0
Fork 0
mirror of https://github.com/sbrl/PolyFeed.git synced 2024-12-24 10:45:02 +00:00

Squash a bunch of bugs

This commit is contained in:
Starbeamrainbowlabs 2019-07-29 19:17:40 +01:00
parent 89cac01006
commit 6bb8da3660
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 19 additions and 14 deletions

View file

@ -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());
}
}
}

View file

@ -24,8 +24,8 @@ namespace PolyFeed
AddRules(new List<LexerRule<SubstitutionToken>>() {
new LexerRule<SubstitutionToken>(SubstitutionToken.Text, @"[^{}]+"),
new LexerRule<SubstitutionToken>(SubstitutionToken.Identifier, @"[^{}]+"),
new LexerRule<SubstitutionToken>(SubstitutionToken.BraceOpen, @"\{"),
new LexerRule<SubstitutionToken>(SubstitutionToken.BraceClose, @"\}"),
new LexerRule<SubstitutionToken>(SubstitutionToken.BraceOpen, @"\{+"),
new LexerRule<SubstitutionToken>(SubstitutionToken.BraceClose, @"\}+"),
});
}

View file

@ -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}<br />{.avatar}{.fullname}<br />{.tweet-content}"
title = "Tweet by {{.username}} {{.tweet-social-context}}"
content = "<p><strong>{.avatar}{.fullname}:</strong></p>\n{.tweet-text}"
url = { selector = ".metadata a", attribute = "href" }