Browse Source

markdown for blogging

pull/7950/head
Yunus Emre Kalkan 8 years ago
parent
commit
c1e70ec1de
  1. 9
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml
  2. 27
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs
  3. 4
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml

9
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml

@ -25,12 +25,13 @@
</div> </div>
<div class="hero-content"> <div class="hero-content">
<p class="tags"> <p class="tags">
<abp-row> <p class="tags">
@foreach (var tag in Model.Post.Tags) @foreach (var tag in Model.Post.Tags)
{ {
<a href="#" class="tag">@tag.Name</a> <a href="#" class="tag">@tag.Name</a>
} }
</abp-row> </p>
</p> </p>
<h1> <h1>
<a href="#">@Model.Post.Title</a> <a href="#">@Model.Post.Title</a>
@ -52,7 +53,7 @@
</a> </a>
<span class="seperator">|</span> <span class="seperator">|</span>
<a href="#"> <a href="#">
<i class="fa fa-comment"></i> 60 @L["Comment"] <i class="fa fa-comment"></i> @Model.CommentCount @L["Comment"]
</a> </a>
</div> </div>
</div> </div>
@ -73,7 +74,7 @@
<div class="row"> <div class="row">
<div class="col-md-8 mx-auto"> <div class="col-md-8 mx-auto">
<section class="post-content"> <section class="post-content">
<p>@Model.Post.Content</p> <p>@Model.FormattedContent</p>
</section> </section>
</div> </div>

27
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs

@ -1,6 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using CommonMark;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Blogging.Blogs; using Volo.Blogging.Blogs;
@ -24,9 +27,13 @@ namespace Volo.Blogging.Pages.Blog.Posts
[BindProperty] [BindProperty]
public PostDetailsViewModel NewComment { get; set; } public PostDetailsViewModel NewComment { get; set; }
public int CommentCount { get; set; }
public PostWithDetailsDto Post { get; set; } public PostWithDetailsDto Post { get; set; }
public IHtmlContent FormattedContent { get; set; }
public IReadOnlyList<CommentWithRepliesDto> CommentsWithReplies { get; set; } public IReadOnlyList<CommentWithRepliesDto> CommentsWithReplies { get; set; }
public BlogDto Blog { get; set; } public BlogDto Blog { get; set; }
@ -59,9 +66,29 @@ namespace Volo.Blogging.Pages.Blog.Posts
{ {
Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); Blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Post = await _postAppService.GetByUrlAsync(new GetPostInput { BlogId = Blog.Id, Url = PostUrl }); Post = await _postAppService.GetByUrlAsync(new GetPostInput { BlogId = Blog.Id, Url = PostUrl });
FormattedContent = RenderMarkdown(Post.Content);
CommentsWithReplies = await _commentAppService.GetHierarchicalListOfPostAsync(new GetCommentListOfPostAsync() { PostId = Post.Id }); 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 public class PostDetailsViewModel
{ {

4
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml

@ -51,7 +51,7 @@
<a asp-page="./Detail" asp-route-postUrl="@post.Url" asp-route-blogShortName="@Model.BlogShortName">@post.Title</a> <a asp-page="./Detail" asp-route-postUrl="@post.Url" asp-route-blogShortName="@Model.BlogShortName">@post.Title</a>
</h2> </h2>
<p class="article-sum"> <p class="article-sum">
@(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))
</p> </p>
<a asp-page="./Detail" asp-route-postUrl="@post.Url" asp-route-blogShortName="@Model.BlogShortName" class="btn btn-primary btn-rounded">@L["ContinueReading"]</a> <a asp-page="./Detail" asp-route-postUrl="@post.Url" asp-route-blogShortName="@Model.BlogShortName" class="btn btn-primary btn-rounded">@L["ContinueReading"]</a>
@ -187,7 +187,7 @@
<a asp-page="./Detail" asp-route-postUrl="@post.Url" asp-route-blogShortName="@Model.BlogShortName">@post.Title</a> <a asp-page="./Detail" asp-route-postUrl="@post.Url" asp-route-blogShortName="@Model.BlogShortName">@post.Title</a>
</h3> </h3>
<p> <p>
@(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))...
</p> </p>
<div class="article-owner"> <div class="article-owner">
<div class="article-infos"> <div class="article-infos">

Loading…
Cancel
Save