Exemple #1
0
        public RssJs GetRssJs(Uri currentHost)
        {
            var host = Utils.Texts.FromUriHost(currentHost);
            var alternativeLink = host + "/f/" + this.Url;

            var rss = new RssJs
            {
                Rss = new RssJs.RssRoot{
                    Channel = new RssJs.RssRoot.RssChannel
                    {
                        Title = Title,
                        Description = Description,
                        Link = alternativeLink,
                        LastBuildDate = LastModified.ToString("R"),
                        PubDate = LastModified.ToString("R"),
                        Ttl = RSS_TTL,
                        Generator = "Hobi Hobi",
                        Items = Posts.Select( x =>
                            {
                                var item = new RssJs.RssRoot.RssChannel.RssItem
                                {
                                    Description = x.Content,
                                    Guid = host + "/f/" + this.Url + "/" + x.Slug,
                                    PubDate = x.DatePublished.ToString("R")
                                };

                                if (!x.ShortLink.IsNullOrWhiteSpace())
                                    item.Link = x.ShortLink;
                                else
                                    item.Link = x.Link;

                                if (!Title.IsNullOrWhiteSpace())
                                    item.Title = x.Title;

                                return item;
                            }
                        ).ToList()
                    }
                }
            };

            return rss;
        }
Exemple #2
0
        private RssJs ConvertToRssJs(SyndicationFeed feed)
        {
            var alink = feed.Links.FirstOrDefault();

            var alternativeLink = "";

            if (alink != null)
                alternativeLink = alink.Uri.ToString();

            var ttl = 30;

            var rss = new RssJs
            {
                Rss = new RssJs.RssRoot{
                    Channel = new RssJs.RssRoot.RssChannel
                    {
                        Title = feed.Title.Text,
                        Description = feed.Description.Text,
                        Link = alternativeLink,
                        LastBuildDate = feed.LastUpdatedTime.ToString("R"),
                        PubDate = feed.LastUpdatedTime.ToString("R"),
                        Ttl = ttl,
                        Generator = feed.Generator,
                        Language = feed.Language,
                        Copyright = (feed.Copyright != null) ? feed.Copyright.Text : null,
                        Items = feed.Items.Select( x =>
                            {
                                var description = "";
                                if (x.Summary != null && x.Summary.Text.Exists())
                                    description = x.Summary.Text;
                                else if (x.Content != null)
                                {
                                    switch(x.Content.Type)
                                    {
                                        case "html" :
                                        case "text" :
                                        case "xhtml":
                                            description = (x.Content as TextSyndicationContent).Text;
                                            break;
                                        default: break;
                                    }
                                }

                                var item = new RssJs.RssRoot.RssChannel.RssItem
                                {
                                    Description = description,
                                    PubDate = x.PublishDate.ToString("R")
                                };

                                if (x.Id.Exists())
                                    item.Guid = x.Id;

                                if (!x.Title.Text.IsNullOrWhiteSpace())
                                    item.Title = x.Title.Text;

                                var link = x.Links.FirstOrDefault();

                                if (link != null && link.Uri != null)
                                    item.Link = link.Uri.ToString();

                                return item;
                            }
                        ).ToList()
                    }
                }
            };

            return rss;
        }