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
{

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

@ -16,8 +16,8 @@ namespace Volo.Blogging
{
CreateMap<Blog, BlogDto>();
CreateMap<Post, PostDto>();
CreateMap<Post, PostWithDetailsDto>().ForMember(x => x.Writer, opt => opt.Ignore()).Ignore(x=>x.CommentCount);
CreateMap<Comment, CommentWithDetailsDto>().ForMember(x => x.Writer, opt => opt.Ignore());
CreateMap<Post, PostWithDetailsDto>().Ignore(x=>x.Writer).Ignore(x=>x.CommentCount);
CreateMap<Comment, CommentWithDetailsDto>().Ignore(x => x.Writer);
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 System.Collections.Generic;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using Volo.Abp.Users;
using Volo.Blogging.Comments;
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",
"Posts": "Posts",
"Edit": "Edit",
"CommentDeletionWarningMessage": "Comment will be deleted.",
"BlogDeletionWarningMessage": "Blog will be deleted.",
"AreYouSure": "Are you sure?",
"Comment": "Comment",
"CoverImage": "Cover Image",
"CreateANewPost": "Create A New Post",
"CreateANewBlog": "Create A New Blog",
"WhatIsNew": "What is new?"
}
}

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

@ -22,9 +22,13 @@
"TagsInThisArticle": "Makalenin Etiketleri",
"Posts": "Yazılar",
"Edit": "Düzenle",
"CommentDeletionWarningMessage": "Yorum silinecek.",
"BlogDeletionWarningMessage": "Blog silinecek.",
"AreYouSure": "Emin misiniz?",
"Comment": "Yorum",
"CoverImage": "Kapak resmi",
"CreateANewPost": "Yeni Yazı oluştur",
"CreateANewBlog": "Yeni Blog Ekle",
"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">
@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-row>

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

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

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

@ -1,4 +1,7 @@
using System;
using System.Text;
using CommonMark;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.AspNetCore.Mvc.Razor.Internal;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
@ -13,6 +16,8 @@ namespace Volo.Blogging.Pages.Blog
public const string DefaultTitle = "Blog";
public const int MaxShortContentLength = 128;
public string GetTitle(string title = null)
{
if (string.IsNullOrWhiteSpace(title))
@ -23,6 +28,49 @@ namespace Volo.Blogging.Pages.Blog
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)
{
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="col-md-8 mx-auto">
<section class="post-content">
<p>@Html.Raw(Model.FormattedContent)</p>
<p>
@Html.Raw(RenderMarkdownToHtml(Model.Post.Content))
</p>
</section>
</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 IHtmlContent FormattedContent { get; set; }
public IReadOnlyList<CommentWithRepliesDto> CommentsWithReplies { get; set; }
public BlogDto Blog { get; set; }
@ -74,7 +72,6 @@ namespace Volo.Blogging.Pages.Blog.Posts
{
Blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Post = await _postAppService.GetForReadingAsync(new GetPostInput { BlogId = Blog.Id, Url = PostUrl });
FormattedContent = RenderMarkdown(Post.Content);
CommentsWithReplies = await _commentAppService.GetHierarchicalListOfPostAsync(new GetCommentListOfPostAsync() { PostId = Post.Id });
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 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>
</h2>
<p class="article-sum">
@(post.Content == null ? "" : (post.Content.Length > 150 ? post.Content.Substring(0, 150) + "..." : post.Content))
@(GetShortContent(post.Content))
</p>
<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>
</h3>
<p>
@(post.Content == null ? "" : (post.Content.Length > 250 ? post.Content.Substring(0, 150) : post.Content))...
@(GetShortContent(post.Content))
</p>
<div class="article-owner">
<div class="article-infos">

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

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

Loading…
Cancel
Save