Browse Source

优化 PostController 逻辑并更新列表样式

在 PostController.cs 中重构代码:
- 调整 HtmlDiff 调用顺序,优化内容处理逻辑。
- 对 ModifyDate 进行时区转换。
- 使用 posts 数组替代原始数据结构,提升可读性。
- 保留广告服务和复制禁用逻辑。

在 style.css 中新增列表样式:
- 为有序列表和无序列表设置统一的样式。
- 增加 margin-left,提升内容展示一致性。
懒得勤快 1 ngày trước cách đây
mục cha
commit
b4d9743743

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

@@ -196,17 +196,17 @@ public sealed class PostController : BaseController
         CheckPermission(post);
         var right = v1 <= 0 ? main : (await PostHistoryVersionService.GetAsync(v => v.Id == v1) ?? throw new NotFoundException("文章未找到")).ToPost();
         var left = v2 <= 0 ? main : (await PostHistoryVersionService.GetAsync(v => v.Id == v2) ?? throw new NotFoundException("文章未找到")).ToPost();
-        main.Id = id;
-        var (html1, html2) = left.Content.HtmlDiff(right.Content);
-        left.Content = await ReplaceVariables(html1).Next(s => CurrentUser.IsAdmin || Request.IsRobot() ? Task.FromResult(s) : s.InjectFingerprint(ClientIP.ToString()));
-        left.ModifyDate = left.ModifyDate.ToTimeZone(HttpContext.Session.Get<string>(SessionKey.TimeZone));
-        right.Content = await ReplaceVariables(html2).Next(s => CurrentUser.IsAdmin || Request.IsRobot() ? Task.FromResult(s) : s.InjectFingerprint(ClientIP.ToString()));
-        right.ModifyDate = right.ModifyDate.ToTimeZone(HttpContext.Session.Get<string>(SessionKey.TimeZone));
-        ViewBag.Ads = AdsService.GetsByWeightedPrice(2, AdvertiseType.InPage, Request.Location(), main.CategoryId, main.Label);
-        ViewBag.DisableCopy = post.DisableCopy;
         left.Id = main.Id;
         right.Id = main.Id;
-        return View(new[] { main, left, right }.OrderByDescending(v => v.ModifyDate).ToArray());
+        var posts = new[] { main, left, right }.OrderByDescending(v => v.ModifyDate).ToArray();
+        var (html2, html1) = posts[2].Content.HtmlDiff(posts[1].Content);
+        posts[2].Content = await ReplaceVariables(html2).Next(s => CurrentUser.IsAdmin || Request.IsRobot() ? Task.FromResult(s) : s.InjectFingerprint(ClientIP.ToString()));
+        posts[2].ModifyDate = posts[2].ModifyDate.ToTimeZone(HttpContext.Session.Get<string>(SessionKey.TimeZone));
+        posts[1].Content = await ReplaceVariables(html1).Next(s => CurrentUser.IsAdmin || Request.IsRobot() ? Task.FromResult(s) : s.InjectFingerprint(ClientIP.ToString()));
+        posts[1].ModifyDate = posts[1].ModifyDate.ToTimeZone(HttpContext.Session.Get<string>(SessionKey.TimeZone));
+        ViewBag.Ads = AdsService.GetsByWeightedPrice(2, AdvertiseType.InPage, Request.Location(), main.CategoryId, main.Label);
+        ViewBag.DisableCopy = post.DisableCopy;
+        return View(posts);
     }
 
     /// <summary>

+ 12 - 0
src/Masuit.MyBlogs.Core/wwwroot/Content/common/style.css

@@ -3353,6 +3353,18 @@ Custom bottom spacer
   justify-content: space-between;
 }
 
+.article-content ol,
+.encrypted-content ol {
+  list-style-type: decimal;
+  margin-left: 20px;
+}
+
+.article-content ul,
+.encrypted-content ul {
+  list-style-type: disc;
+  margin-left: 20px;
+}
+
 .article-content h3,
 .encrypted-content h3 {
   font-size: 1.45rem;