Explorar o código

增加相关搜索

懒得勤快 %!s(int64=4) %!d(string=hai) anos
pai
achega
952bf1969e

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

@@ -297,17 +297,14 @@ namespace Masuit.MyBlogs.Core.Common
         /// <param name="length">截取长度</param>
         /// <param name="min">摘要最少字数</param>
         /// <returns></returns>
-        public static async Task<string> GetSummary(this string html, int length = 150, int min = 10)
+        public static Task<string> GetSummary(this string html, int length = 150, int min = 10)
         {
             var context = BrowsingContext.New(Configuration.Default);
-            var doc = await context.OpenAsync(req => req.Content(html));
-            var summary = doc.DocumentElement.GetElementsByTagName("p").FirstOrDefault(n => n.TextContent.Length > min)?.TextContent ?? "没有摘要";
-            if (summary.Length > length)
+            return context.OpenAsync(req => req.Content(html)).ContinueWith(t =>
             {
-                return summary[..length] + "...";
-            }
-
-            return summary;
+                var summary = t.Result.DocumentElement.GetElementsByTagName("p").FirstOrDefault(n => n.TextContent.Length > min)?.TextContent ?? "没有摘要";
+                return summary.Length > length ? summary[..length] + "..." : summary;
+            });
         }
 
         public static string TrimQuery(this string path)

+ 8 - 8
src/Masuit.MyBlogs.Core/Controllers/Drive/DefaultController.cs → src/Masuit.MyBlogs.Core/Controllers/Drive/SitesController.cs

@@ -15,7 +15,7 @@ namespace Masuit.MyBlogs.Core.Controllers.Drive
 {
     [ApiController]
     [Route("api/")]
-    public class DefaultController : Controller
+    public class SitesController : Controller
     {
         readonly IDriveAccountService _siteService;
         readonly IDriveService _driveService;
@@ -23,7 +23,7 @@ namespace Masuit.MyBlogs.Core.Controllers.Drive
 
         public UserInfoDto CurrentUser => HttpContext.Session.Get<UserInfoDto>(SessionKey.UserInfo) ?? new UserInfoDto();
 
-        public DefaultController(IDriveAccountService siteService, IDriveService driveService, SettingService setting)
+        public SitesController(IDriveAccountService siteService, IDriveService driveService, SettingService setting)
         {
             this._siteService = siteService;
             this._driveService = driveService;
@@ -36,7 +36,7 @@ namespace Masuit.MyBlogs.Core.Controllers.Drive
         /// 返回所有sites
         /// </summary>
         /// <returns></returns>
-        [HttpGet("sites")]
+        [HttpGet("sites"), ResponseCache(Duration = 600)]
         public IActionResult GetSites()
         {
             return Json(_siteService.GetSites(), new JsonSerializerSettings()
@@ -48,7 +48,7 @@ namespace Masuit.MyBlogs.Core.Controllers.Drive
         /// 根据路径获取文件夹内容
         /// </summary>
         /// <returns></returns>
-        [HttpGet("sites/{siteName}/{**path}")]
+        [HttpGet("sites/{siteName}/{**path}"), ResponseCache(Duration = 600)]
         public async Task<IActionResult> GetDrectory(string siteName, string path)
         {
             if (string.IsNullOrEmpty(siteName))
@@ -105,7 +105,7 @@ namespace Masuit.MyBlogs.Core.Controllers.Drive
         /// </summary>
         /// <param name="path"></param>
         /// <returns></returns>
-        [HttpGet("files/{siteName}/{**path}")]
+        [HttpGet("files/{siteName}/{**path}"), ResponseCache(Duration = 600)]
         public async Task<IActionResult> Download(string siteName, string path)
         {
             try
@@ -131,7 +131,7 @@ namespace Masuit.MyBlogs.Core.Controllers.Drive
         /// 获取基本信息
         /// </summary>
         /// <returns></returns>
-        [HttpGet("info")]
+        [HttpGet("info"), ResponseCache(Duration = 600)]
         public IActionResult GetInfo()
         {
             bool isAollowAnonymous = !string.IsNullOrEmpty(_setting.Get("AllowAnonymouslyUpload")) && Convert.ToBoolean(_setting.Get("AllowAnonymouslyUpload"));
@@ -152,7 +152,7 @@ namespace Masuit.MyBlogs.Core.Controllers.Drive
         /// 获得readme
         /// </summary>
         /// <returns></returns>
-        [HttpGet("readme")]
+        [HttpGet("readme"), ResponseCache(Duration = 600)]
         public IActionResult GetReadme()
         {
             return Json(new
@@ -168,7 +168,7 @@ namespace Masuit.MyBlogs.Core.Controllers.Drive
         /// 获取文件分片上传路径
         /// </summary>
         /// <returns></returns>
-        [HttpGet("upload/{siteName}/{**fileName}")]
+        [HttpGet("upload/{siteName}/{**fileName}"), ResponseCache(Duration = 600)]
         public async Task<IActionResult> GetUploadUrl(string siteName, string fileName)
         {
             bool isAollowAnonymous = !string.IsNullOrEmpty(_setting.Get("AllowAnonymouslyUpload")) && Convert.ToBoolean(_setting.Get("AllowAnonymouslyUpload"));

+ 2 - 2
src/Masuit.MyBlogs.Core/Controllers/ErrorController.cs

@@ -49,7 +49,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                     Success = false,
                     Message = "页面未找到!"
                 }),
-                _ => View()
+                _ => View("Index")
             };
         }
 
@@ -95,7 +95,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                         }
                         break;
                     case NotFoundException:
-                        return RedirectToAction("Index");
+                        return Index();
                     case AccessDenyException:
                         var entry = ip.GetIPLocation();
                         var tips = Template.Create(CommonHelper.SystemSettings.GetOrAdd("AccessDenyTips", @"<h4>遇到了什么问题?</h4>

+ 4 - 4
src/Masuit.MyBlogs.Core/Controllers/SearchController.cs

@@ -1,5 +1,5 @@
 using CacheManager.Core;
-using JiebaNet.Segmenter;
+using EFCoreSecondLevelCacheInterceptor;
 using Masuit.MyBlogs.Core.Common;
 using Masuit.MyBlogs.Core.Extensions;
 using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
@@ -37,7 +37,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="page"></param>
         /// <param name="size"></param>
         /// <returns></returns>
-        [Route("search"), Route("search/{**wd}", Order = 1), Route("s", Order = 2), Route("s/{**wd}", Order = 3)]
+        [Route("search/{**wd}"), Route("search", Order = 1), Route("s/{**wd}", Order = 2), Route("s", Order = 3)]
         public async Task<ActionResult> Search([FromServices] IPostService postService, string wd = "", [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")] int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")] int size = 15)
         {
             wd = ChineseConverter.Convert(wd?.Trim() ?? "", ChineseConversionDirection.TraditionalToSimplified);
@@ -59,7 +59,6 @@ namespace Masuit.MyBlogs.Core.Controllers
 
             if (!string.IsNullOrWhiteSpace(wd) && !wd.Contains("锟斤拷"))
             {
-                new JiebaSegmenter().AddWord(wd);
                 if (!HttpContext.Session.TryGetValue("search:" + wd, out _) && !HttpContext.Request.IsRobot())
                 {
                     SearchDetailsService.AddEntity(new SearchDetails
@@ -69,7 +68,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                         IP = ClientIP
                     });
                     await SearchDetailsService.SaveChangesAsync();
-                    HttpContext.Session.Set("search:" + wd, wd.ToByteArray());
+                    HttpContext.Session.Set("search:" + wd, wd);
                 }
 
                 var posts = postService.SearchPage(page, size, wd);
@@ -82,6 +81,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 }
 
                 ViewBag.hotSearches = new List<KeywordsRank>();
+                ViewBag.RelateKeywords = SearchDetailsService.GetQuery(s => s.Keywords.Contains(wd) && s.Keywords != wd).Select(s => s.Keywords).GroupBy(s => s).OrderByDescending(g => g.Count()).Select(g => g.Key).Take(10).Cacheable().ToList();
                 return View(posts);
             }
 

+ 4 - 7
src/Masuit.MyBlogs.Core/Controllers/SubscribeController.cs

@@ -45,8 +45,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 {
                     Author = new Author
                     {
-                        Name = p.Author,
-                        Email = p.Email.MaskEmail()
+                        Name = p.Modifier
                     },
                     Body = summary,
                     Categories = new List<string>
@@ -90,7 +89,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                     {
                         Author = new Author()
                         {
-                            Name = ad.IndexId
+                            Name = ad.Title
                         },
                         Body = ad.Description,
                         Title = ad.Title,
@@ -124,8 +123,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 {
                     Author = new Author
                     {
-                        Name = p.Author,
-                        Email = p.Email.MaskEmail()
+                        Name = p.Modifier
                     },
                     Body = summary,
                     Categories = new List<string>
@@ -173,8 +171,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             {
                 Author = new Author
                 {
-                    Name = post.Author,
-                    Email = post.Email.MaskEmail()
+                    Name = post.Modifier
                 },
                 Body = summary,
                 Categories = new List<string>

+ 1 - 1
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.csproj

@@ -54,7 +54,7 @@
         <PackageReference Include="PanGu.HighLight" Version="1.0.0" />
         <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.1" />
         <PackageReference Include="System.Diagnostics.PerformanceCounter" Version="5.0.1" />
-        <PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.11" />
+        <PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.12" />
         <PackageReference Include="TimeZoneConverter" Version="3.5.0" />
         <PackageReference Include="WilderMinds.RssSyndication" Version="1.7.0" />
         <PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="5.2.5" />

+ 3 - 0
src/Masuit.MyBlogs.Core/Views/Error/TempDeny.cshtml

@@ -16,6 +16,7 @@
             background-size: cover;
             background-position: 50% 0;
             margin: 0;
+            min-height: 100vh;
         }
 
             body:before {
@@ -27,9 +28,11 @@
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+    <link href="https://cdn.staticfile.org/normalize/8.0.1/normalize.min.css" rel="stylesheet">
     <link href="https://cdn.staticfile.org/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
     <script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
     <script src="https://cdn.staticfile.org/jquery.ripples/0.5.3/jquery.ripples.min.js"></script>
+    <script src="https://cdn.staticfile.org/phaser/3.24.1/phaser.min.js"></script>
 </head>
 <body>
     <div class="container">

+ 18 - 9
src/Masuit.MyBlogs.Core/Views/Search/Search.cshtml

@@ -1,5 +1,4 @@
-@using System.Web
-@using Masuit.MyBlogs.Core.Common
+@using Masuit.MyBlogs.Core.Common
 @using Masuit.MyBlogs.Core.Models.Entity
 @using Masuit.MyBlogs.Core.Models.ViewModel
 @using Masuit.Tools
@@ -10,6 +9,7 @@
     ViewBag.Title = "站内搜索:" + ViewBag.Keyword;
     Layout = "~/Views/Shared/_Layout.cshtml";
     List<KeywordsRank> hotSearches = ViewBag.hotSearches;
+    List<string> relateKeywords = ViewBag.RelateKeywords;
     Advertisement ad = ViewBag.Ads;
 }
 <div class="container min-height610">
@@ -82,6 +82,15 @@
                         </div>
                     }
                 }
+                @if(relateKeywords?.Count>0) {
+                    <div class="margin-bot10">
+                        <h3>相关搜索:</h3>
+                        @foreach (var kw in relateKeywords)
+                        {
+                            <a asp-action="Search" asp-route-wd="@kw">@kw</a><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
+                        }
+                    </div>
+                }
                 @if (!string.IsNullOrEmpty((string)ViewBag.ErrorMsg))
                 {
                     <h3>@ViewBag.ErrorMsg</h3>
@@ -116,8 +125,8 @@
                         }
                         else
                         {
-                            <li><a href="@[email protected](Context.Request.Query["wd"])" aria-label="Previous">首页</a></li>
-                            <li><a href="@Context.Request.Path?page=@(Context.Request.Query["page"].ToString().ToInt32() - 1 <= 0 ? 1 : Context.Request.Query["page"].ToString().ToInt32() - 1)&[email protected](Context.Request.Query["wd"])" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
+                            <li><a asp-action="Search" asp-route-wd="@ViewBag.Keyword" aria-label="Previous">首页</a></li>
+                            <li><a asp-action="Search" asp-route-wd="@ViewBag.Keyword" asp-route-page="@(Context.Request.Query["page"].ToString().ToInt32() - 1 <= 0 ? 1 : Context.Request.Query["page"].ToString().ToInt32() - 1)" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
                         }
                         @if (pageStart > 1)
                         {
@@ -131,7 +140,7 @@
                             }
                             else
                             {
-                                <li><a href="@Context.Request.Path?page=@i&[email protected](Context.Request.Query["wd"])">@i</a></li>
+                                <li><a asp-action="Search" asp-route-page="@i" asp-route-wd="@ViewBag.Keyword">@i</a></li>
                             }
                         }
                         @if (pageEnd < pages)
@@ -141,12 +150,12 @@
                         @if (current == pages)
                         {
                             <li class="disabled"><a><span aria-hidden="true">&raquo;</span></a></li>
-                            <li class="disabled"><a>页</a></li>
+                            <li class="disabled"><a>最后一页</a></li>
                         }
                         else
                         {
-                            <li><a href="@Context.Request.Path?page=@(current + 1)&[email protected](Context.Request.Query["wd"])" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>
-                            <li><a href="@Context.Request.Path?page=@pages&[email protected](Context.Request.Query["wd"])" aria-label="Next">末页</a></li>
+                            <li><a asp-action="Search" asp-route-page="@(current + 1)" asp-route-wd="@ViewBag.Keyword" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>
+                            <li><a asp-action="Search" asp-route-page="@pages" asp-route-wd="@ViewBag.Keyword" aria-label="Next">最后一页</a></li>
                         }
                     </ul>
                 }
@@ -156,6 +165,6 @@
 </div>
 <script>
     $(".baidu").on("click", function(e) {
-		window.location.href = `https://www.baidu.com/s?wd=${$("#search").val().trim()}&[email protected]&ct=2097152`;
+		window.location.href = `https://www.baidu.com/s?wd=@ViewBag.Keyword&[email protected]&ct=2097152`;
 	});
 </script>

+ 37 - 21
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/main.js

@@ -232,12 +232,17 @@
 
 	this.CheckLogin = $scope.CheckLogin;
 
-	setInterval(function() {
-		fetch("/dashboard/getmessages").then(function(response) {
+	function getmsgs(show) {
+		fetch("/dashboard/getmessages",{
+            headers:{
+                'Accept': 'application/json',
+                'Content-Type': 'application/json'
+            }
+        }).then(function(response) {
             return response.json();
         }).then(function(res) {
             $scope.Msgs = res.Data;
-			if(res.Data.post.length > 0) {
+			if(res.Data.post.length > 0&&show) {
 				iziToast.info({
 					title:'待审核文章',
 					message:'有' + res.Data.post.length + '篇新文章待审核哦!',
@@ -245,7 +250,7 @@
 					transitionIn:'bounceInRight',
 				});
 			}
-			if(res.Data.msgs.length > 0) {
+			if(res.Data.msgs.length > 0&&show) {
 				iziToast.info({
 					title:'待审核留言',
 					message:'有' + res.Data.msgs.length + '条新留言待审核哦!',
@@ -253,7 +258,7 @@
 					transitionIn:'bounceInRight',
 				});
 			}
-			if(res.Data.comments.length > 0) {
+			if(res.Data.comments.length > 0&&show) {
 				iziToast.info({
 					title:'待审核文章评论',
 					message:'有' + res.Data.comments.length + '条新文章评论待审核哦!',
@@ -261,25 +266,36 @@
 					transitionIn:'bounceInRight',
 				});
 			}
+			$scope.$apply();
         }).catch(function(e) {
             console.log("Oops, error");
         });
-		fetch("/msg/GetUnreadMsgs").then(function(response) {
-            return response.json();
-        }).then(function(res) {
-            $scope.InternalMsgs = res.data.Data;
-			if($scope.InternalMsgs.length > 0) {
-				iziToast.info({
-					title:'未读消息',
-					message:'有' + $scope.InternalMsgs.length + '条未读消息!',
-					position:'topRight',
-					transitionIn:'bounceInRight',
-				});
-			}
-        }).catch(function(e) {
-            console.log("Oops, error");
-        });
-    },5000);
+        if (($scope.InternalMsgs||[]).length==0) {
+			fetch("/msg/GetUnreadMsgs",{
+                headers:{
+                    'Accept': 'application/json',
+                    'Content-Type': 'application/json'
+                }
+            }).then(function(response) {
+                return response.json();
+            }).then(function(res) {
+                $scope.InternalMsgs = res.Data;
+			    if($scope.InternalMsgs.length > 0&&show) {
+				    iziToast.info({
+					    title:'未读消息',
+					    message:'有' + $scope.InternalMsgs.length + '条未读消息!',
+					    position:'topRight',
+					    transitionIn:'bounceInRight',
+				    });
+			    }
+			    $scope.$apply();
+            }).catch(function(e) {
+                console.log("Oops, error");
+            });
+        }
+    }
+	getmsgs(true);
+	setInterval(getmsgs,5000);
 	$scope.read = function(id) {
 		$http.post("/msg/read", {
 			id

+ 4 - 4
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/partner.js

@@ -116,7 +116,7 @@
 
 	$scope.edit = function (item) {
 		$scope.partner = angular.copy(item);
-		$scope.partner.ExpireTime=$scope.partner.ExpireTime == null?"2099-12-31":$scope.partner.ExpireTime.Format("yyyy-MM-dd");
+		$scope.partner.ExpireTime=$scope.partner.ExpireTime == null?"2099-12-31":new Date($scope.partner.ExpireTime).Format("yyyy-MM-dd");
 		$scope.isAdd = false;
 		$scope.allowUpload=false;
 		layer.closeAll();
@@ -146,7 +146,7 @@
 	$scope.copy = function (item) {
 		$scope.partner = angular.copy(item);
 		delete $scope.partner.Id;
-		$scope.partner.ExpireTime=$scope.partner.ExpireTime == null?"2099-12-31":$scope.partner.ExpireTime.Format("yyyy-MM-dd");
+		$scope.partner.ExpireTime=$scope.partner.ExpireTime == null?"2099-12-31":new Date($scope.partner.ExpireTime).Format("yyyy-MM-dd");
 		$scope.isAdd = true;
 		$scope.allowUpload=false;
 		layer.closeAll();
@@ -267,10 +267,10 @@
 		isTime: true,
 		ishmsVal: true,
 		format: 'YYYY-MM-DD hh:mm:ss',
-		minDate: new Date().Format("yyyy-MM-dd 00:00:00"),
+		minDate: new Date().Format("yyyy-MM-dd"),
 		maxDate: '2099-12-31 23:59:59',
 		donefun: function (obj) {
-			$scope.partner.ExpireTime = obj.val;
+			$scope.partner.ExpireTime = new Date(obj.val).Format("yyyy-MM-dd 23:59:59");
 		}
 	});
 }]);