From e62cd146f1deb7ef24d8e409eb02c48689e4b251 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 14 Sep 2018 15:22:56 +0300 Subject: [PATCH] blogging module added share on twitter (without css) --- .../Pages/Blog/Posts/Detail.cshtml | 19 ++++++++++----- .../Pages/Blog/Posts/Detail.cshtml.cs | 23 +++++++++++++++---- 2 files changed, 32 insertions(+), 10 deletions(-) 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 e069229c9f..fbcb941cfd 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 @@ -1,6 +1,7 @@ @page @inherits Volo.Blogging.Pages.Blog.BloggingPage @using Microsoft.AspNetCore.Authorization +@using Microsoft.AspNetCore.Http.Extensions @using Volo.Blogging @using Volo.Blogging.Pages.Blog.Posts @inject IAuthorizationService Authorization @@ -153,6 +154,12 @@ @tag.Name } + + + Tweet + +

@L["LeaveComment"]

@@ -186,7 +193,7 @@ @commentWithRepliesDto.Comment.Text

- + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Create)) { @@ -210,7 +217,7 @@ }
- + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Create)) {
@@ -221,13 +228,13 @@
- - + +
- +
@@ -263,7 +270,7 @@ @reply.Text

- + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Create)) { 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 d62ebffbbf..48c1b6dc96 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,9 +1,7 @@ using System; using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; -using CommonMark; -using Microsoft.AspNetCore.Html; +using System.Web; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Volo.Blogging.Blogs; @@ -16,6 +14,7 @@ namespace Volo.Blogging.Pages.Blog.Posts { public class DetailModel : PageModel { + private const int TwitterLinkLength = 23; private readonly IPostAppService _postAppService; private readonly IBlogAppService _blogAppService; private readonly ICommentAppService _commentAppService; @@ -28,7 +27,7 @@ namespace Volo.Blogging.Pages.Blog.Posts [BindProperty] public PostDetailsViewModel NewComment { get; set; } - + public int CommentCount { get; set; } public PostWithDetailsDto Post { get; set; } @@ -85,6 +84,22 @@ namespace Volo.Blogging.Pages.Blog.Posts } } + public string GetTwitterShareUrl(string title, string url) + { + var readAtString = " | Read More At"; + var linkedAccounts = "" ; + + var otherCharsLength = (readAtString + linkedAccounts).Length; + var maxTitleLength = 280 - TwitterLinkLength - otherCharsLength; + + title = title.Length < maxTitleLength ? title : title.Substring(0, maxTitleLength -3) + "..."; + + var text = title + readAtString + url + linkedAccounts; + + var builder = new UriBuilder("https://twitter.com/intent/tweet") { Query = "text=" + HttpUtility.UrlEncode(text) }; + return builder.ToString(); + } + public class PostDetailsViewModel { public Guid? RepliedCommentId { get; set; }