Exemplo n.º 1
0
        protected virtual SyndicationItem GetFeedItem(IMasterModel model, PostModel post, string rootUrl)
        {
            var posturl = post.UrlWithDomain();

            //Cannot continue if the url cannot be resolved - probably has publishing issues
            if (posturl.StartsWith("#"))
            {
                return null;
            }

            var appPath = _umbracoContext.HttpContext.Request.ApplicationPath;
            var rootUri = new Uri(rootUrl);
            var mediaRoot = rootUri.GetLeftPart(UriPartial.Authority) + appPath.EnsureStartsWith('/').TrimEnd('/');

            var content = _relativeMediaHref.Replace(GetPostContent(post), match =>
            {
                if (match.Groups.Count == 2)
                {
                    return $" href=\"{rootUrl.TrimEnd('/')}{match.Groups[1].Value.EnsureStartsWith('/')}\"";
                }
                return null;
            });
            content = _relativeMediaSrc.Replace(content, match =>
            {
                if (match.Groups.Count == 2)
                {
                    return $" src=\"{mediaRoot}{match.Groups[1].Value.EnsureStartsWith('/')}\"";
                }
                return null;
            });

            var item = new SyndicationItem(
                post.Name,
                new TextSyndicationContent(content, TextSyndicationContentKind.Html),
                new Uri(posturl),
                post.Id.ToString(CultureInfo.InvariantCulture),
                post.PublishedDate)
            {
                PublishDate = post.PublishedDate,

                //don't include this as it will override the main content bits
                //Summary = new TextSyndicationContent(post.Excerpt)
            };

            //TODO: attempting to add media:thumbnail...
            //item.ElementExtensions.Add(new SyndicationElementExtension("thumbnail", "http://search.yahoo.com/mrss/", "This is a test!"));

            foreach (var c in post.Categories)
            {
                item.Categories.Add(new SyndicationCategory(c));
            }

            return item;
        }
Exemplo n.º 2
0
        protected virtual SyndicationItem GetFeedItem(IMasterModel model, PostModel post, string rootUrl)
        {
            var content = _relativeMediaHref.Replace(GetPostContent(post), match =>
            {
                if (match.Groups.Count == 2)
                {
                    return " href=\"" +
                           rootUrl.TrimEnd('/') + match.Groups[1].Value.EnsureStartsWith('/') +
                           "\"";
                }
                return null;
            });
            content = _relativeMediaSrc.Replace(content, match =>
            {
                if (match.Groups.Count == 2)
                {
                    return " src=\"" +
                           rootUrl.TrimEnd('/') + match.Groups[1].Value.EnsureStartsWith('/') +
                           "\"";
                }
                return null;
            });

            var item = new SyndicationItem(
                post.Name,
                new TextSyndicationContent(content, TextSyndicationContentKind.Html),
                new Uri(post.UrlWithDomain()),
                post.Id.ToString(CultureInfo.InvariantCulture),
                post.PublishedDate)
            {
                PublishDate = post.PublishedDate,

                //don't include this as it will override the main content bits
                //Summary = new TextSyndicationContent(post.Excerpt)
            };

            //TODO: attempting to add media:thumbnail...
            //item.ElementExtensions.Add(new SyndicationElementExtension("thumbnail", "http://search.yahoo.com/mrss/", "This is a test!"));

            foreach (var c in post.Categories)
            {
                item.Categories.Add(new SyndicationCategory(c));
            }

            return item;
        }