public ActionResult BlogDetails(AgilityContentItem module) { #region --- Get Blog Config and Repos --- var blogConfigRef = module["BlogConfiguration"] as string; AgilityContentItem blogConfig = null; IAgilityContentRepository <AgilityContentItem> blogPosts = null; IAgilityContentRepository <AgilityContentItem> blogCategories = null; IAgilityContentRepository <AgilityContentItem> blogTags = null; IAgilityContentRepository <AgilityContentItem> blogAuthors = null; BlogUtils.GetBlogConfig(blogConfigRef, out blogConfig, out blogPosts, out blogCategories, out blogTags, out blogAuthors); #endregion #region --- Resolve Dynamic Post and Category (if any) --- var post = ResolveBlogPostDetails(); if (post == null || !post.IsBlogPost()) { Agility.Web.Tracing.WebTrace.WriteErrorLine("Cannot resolve current dynamic item to a Blog Posts."); return(null); } var currentNode = SiteMap.CurrentNode; AgilityContentItem currentCategory = null; if (currentNode != null && currentNode.ParentNode != null) { currentCategory = AgilityContext.GetDynamicPageItem <AgilityContentItem>(currentNode.ParentNode); } //only set category if the parent dynamic item is a category if (currentCategory != null && !currentCategory.IsBlogCategory()) { currentCategory = null; } #endregion #region --- Get Related Posts --- int relatedPostsLimit; int.TryParse(string.Format("{0}", module["RelatedPostsLimit"]), out relatedPostsLimit); if (relatedPostsLimit < 0) { relatedPostsLimit = 0; } var relatedPosts = BlogUtils.GetRelatedPosts(post, blogPosts, true, relatedPostsLimit); #endregion #region --- Set SEO Properties --- string canonicalUrl = post.BlogDynamicUrl(blogConfig, currentCategory); AgilityContext.CanonicalLink = BlogUtils.GetAbsoluteUrl(canonicalUrl); //Enables image for twitter cards - but twitter cards need to be enabled ... //to enable twitter cards include setting in app settings in web.config AgilityContext.FeaturedImageUrl = BlogUtils.GetPostImageUrl(blogConfig, post, PostImageType.Details); if (string.IsNullOrEmpty(AgilityContext.Page.MetaTags)) { AgilityContext.Page.MetaTags = Server.HtmlEncode(BlogUtils.GetPostDescription(post, "Excerpt", 255, true)); } string websiteName = blogConfig["WebsiteName"] as string; if (string.IsNullOrEmpty(websiteName)) { websiteName = AgilityContext.WebsiteName; } AgilityContext.Page.MetaTagsRaw += string.Format( "{6}" + "<meta property='og:title' content='{0}' />" + "<meta property='og:type' content='{1}' />" + "<meta property='og:url' content='{2}' />" + "<meta property='og:image' content='{3}' />" + "<meta property='og:site_name' content='{4}' />" + "<meta property='og:description' content='{5}' />", Server.HtmlEncode(AgilityContext.Page.Title), "article", Request.Url.ToString(), BlogUtils.GetPostImageUrl(blogConfig, post, PostImageType.Details), websiteName, Server.HtmlEncode(AgilityContext.Page.MetaTags), Environment.NewLine ); #endregion #region --- Set ViewModel --- var model = new PostViewModel(); model.Configuration = blogConfig; model.Post = post; model.RelatedPosts = relatedPosts; model.CurrentCategory = currentCategory; model.Module = module; model.Categories = BlogUtils.GetItemsByIDs(blogCategories.ContentReferenceName, post["CategoriesIDs"]);; model.Tags = BlogUtils.GetItemsByIDs(blogTags.ContentReferenceName, post["BlogTagsIDs"]);; #endregion return(PartialView(AgilityComponents.TemplatePath("Blog-PostDetailsModule"), model)); }