private static void WriteRssItem(RssItem rssItem, XmlTextWriter writer) { writer.WriteStartElement("item"); writer.WriteElementString("title", rssItem.Title); writer.WriteElementString("link", URIHelper.ConvertToAbsUrl(rssItem.Link)); string shortDesc = StringHelper.StripHtmlTags(rssItem.Description); if (shortDesc.Length > 255) { shortDesc = shortDesc.Substring(0, 255) + " ..."; } writer.WriteElementString("description", shortDesc); writer.WriteElementString("author", rssItem.Author); writer.WriteElementString("pubDate", rssItem.PubDate); writer.WriteElementString("updated", rssItem.Updated); writer.WriteEndElement(); }
public string GetMetaDescription() { if (!string.IsNullOrEmpty(contextMetaDescription)) { return(contextMetaDescription); } var description = StringHelper.StripExtraSpaces(StringHelper.StripExtraLines(MetaDescription)); if (string.IsNullOrEmpty(description)) { description = StringHelper.StripExtraSpaces(StringHelper.StripExtraLines(this.ShortDescription)).Trim(); } if (description.Length < 100) { var mainContent = StringHelper.StripExtraSpaces(StringHelper.StripExtraLines(this.MainContent)).Trim(); if (mainContent.Contains("<script") || mainContent.Contains("<style")) { var htmlDocument = new HtmlAgilityPack.HtmlDocument(); htmlDocument.LoadHtml(mainContent); htmlDocument.DocumentNode.Descendants() .Where(n => n.Name == "script" || n.Name == "style" || n.NodeType == HtmlAgilityPack.HtmlNodeType.Comment) .ToList() .ForEach(n => n.Remove()); mainContent = StringHelper.StripExtraSpaces(StringHelper.StripExtraLines(StringHelper.StripHtmlTags(htmlDocument.DocumentNode.InnerText.Trim()))); } if (mainContent.Length > description.Length) { description = mainContent; } } description = StringHelper.StripExtraSpaces(StringHelper.StripExtraLines(StringHelper.StripHtmlTags(description))); if (description.Length > 255) { description = description.Substring(0, 255) + " ..."; } if (string.IsNullOrEmpty(description)) { description = GetPageTitle(); } /*if ((description == "") || (description == LinkTitle)) * { * description = StringHelper.StripHtmlTags(StringHelper.StripExtraSpaces(StringHelper.StripExtraLines(this.MainContent))); * * if (description.Length > 255) * description = description.Substring(0, 255) + " ..."; * }*/ description = Regex.Replace(description, "{.*}", ""); contextMetaDescription = description; return(contextMetaDescription); }