Пример #1
0
        public PostPreview DefaultArticleExtractor(string url)
        {
            try
            {
                var    htmlDoc = new HtmlDocument();
                string html    = GetHtmlFromUrl(url);
                htmlDoc.LoadHtml(html);
                var titleNode = htmlDoc.DocumentNode.Descendants("title").First();

                var    node            = htmlDoc.DocumentNode;
                string fullDescription = GetDescription(node);

                var images = htmlDoc.DocumentNode.Descendants("img")
                             .Where(img => img.Attributes.Contains("src"))
                             .Select(img => GetAbsoluteUri(img.Attributes["src"].Value, url)).Distinct();


                var postPreview = new PostPreview
                {
                    Heading      = titleNode.InnerText,
                    Date         = DateTime.Now.ToUniversalTime().ToString(),
                    CardStyle    = "Horizontal",     // TODO: Enum
                    Snippet      = fullDescription,  // TODO:
                    OriginalLink = url,
                    Images       = images.ToArray(), // TODO: Filter out bad res. images
                    ImagesFromDb = new DbImage[] { } // TODO:
                };
                return(postPreview);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #2
0
        public static PostPreview ToPostPreview(this Feed feed, Utils utils)
        {
            var images      = utils.ExtractImages(feed.Link);
            var postPreview = new PostPreview()
            {
                Date         = feed.PublishedDate.ToString(),
                CardStyle    = "Horizontal",
                Heading      = feed.Title,
                Snippet      = feed.Description,
                OriginalLink = feed.Link,
                Images       = images,
                ImagesFromDb = new List <DbImage>().ToArray()
            };

            return(postPreview);
        }