Exemplo n.º 1
0
        public SyndicationFeed GetBlog()
        {
            string feedUrl = linkGenerator.GetUriByAction(contextAccessor.HttpContext, "Rss20", "Feed");

            SyndicationFeed feed = new SyndicationFeed(settingRepository.BlogName, settingRepository.BlogDescription, new Uri(feedUrl));

            //foreach (ApplicationUser user in feedRepository.GetAllUsers())
            //{
            //    feed.Authors.Add(new SyndicationPerson(user.Email, user.DisplayName, getAuthorUrl(user)));
            //}

            //foreach (Category category in feedRepository.GetAllCategories())
            //{
            //    feed.Categories.Add(new SyndicationCategory(category.Name));
            //}

            List <SyndicationItem> items = new List <SyndicationItem>(settingRepository.ItemsShownInFeed);

            foreach (Post post in feedRepository.GetPosts(settingRepository.ItemsShownInFeed))
            {
                string content = post.Content ?? string.Empty;

                int moreIndex = content.IndexOf("[more]", StringComparison.OrdinalIgnoreCase);
                if (moreIndex >= 0)
                {
                    content = content.Remove(moreIndex, 6);
                }

                items.Add(new SyndicationItem(
                              post.Title,
                              new TextSyndicationContent(content, TextSyndicationContentKind.Html),
                              new Uri(linkGenerator.GetUriByRouteValues(contextAccessor.HttpContext, "PostDetailId", new { Id = post.Id })),
                              post.Id.ToString(),
                              post.LastModificationDate));
            }

            feed.Items = items;

            return(feed);
        }
Exemplo n.º 2
0
        public Task <RssChannel> GetChannel(CancellationToken cancellationToken = default(CancellationToken))
        {
            var posts = feedRepository.GetPosts(settings.ItemsShownInFeed);

            var channel = new RssChannel();

            channel.Title       = settings.BlogName;
            channel.Description = settings.BlogDescription;

            foreach (Category category in feedRepository.GetAllCategories())
            {
                channel.Categories.Add(new RssCategory(category.Name));
            }

            foreach (var user in feedRepository.GetAllUsers())
            {
                //    feed.Authors.Add(new SyndicationPerson(user.Email, user.DisplayName, getAuthorUrl(user)));
            }

            channel.Generator = Name;

            var indexUrl = urlHelper.Action("Index", "Post", null, contextAccessor.HttpContext.Request.Scheme);

            channel.Link = new Uri(indexUrl);

            string feedUrl = urlHelper.Action("Rss20", "Feed", null, contextAccessor.HttpContext.Request.Scheme);

            channel.SelfLink = new Uri(feedUrl);

            var items = new List <RssItem>();

            foreach (var post in posts)
            {
                var rssItem = new RssItem();
                rssItem.Author = post.Author.DisplayName;

                foreach (var c in post.PostCategories)
                {
                    rssItem.Categories.Add(new RssCategory(c.Category.Name));
                }

                string content = post.Content ?? string.Empty;

                int moreIndex = content.IndexOf("[more]", StringComparison.OrdinalIgnoreCase);
                if (moreIndex >= 0)
                {
                    content = content.Remove(moreIndex, 6);
                }
                rssItem.Description = content;
                rssItem.Guid        = new RssGuid(post.Id.ToString());
                string postUrl = urlHelper.RouteUrl("PostDetail", new { postSlug = post.Slug }, contextAccessor.HttpContext.Request.Scheme);

                rssItem.Link            = new Uri(postUrl);
                rssItem.PublicationDate = post.LastModificationDate;
                rssItem.Title           = post.Title;

                items.Add(rssItem);
            }

            channel.PublicationDate = posts.Max(x => (DateTime?)x.LastModificationDate).GetValueOrDefault(DateTime.MinValue);
            channel.Items           = items;

            return(Task.FromResult(channel));
        }
Exemplo n.º 3
0
        // GET
        public IActionResult Index()
        {
            var posts = _feedRepository.GetPosts(Program.CurrentUser);

            return(View(posts));
        }