Exemplo n.º 1
0
    async Task AddPostsToFeedAsync(Feed feed, IEnumerable <FeedItem> feed_items)
    {
        foreach (var item in feed_items)
        {
            var post_title = ExtractTextFromHtml(item.Title);
            var post_id    = MakeSafeId(post_title);

            var post = new Feed.Post(feed, post_id)
            {
                GUID          = item.Id,
                Link          = item.Link,
                Title         = post_title,
                DatePublished = (DateTime)item.PublishingDate,
                Description   = ExtractTextFromHtml(item.Description),
            };

            var post_content_filename = Path.Combine(FeedDirectory, feed.ID, post_id);

            try
            {
                var post_content = (await ProcessHtmlAsync(item.Content is null ? item.Description : item.Content, post)).Trim();

                await WriteToFileAsync($"{post_content_filename}.post", post.Serialize());
                await WriteToFileAsync($"{post_content_filename}.content", post_content.Trim());

                feed.Posts.Add(post);
            }
            catch (Exception e) {; }
        }
    }
Exemplo n.º 2
0
 public async Task MarkPostUnreadAsync(Feed.Post post)
 {
     if (post.Read)
     {
         post.Read = false;
         var post_filepath = Path.Combine(FeedDirectory, post.ParentFeed.ID, $"{post.ID}.post");
         if (File.Exists(post_filepath))
         {
             using (var post_file = new StreamWriter(post_filepath))
                 await post_file.WriteAsync(post.Serialize());
         }
     }
 }