protected override void Render(HtmlTextWriter writer)
        {
            IPagedCollection <MetaTag> blogMetaTags = MetaTags.GetMetaTagsForBlog(Blog, 0, int.MaxValue);

            foreach (MetaTag tag in blogMetaTags)
            {
                var htmlMetaTag = new HtmlMeta {
                    Content = tag.Content
                };

                if (!string.IsNullOrEmpty(tag.Name))
                {
                    htmlMetaTag.Name = tag.Name;
                }
                else
                {
                    htmlMetaTag.HttpEquiv = tag.HttpEquiv;
                }

                var newLineLiteral = new Literal {
                    Text = Environment.NewLine
                };
                newLineLiteral.RenderControl(writer);
                htmlMetaTag.RenderControl(writer);
            }
        }
        /// <summary>
        /// Renders the meta.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="id">The id.</param>
        /// <param name="name">The name.</param>
        /// <param name="content">The content.</param>
        private void RenderMeta(HtmlTextWriter w, string id, string name, string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                return;
            }
            var htmlMeta = new HtmlMeta {
                ID = id, Name = name, Content = content
            };

            htmlMeta.RenderControl(w);
        }
예제 #3
0
        protected override void Render(HtmlTextWriter writer)
        {
            //var ctx = Parent.Page
            SubtextContext ctx = base.SubtextContext as SubtextContext;

            if (ctx != null)
            {
                HtmlMeta summaryTitleMeta = new HtmlMeta();
                summaryTitleMeta.Name = "twitter:title";

                HtmlMeta descriptionMeta = new HtmlMeta();
                descriptionMeta.Name = "twitter:description";

                Entry entry = Cacher.GetEntryFromRequest(true, ctx);

                if (entry != null)
                {
                    string title       = entry.Title;
                    string description = entry.HasDescription ? entry.Description : entry.Body;

                    summaryTitleMeta.Content = title;

                    var cleanedDescription =
                        HttpUtility.HtmlDecode(Regex.Replace(description, "<[^>]*(>|$)", string.Empty));

                    var maxLen = (cleanedDescription.Length > 180) ? 180 : cleanedDescription.Length;

                    descriptionMeta.Content = cleanedDescription.Substring(0, maxLen) + "...";
                }
                else
                {
                    // get the default title/summary from the blog
                    summaryTitleMeta.Content = ctx.Blog.Title;
                    descriptionMeta.Content  = ctx.Blog.SubTitle;
                }
                summaryTitleMeta.RenderControl(writer);
                descriptionMeta.RenderControl(writer);
            }
        }