Browse Source

blogging module added share on twitter (without css)

pull/441/head
Yunus Emre Kalkan 8 years ago
parent
commit
e62cd146f1
  1. 19
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml
  2. 23
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs

19
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 @@
<a asp-page="/Blog/Posts/Index" asp-route-blogShortName="@Model.BlogShortName" asp-route-tagName="@tag.Name" class="tag">@tag.Name</a>
}
</div>
<a class="twitter-share-button"
href="@Model.GetTwitterShareUrl(Model.Post.Title, HttpContext.Request.GetEncodedUrl())" target="_blank">
Tweet
</a>
<div class="comment-form mt-4">
<div class="vs-blog-title mb-0">
<h3>@L["LeaveComment"]</h3>
@ -186,7 +193,7 @@
@commentWithRepliesDto.Comment.Text
</p>
<div class="comment-buttons font-75 bg-light">
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Create))
{
<a href="#" class="tag replyLink" data-relpyid="@commentWithRepliesDto.Comment.Id">
@ -210,7 +217,7 @@
</a>
}
</div>
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Create))
{
<div class="comment-form mt-4 replyForm">
@ -221,13 +228,13 @@
</h3>
<div>
<form method="post">
<input name="postId" value="@Model.Post.Id" hidden/>
<input name="repliedCommentId" value="@commentWithRepliesDto.Comment.Id" hidden/>
<input name="postId" value="@Model.Post.Id" hidden />
<input name="repliedCommentId" value="@commentWithRepliesDto.Comment.Id" hidden />
<div class="form-group">
<textarea class="form-control no-border" name="text" id="textBoxId" rows="4"></textarea>
</div>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Comment"].Value"/>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Comment"].Value" />
</form>
</div>
</div>
@ -263,7 +270,7 @@
@reply.Text
</p>
<div class="comment-buttons font-75 bg-light">
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Create))
{
<a href="#" class="tag replyLink" data-relpyid="@commentWithRepliesDto.Comment.Id">

23
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; }

Loading…
Cancel
Save