mirror of
https://github.com/sbrl/PolyFeed.git
synced 2024-11-22 06:23:02 +00:00
Squash a bunch of bugs
This commit is contained in:
parent
89cac01006
commit
6bb8da3660
3 changed files with 19 additions and 14 deletions
|
@ -15,16 +15,17 @@ namespace PolyFeed
|
||||||
{
|
{
|
||||||
public class FeedBuilder
|
public class FeedBuilder
|
||||||
{
|
{
|
||||||
StringBuilder result = new StringBuilder();
|
MemoryStream stream = new MemoryStream();
|
||||||
XmlWriter xml = null;
|
XmlWriter xml = null;
|
||||||
AtomFeedWriter feed = null;
|
AtomFeedWriter feed = null;
|
||||||
|
|
||||||
public FeedBuilder() {
|
public FeedBuilder() {
|
||||||
xml = XmlWriter.Create(result, new XmlWriterSettings() {
|
xml = XmlWriter.Create(stream, new XmlWriterSettings() {
|
||||||
Indent = true,
|
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) {
|
public async Task AddSource(FeedSource source) {
|
||||||
|
@ -36,6 +37,7 @@ namespace PolyFeed
|
||||||
// Write the header
|
// Write the header
|
||||||
await feed.WriteGenerator("Polyfeed", "https://github.com/sbrl/PolyFeed.git", Program.GetProgramVersion());
|
await feed.WriteGenerator("Polyfeed", "https://github.com/sbrl/PolyFeed.git", Program.GetProgramVersion());
|
||||||
await feed.WriteId(source.Feed.Url);
|
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");
|
string lastModified = response.Headers.Get("last-modified");
|
||||||
if (string.IsNullOrWhiteSpace(lastModified))
|
if (string.IsNullOrWhiteSpace(lastModified))
|
||||||
await feed.WriteUpdated(DateTimeOffset.Now);
|
await feed.WriteUpdated(DateTimeOffset.Now);
|
||||||
|
@ -86,12 +88,14 @@ namespace PolyFeed
|
||||||
string url = source.Entries.Url.Attribute == string.Empty ?
|
string url = source.Entries.Url.Attribute == string.Empty ?
|
||||||
urlNode.InnerText : urlNode.Attributes[source.Entries.Url.Attribute].DeEntitizeValue;
|
urlNode.InnerText : urlNode.Attributes[source.Entries.Url.Attribute].DeEntitizeValue;
|
||||||
|
|
||||||
|
Uri entryUri = new Uri(new Uri(source.Feed.Url), new Uri(url));
|
||||||
SyndicationItem nextItem = new SyndicationItem() {
|
AtomEntry nextItem = new AtomEntry() {
|
||||||
Id = new Uri(new Uri(source.Feed.Url), new Uri(url)).ToString(),
|
Id = entryUri.ToString(),
|
||||||
Title = ReferenceSubstitutor.Replace(source.Entries.Title, nextNode),
|
Title = ReferenceSubstitutor.Replace(source.Entries.Title, nextNode),
|
||||||
Description = ReferenceSubstitutor.Replace(source.Entries.Content, nextNode),
|
Description = ReferenceSubstitutor.Replace(source.Entries.Content, nextNode),
|
||||||
|
ContentType = "html"
|
||||||
};
|
};
|
||||||
|
nextItem.AddLink(new SyndicationLink(entryUri, AtomLinkTypes.Alternate));
|
||||||
|
|
||||||
if (source.Entries.Published != null) {
|
if (source.Entries.Published != null) {
|
||||||
nextItem.Published = DateTime.Parse(
|
nextItem.Published = DateTime.Parse(
|
||||||
|
@ -130,7 +134,8 @@ namespace PolyFeed
|
||||||
await feed.Flush();
|
await feed.Flush();
|
||||||
xml.WriteEndDocument();
|
xml.WriteEndDocument();
|
||||||
xml.Flush();
|
xml.Flush();
|
||||||
return result.ToString();
|
xml.Close();
|
||||||
|
return Encoding.UTF8.GetString(stream.ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ namespace PolyFeed
|
||||||
AddRules(new List<LexerRule<SubstitutionToken>>() {
|
AddRules(new List<LexerRule<SubstitutionToken>>() {
|
||||||
new LexerRule<SubstitutionToken>(SubstitutionToken.Text, @"[^{}]+"),
|
new LexerRule<SubstitutionToken>(SubstitutionToken.Text, @"[^{}]+"),
|
||||||
new LexerRule<SubstitutionToken>(SubstitutionToken.Identifier, @"[^{}]+"),
|
new LexerRule<SubstitutionToken>(SubstitutionToken.Identifier, @"[^{}]+"),
|
||||||
new LexerRule<SubstitutionToken>(SubstitutionToken.BraceOpen, @"\{"),
|
new LexerRule<SubstitutionToken>(SubstitutionToken.BraceOpen, @"\{+"),
|
||||||
new LexerRule<SubstitutionToken>(SubstitutionToken.BraceClose, @"\}"),
|
new LexerRule<SubstitutionToken>(SubstitutionToken.BraceClose, @"\}+"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[feed]
|
[feed]
|
||||||
output = "CrossCodeLea-Twitter.atom"
|
output = "euruicimages-Twitter.atom"
|
||||||
|
|
||||||
url = "https://mobile.twitter.com/CrossCodeLea"
|
url = "https://mobile.twitter.com/euruicimages"
|
||||||
|
|
||||||
source_type = "html"
|
source_type = "html"
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ logo_url = { selector = ".avatar img", attribute = "src" }
|
||||||
|
|
||||||
[entries]
|
[entries]
|
||||||
selector = ".tweet"
|
selector = ".tweet"
|
||||||
title = "Tweet by {.username}"
|
title = "Tweet by {{.username}} {{.tweet-social-context}}"
|
||||||
content = "{.tweet-social-context}<br />{.avatar}{.fullname}<br />{.tweet-content}"
|
content = "<p><strong>{.avatar}{.fullname}:</strong></p>\n{.tweet-text}"
|
||||||
|
|
||||||
url = { selector = ".metadata a", attribute = "href" }
|
url = { selector = ".metadata a", attribute = "href" }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue