diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml
index 424c023336..d8a987b41d 100644
--- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml
+++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml
@@ -25,12 +25,13 @@
-
+
+
@foreach (var tag in Model.Post.Tags)
{
@tag.Name
}
-
+
@@ -73,7 +74,7 @@
- @Model.Post.Content
+ @Model.FormattedContent
diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs
index c42ac3f5bc..362f0902e8 100644
--- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs
+++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
+using System.Text;
using System.Threading.Tasks;
+using CommonMark;
+using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Blogging.Blogs;
@@ -24,9 +27,13 @@ namespace Volo.Blogging.Pages.Blog.Posts
[BindProperty]
public PostDetailsViewModel NewComment { get; set; }
+
+ public int CommentCount { get; set; }
public PostWithDetailsDto Post { get; set; }
+ public IHtmlContent FormattedContent { get; set; }
+
public IReadOnlyList
CommentsWithReplies { get; set; }
public BlogDto Blog { get; set; }
@@ -59,9 +66,29 @@ namespace Volo.Blogging.Pages.Blog.Posts
{
Blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Post = await _postAppService.GetByUrlAsync(new GetPostInput { BlogId = Blog.Id, Url = PostUrl });
+ FormattedContent = RenderMarkdown(Post.Content);
CommentsWithReplies = await _commentAppService.GetHierarchicalListOfPostAsync(new GetCommentListOfPostAsync() { PostId = Post.Id });
+ CountComments();
+ }
+
+ public void CountComments()
+ {
+ CommentCount = CommentsWithReplies.Count;
+ foreach (var commentWithReply in CommentsWithReplies)
+ {
+ CommentCount += commentWithReply.Replies.Count;
+ }
}
+ public IHtmlContent RenderMarkdown(string content)
+ {
+ byte[] bytes = Encoding.Default.GetBytes(content);
+ var utf8Content = Encoding.UTF8.GetString(bytes);
+
+ var html = CommonMarkConverter.Convert(utf8Content);
+
+ return new HtmlString(html);
+ }
public class PostDetailsViewModel
{
diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml
index a8c01af63b..995ccf58f5 100644
--- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml
+++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml
@@ -51,7 +51,7 @@
@post.Title
- @(post.Content == null ? "" : (post.Content.Length > 150 ? post.Content.Substring(150) : post.Content))
+ @(post.Content == null ? "" : (post.Content.Length > 150 ? post.Content.Substring(0,150) : post.Content))
@L["ContinueReading"]
@@ -187,7 +187,7 @@
@post.Title
- @(post.Content == null ? "" : (post.Content.Length > 250 ? post.Content.Substring(150) : post.Content))...
+ @(post.Content == null ? "" : (post.Content.Length > 250 ? post.Content.Substring(0, 150) : post.Content))...