/// <summary> /// Truncates a string on word breaks /// </summary> public static string TruncateWordBreak(this UmbracoHelper helper, string s, int maxLength) { var truncated = helper.Truncate(s, maxLength, true).ToString(); if (truncated.EndsWith("…")) { var lastSpaceIndex = truncated.LastIndexOf(' '); if (lastSpaceIndex > 0) { truncated = truncated.Substring(0, lastSpaceIndex) + "…"; } } return(truncated); }
public void Load() { var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current); BlogRoot = Content.Parent; EntryDate = (Content.HasValue("entryDate")) ? DateTime.Parse(Content.GetPropertyValue<string>("entryDate")) : Content.CreateDate; BlogContent = Content.GetPropertyValue<HtmlString>("content"); Categories = (Content.HasValue("categories")) ? umbracoHelper.Content(Content.GetPropertyValue<string>("categories").Split(',')) : new List<IPublishedContent>().AsEnumerable(); Tags = (Content.HasValue("tags")) ? Content.GetPropertyValue<string>("tags").Split(',') : new string[0]; MainImage = (Content.HasValue("mainImage")) ? JsonConvert.DeserializeObject<ImageCropDataSet>(Content.GetPropertyValue <string>("mainImage") ): null; Blurb = (Content.HasValue("blurb")) ? Content.GetPropertyValue<HtmlString>("blurb") : (HtmlString)umbracoHelper.Truncate(BlogContent, 800); Title = Content.Name; CommentsEnabled = (Content.HasValue("commentsEnabled", true)) ? Content.GetPropertyValue<bool>("commentsEnabled", true) : false; DisqusShortname = (Content.HasValue("disqusShortname", true)) ? Content.GetPropertyValue<string>("disqusShortname", true) : null; TwitterUsername = Content.GetPropertyValue<string>("twitterUsername", true); ShareDescription = Content.GetPropertyValue<string>("shareDescription", true); FullUrl = Content.UrlWithDomain(); var authorId = Content.GetProperty("author"); Author = (authorId != null && authorId.HasValue) ? new BlogAuthor( Convert.ToInt32( authorId.Value) ) : null; EnableShareIcons = (Content.HasValue("enableShareIcons", true)) ? Content.GetPropertyValue<bool>("enableShareIcons", true) : false; }