public async Task <IActionResult> Single(string slug) { try { ViewBag.Slug = slug; PostModel model = await _postProvider.GetPostModel(slug); // If unpublished and unauthorised redirect to error / 404. if (model.Post.Published == DateTime.MinValue && !User.Identity.IsAuthenticated) { return(Redirect("~/error")); } model.Blog = await _blogProvider.GetBlogItem(); model.Post.Description = model.Post.Description.MdToHtml(); model.Post.Content = model.Post.Content.MdToHtml(); return(View($"~/Views/Themes/{model.Blog.Theme}/Post.cshtml", model)); } catch { return(Redirect("~/error")); } }
public async Task <IActionResult> Single(string slug) { try { ViewBag.Slug = slug; PostModel model = await _postProvider.GetPostModel(slug); // If unpublished and unauthorised redirect to error / 404. if (model.Post.Published == DateTime.MinValue && !User.Identity.IsAuthenticated) { return(Redirect("~/error")); } model.Blog = await _blogProvider.GetBlogItem(); model.Post.Description = model.Post.Description.MdToHtml(); model.Post.Content = model.Post.Content.MdToHtml(); if (!model.Post.Author.Avatar.StartsWith("data:")) { model.Post.Author.Avatar = Url.Content($"~/{model.Post.Author.Avatar}"); } if (model.Post.PostType == PostType.Page) { string viewPath = $"~/Views/Themes/{model.Blog.Theme}/Page.cshtml"; if (IsViewExists(viewPath)) { return(View(viewPath, model)); } } return(View($"~/Views/Themes/{model.Blog.Theme}/Post.cshtml", model)); } catch { return(Redirect("~/error")); } }