From fe0a804677a7f60dfafd0bc3ef005b795d2e5748 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Wed, 14 Aug 2024 00:01:12 +0800 Subject: [PATCH] fix: tags in essay card and essay page. --- YaeBlog.Core/Services/RendererService.cs | 21 ++++++--------------- YaeBlog/Components/EssayCard.razor | 3 ++- YaeBlog/Pages/Essays.razor | 5 ++++- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/YaeBlog.Core/Services/RendererService.cs b/YaeBlog.Core/Services/RendererService.cs index 3195efb..e5b1d96 100644 --- a/YaeBlog.Core/Services/RendererService.cs +++ b/YaeBlog.Core/Services/RendererService.cs @@ -216,29 +216,20 @@ public partial class RendererService( private uint GetWordCount(BlogContent content) { - uint count = 0; - - foreach (char c in content.FileContent) - { - if (char.IsControl(c) || char.IsSymbol(c) - || char.IsSeparator(c)) - { - continue; - } - - count++; - } + int count = (from c in content.FileContent + where char.IsLetterOrDigit(c) + select c).Count(); logger.LogDebug("Word count of {} is {}", content.FileName, count); - return count; + return (uint)count; } private static string CalculateReadTime(uint wordCount) { - // 据说语文教学大纲规定,中国高中问阅读现代文的速度是600字每分钟 + // 据说语文教学大纲规定,中国高中生阅读现代文的速度是600字每分钟 int second = (int)wordCount / 10; - TimeSpan span = new TimeSpan(0, 0, second); + TimeSpan span = new(0, 0, second); return span.ToString("mm'分 'ss'秒'"); } diff --git a/YaeBlog/Components/EssayCard.razor b/YaeBlog/Components/EssayCard.razor index 6c4c34e..02fe971 100644 --- a/YaeBlog/Components/EssayCard.razor +++ b/YaeBlog/Components/EssayCard.razor @@ -1,3 +1,4 @@ +@using System.Text.Encodings.Web @using YaeBlog.Core.Models
@@ -13,7 +14,7 @@ @foreach (string key in Essay.Tags) { diff --git a/YaeBlog/Pages/Essays.razor b/YaeBlog/Pages/Essays.razor index 0a05d69..c61a9ea 100644 --- a/YaeBlog/Pages/Essays.razor +++ b/YaeBlog/Pages/Essays.razor @@ -1,4 +1,5 @@ @page "/blog/essays/{BlogKey}" +@using System.Text.Encodings.Web @using YaeBlog.Core.Abstractions @using YaeBlog.Core.Models @@ -25,7 +26,9 @@ @foreach (string tag in _essay!.Tags) { }