Example #1
0
        public string ExtractFirstImargeUrl(IPost post, IUrlHelper urlHelper)
        {
            if (post == null)
            {
                return(string.Empty);
            }
            if (urlHelper == null)
            {
                return(string.Empty);
            }

            var result = filter.ExtractFirstImageUrl(post.Content);

            if (result == null)
            {
                return(string.Empty);
            }

            if (result.StartsWith("http"))
            {
                return(result);
            }

            var baseUrl = string.Concat(urlHelper.ActionContext.HttpContext.Request.Scheme,
                                        "://",
                                        urlHelper.ActionContext.HttpContext.Request.Host.ToUriComponent());

            return(baseUrl + result);
        }
        public string ExtractFirstImargeUrl(IPost post, IUrlHelper urlHelper, string fallbackImageUrl = null)
        {
            if (urlHelper == null)
            {
                return(string.Empty);
            }

            var baseUrl = string.Concat(urlHelper.ActionContext.HttpContext.Request.Scheme,
                                        "://",
                                        urlHelper.ActionContext.HttpContext.Request.Host.ToUriComponent());

            if (!string.IsNullOrWhiteSpace(firstImageUrl))
            {
                if (firstImageUrl.StartsWith("http"))
                {
                    return(firstImageUrl);
                }

                return(baseUrl + firstImageUrl); //don't extract it more than once
            }

            if (post == null)
            {
                return(string.Empty);
            }


            firstImageUrl = filter.ExtractFirstImageUrl(post.Content);

            if (firstImageUrl == null)
            {
                return(fallbackImageUrl);
            }

            if (firstImageUrl.StartsWith("http"))
            {
                return(firstImageUrl);
            }



            return(baseUrl + firstImageUrl);
        }
Example #3
0
        public string ExtractFirstImageUrl(IContentItem item, IUrlHelper urlHelper, string fallbackImageUrl = null)
        {
            if (urlHelper == null)
            {
                return(string.Empty);
            }
            if (item == null)
            {
                return(string.Empty);
            }

            var baseUrl = string.Concat(urlHelper.ActionContext.HttpContext.Request.Scheme,
                                        "://",
                                        urlHelper.ActionContext.HttpContext.Request.Host.ToUriComponent());

            if (item.ContentType == "markdown")
            {
                var mdImg = _markdownProcessor.ExtractFirstImageUrl(item.Content);
                if (!string.IsNullOrEmpty(mdImg))
                {
                    if (mdImg.StartsWith("http"))
                    {
                        return(mdImg);
                    }

                    return(baseUrl + mdImg);
                }

                return(string.Empty);
            }

            if (!string.IsNullOrWhiteSpace(firstImageUrl) && pslug == item.Slug)
            {
                if (firstImageUrl.StartsWith("http"))
                {
                    return(firstImageUrl);
                }

                return(baseUrl + firstImageUrl); //don't extract it more than once
            }

            if (item == null)
            {
                return(string.Empty);
            }


            firstImageUrl = _htmlProcessor.ExtractFirstImageUrl(item.Content);
            pslug         = item.Slug;

            if (firstImageUrl == null)
            {
                return(fallbackImageUrl);
            }

            if (firstImageUrl.StartsWith("http"))
            {
                return(firstImageUrl);
            }



            return(baseUrl + firstImageUrl);
        }