Browse Source

bloggin module improvements

pull/441/head
Yunus Emre Kalkan 8 years ago
parent
commit
7e93316c7f
  1. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/GetPostInput.cs
  2. 4
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs
  3. 1
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  4. 4
      modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/en.json
  5. 4
      modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json
  6. 2
      modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Index.cshtml
  7. 7
      modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/index.js
  8. 48
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs
  9. 5
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml
  10. 13
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs
  11. 4
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml
  12. 6
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js

2
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/GetPostInput.cs

@ -1,4 +1,4 @@
using System;  using System;
namespace Volo.Blogging.Posts namespace Volo.Blogging.Posts
{ {

4
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs

@ -16,8 +16,8 @@ namespace Volo.Blogging
{ {
CreateMap<Blog, BlogDto>(); CreateMap<Blog, BlogDto>();
CreateMap<Post, PostDto>(); CreateMap<Post, PostDto>();
CreateMap<Post, PostWithDetailsDto>().ForMember(x => x.Writer, opt => opt.Ignore()).Ignore(x=>x.CommentCount); CreateMap<Post, PostWithDetailsDto>().Ignore(x=>x.Writer).Ignore(x=>x.CommentCount);
CreateMap<Comment, CommentWithDetailsDto>().ForMember(x => x.Writer, opt => opt.Ignore()); CreateMap<Comment, CommentWithDetailsDto>().Ignore(x => x.Writer);
CreateMap<Tag, TagDto>(); CreateMap<Tag, TagDto>();
} }
} }

1
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs

@ -5,7 +5,6 @@ using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using Volo.Abp.Users; using Volo.Abp.Users;
using Volo.Blogging.Comments; using Volo.Blogging.Comments;
using Volo.Blogging.Tagging; using Volo.Blogging.Tagging;

4
modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/en.json

@ -22,9 +22,13 @@
"TagsInThisArticle": "Tags in this article", "TagsInThisArticle": "Tags in this article",
"Posts": "Posts", "Posts": "Posts",
"Edit": "Edit", "Edit": "Edit",
"CommentDeletionWarningMessage": "Comment will be deleted.",
"BlogDeletionWarningMessage": "Blog will be deleted.",
"AreYouSure": "Are you sure?",
"Comment": "Comment", "Comment": "Comment",
"CoverImage": "Cover Image", "CoverImage": "Cover Image",
"CreateANewPost": "Create A New Post", "CreateANewPost": "Create A New Post",
"CreateANewBlog": "Create A New Blog",
"WhatIsNew": "What is new?" "WhatIsNew": "What is new?"
} }
} }

4
modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json

@ -22,9 +22,13 @@
"TagsInThisArticle": "Makalenin Etiketleri", "TagsInThisArticle": "Makalenin Etiketleri",
"Posts": "Yazılar", "Posts": "Yazılar",
"Edit": "Düzenle", "Edit": "Düzenle",
"CommentDeletionWarningMessage": "Yorum silinecek.",
"BlogDeletionWarningMessage": "Blog silinecek.",
"AreYouSure": "Emin misiniz?",
"Comment": "Yorum", "Comment": "Yorum",
"CoverImage": "Kapak resmi", "CoverImage": "Kapak resmi",
"CreateANewPost": "Yeni Yazı oluştur", "CreateANewPost": "Yeni Yazı oluştur",
"CreateANewBlog": "Yeni Blog Ekle",
"WhatIsNew": "Yeniler" "WhatIsNew": "Yeniler"
} }
} }

2
modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Index.cshtml

@ -23,7 +23,7 @@
<abp-column size-md="_6" class="text-right"> <abp-column size-md="_6" class="text-right">
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Blogs.Create)) @if (await Authorization.IsGrantedAsync(BloggingPermissions.Blogs.Create))
{ {
<abp-button icon="plus" text="@L["CreateNewBlog"].Value" button-type="Primary" id="CreateNewBlogButtonId"></abp-button> <abp-button icon="plus" text="@L["CreateANewBlog"].Value" button-type="Primary" id="CreateNewBlogButtonId"></abp-button>
} }
</abp-column> </abp-column>
</abp-row> </abp-row>

7
modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/index.js

@ -1,5 +1,6 @@
$(function () { $(function () {
var l = abp.localization.getResource('Blogging');
var _createModal = new abp.ModalManager(abp.appPath + 'Admin/Blogs/Create'); var _createModal = new abp.ModalManager(abp.appPath + 'Admin/Blogs/Create');
var _editModal = new abp.ModalManager(abp.appPath + 'Admin/Blogs/Edit'); var _editModal = new abp.ModalManager(abp.appPath + 'Admin/Blogs/Edit');
@ -20,7 +21,7 @@
items: items:
[ [
{ {
text: 'Edit', text: l('Edit'),
visible: function () { visible: function () {
return true; //TODO: Check permission return true; //TODO: Check permission
}, },
@ -31,11 +32,11 @@
} }
}, },
{ {
text: 'Delete', text: l('Delete'),
visible: function () { visible: function () {
return true; //TODO: Check permission return true; //TODO: Check permission
}, },
confirmMessage: function (data) { return 'Todo: fill this message' }, confirmMessage: function (data) { return l('BlogDeletionWarningMessage') },
action: function (data) { action: function (data) {
volo.blogging.blogs volo.blogging.blogs
.delete(data.record.id) .delete(data.record.id)

48
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs

@ -1,4 +1,7 @@
using System; using System;
using System.Text;
using CommonMark;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Localization; using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.AspNetCore.Mvc.Razor.Internal; using Microsoft.AspNetCore.Mvc.Razor.Internal;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
@ -13,6 +16,8 @@ namespace Volo.Blogging.Pages.Blog
public const string DefaultTitle = "Blog"; public const string DefaultTitle = "Blog";
public const int MaxShortContentLength = 128;
public string GetTitle(string title = null) public string GetTitle(string title = null)
{ {
if (string.IsNullOrWhiteSpace(title)) if (string.IsNullOrWhiteSpace(title))
@ -23,6 +28,49 @@ namespace Volo.Blogging.Pages.Blog
return title; return title;
} }
public string GetShortContent(string content)
{
var openingTag = "<p>";
var closingTag = "</p>";
var html = RenderMarkdownToString(content);
var splittedHtml = html.Split(closingTag);
if (splittedHtml.Length < 1)
{
return "";
}
var firstHtmlPart = splittedHtml[0];
var paragraphStartIndex = firstHtmlPart.IndexOf(openingTag, StringComparison.Ordinal) + openingTag.Length;
if (firstHtmlPart.Length - paragraphStartIndex <= MaxShortContentLength)
{
return firstHtmlPart.Substring(paragraphStartIndex);
}
return firstHtmlPart.Substring(paragraphStartIndex, MaxShortContentLength) + "...";
}
public IHtmlContent RenderMarkdownToHtml(string content)
{
byte[] bytes = Encoding.Default.GetBytes(content);
var utf8Content = Encoding.UTF8.GetString(bytes);
var html = CommonMarkConverter.Convert(utf8Content);
return new HtmlString(html);
}
public string RenderMarkdownToString(string content)
{
byte[] bytes = Encoding.Default.GetBytes(content);
var utf8Content = Encoding.UTF8.GetString(bytes);
return CommonMarkConverter.Convert(utf8Content);
}
public string ConvertDatetimeToTimeAgo(DateTime dt) public string ConvertDatetimeToTimeAgo(DateTime dt)
{ {
var timeDiff = DateTime.Now - dt; var timeDiff = DateTime.Now - dt;

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

@ -135,7 +135,10 @@
<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>@Html.Raw(Model.FormattedContent)</p> <p>
@Html.Raw(RenderMarkdownToHtml(Model.Post.Content))
</p>
</section> </section>
</div> </div>

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

@ -33,8 +33,6 @@ namespace Volo.Blogging.Pages.Blog.Posts
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; }
@ -74,7 +72,6 @@ namespace Volo.Blogging.Pages.Blog.Posts
{ {
Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); Blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Post = await _postAppService.GetForReadingAsync(new GetPostInput { BlogId = Blog.Id, Url = PostUrl }); Post = await _postAppService.GetForReadingAsync(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(); CountComments();
} }
@ -88,16 +85,6 @@ namespace Volo.Blogging.Pages.Blog.Posts
} }
} }
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
{ {
public Guid? RepliedCommentId { get; set; } public Guid? RepliedCommentId { get; set; }

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

@ -81,7 +81,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(0, 150) + "..." : post.Content)) @(GetShortContent(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>
@ -183,7 +183,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(0, 150) : post.Content))... @(GetShortContent(post.Content))
</p> </p>
<div class="article-owner"> <div class="article-owner">
<div class="article-infos"> <div class="article-infos">

6
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js

@ -1,5 +1,7 @@
(function ($) { (function ($) {
var l = abp.localization.getResource('Blogging');
$('div .replyForm').hide(); $('div .replyForm').hide();
$('div .editForm').hide(); $('div .editForm').hide();
@ -49,8 +51,8 @@
if (deleteCommentId != '' && deleteCommentId !== undefined) { if (deleteCommentId != '' && deleteCommentId !== undefined) {
abp.message.confirm( abp.message.confirm(
'Comment will be deleted.', // TODO: localize l('CommentDeletionWarningMessage'), // TODO: localize
'Are you sure?', l('Are you sure?)',
function(isConfirmed) { function(isConfirmed) {
if (isConfirmed) { if (isConfirmed) {
$.ajax({ $.ajax({

Loading…
Cancel
Save