懒得勤快 5 лет назад
Родитель
Сommit
f5e59cfbe5

+ 5 - 3
src/Masuit.MyBlogs.Core/Common/CommonHelper.cs

@@ -284,15 +284,17 @@ namespace Masuit.MyBlogs.Core.Common
         /// 获取文章摘要
         /// </summary>
         /// <param name="html"></param>
+        /// <param name="length">截取长度</param>
+        /// <param name="min">摘要最少字数</param>
         /// <returns></returns>
-        public static string GetSummary(this string html)
+        public static string GetSummary(this string html, int length = 150, int min = 10)
         {
             var doc = new HtmlDocument();
             doc.LoadHtml(html);
-            var summary = doc.DocumentNode.Descendants("p").FirstOrDefault(n => n.InnerText.Length > 10)?.InnerText ?? "没有摘要";
+            var summary = doc.DocumentNode.Descendants("p").FirstOrDefault(n => n.InnerText.Length > min)?.InnerText ?? "没有摘要";
             if (summary.Length > 150)
             {
-                return summary.Substring(0, 150) + "...";
+                return summary.Substring(0, length) + "...";
             }
 
             return summary;

+ 3 - 3
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -497,7 +497,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                     .Replace("{{time}}", post.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss"))
                     .Replace("{{title}}", post.Title)
                     .Replace("{{author}}", post.Author)
-                    .Replace("{{content}}", post.Content.RemoveHtmlTag(150))
+                    .Replace("{{content}}", post.Content.GetSummary())
                     .Replace("{{cancel}}", Url.Action("Subscribe", "Subscribe", new
                     {
                         c.Email,
@@ -730,7 +730,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                         .Replace("{{time}}", p.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss"))
                         .Replace("{{title}}", post.Title)
                         .Replace("{{author}}", post.Author)
-                        .Replace("{{content}}", post.Content.RemoveHtmlTag(150))
+                        .Replace("{{content}}", post.Content.GetSummary())
                         .Replace("{{cancel}}", Url.Action("Subscribe", "Subscribe", new
                         {
                             c.Email,
@@ -837,7 +837,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                     .Replace("{{link}}", link + "?email=" + c.Email)
                     .Replace("{{time}}", p.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss"))
                     .Replace("{{title}}", post.Title).Replace("{{author}}", post.Author)
-                    .Replace("{{content}}", post.Content.RemoveHtmlTag(150))
+                    .Replace("{{content}}", post.Content.GetSummary())
                     .Replace("{{cancel}}", Url.Action("Subscribe", "Subscribe", new
                     {
                         c.Email,

+ 1 - 2
src/Masuit.MyBlogs.Core/Controllers/SubscribeController.cs

@@ -9,7 +9,6 @@ using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools;
 using Masuit.Tools.DateTimeExt;
-using Masuit.Tools.Html;
 using Masuit.Tools.Logging;
 using Masuit.Tools.Security;
 using Microsoft.AspNetCore.Hosting;
@@ -78,7 +77,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                     Name = p.Author,
                     Email = p.Email
                 },
-                Body = p.Content.RemoveHtmlTag(300),
+                Body = p.Content.GetSummary(300, 10),
                 Categories = new List<string>
                 {
                     p.Category.Name

+ 3 - 1
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.xml

@@ -111,11 +111,13 @@
             <param name="title"></param>
             <returns></returns>
         </member>
-        <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.GetSummary(System.String)">
+        <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.GetSummary(System.String,System.Int32,System.Int32)">
             <summary>
             获取文章摘要
             </summary>
             <param name="html"></param>
+            <param name="length">截取长度</param>
+            <param name="min">摘要最少字数</param>
             <returns></returns>
         </member>
         <member name="T:Masuit.MyBlogs.Core.Common.HangfireHelper">

+ 1 - 2
src/Masuit.MyBlogs.Core/Views/Shared/_ArticleListItem.cshtml

@@ -39,10 +39,9 @@
                     </span>
                 </div>
                 <p>
-                    @Model.Content.GetSummary()
+                    @Html.Raw(Model.Content.GetSummary())
                 </p>
             </div>
-
         </div>
         <div class="row">
             @if (!string.IsNullOrEmpty(Model.Label))

+ 1 - 2
src/Masuit.MyBlogs.Core/Views/Shared/_ArticleListItem_Admin.cshtml

@@ -41,10 +41,9 @@
                     </span>
                 </div>
                 <p>
-                    @Model.Content.GetSummary()
+                    @Html.Raw(Model.Content.GetSummary())
                 </p>
             </div>
-
         </div>
         <div class="row">
             @if (!string.IsNullOrEmpty(Model.Label))

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Shared/_Aside.cshtml

@@ -41,7 +41,7 @@
                                 @foreach (NoticeOutputDto notice in Model.Notices)
                                 {
                                     <li class="news-item">
-                                        @Html.ActionLink(notice.Content.RemoveHtmlTag(45) + "...", "Details", "Notice", new { id = notice.Id }, new { @class = "tippy-scale", title = "查看详情" })
+                                        @Html.ActionLink(notice.Content.GetSummary(45, 2), "Details", "Notice", new { id = notice.Id }, new { @class = "tippy-scale", title = "查看详情" })
                                     </li>
                                 }
                             </ul>

+ 1 - 1
src/Masuit.MyBlogs.Core/wwwroot/Assets/UEditor/ueditor.config.front.js

@@ -36,7 +36,7 @@
         //工具栏上的所有的功能按钮和下拉框,可以在new编辑器的实例时选择自己需要的重新定义
         ,
         toolbars: [[
-            //'source', //源代码
+            'source', //源代码
             'removeformat', //清除格式
             //'cleardoc', //清空文档
             'autotypeset', //自动排版