From 9d68c675cfc53c2cfef7ffc7cb44605d771a6d82 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Thu, 25 Jan 2024 11:41:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=AE=BE=E7=BD=AE=E9=BB=98?= =?UTF-8?q?=E8=AE=A4Builder=E9=85=8D=E7=BD=AE=E5=87=BD=E6=95=B0=E5=92=8CAp?= =?UTF-8?q?plication=E9=85=8D=E7=BD=AE=E5=87=BD=E6=95=B0=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BF=AE=E6=94=B9BlogEssay=E5=B7=A5=E5=85=B7=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YaeBlog.Core/Builder/BlogApplicationBuilder.cs | 6 ++++-- .../BlogApplicationBuilderExtension.cs | 2 +- .../Extensions/BlogApplicationExtension.cs | 5 +++++ YaeBlog.Core/Models/BlogEssay.cs | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/YaeBlog.Core/Builder/BlogApplicationBuilder.cs b/YaeBlog.Core/Builder/BlogApplicationBuilder.cs index 0b18ee1..0d358ab 100644 --- a/YaeBlog.Core/Builder/BlogApplicationBuilder.cs +++ b/YaeBlog.Core/Builder/BlogApplicationBuilder.cs @@ -31,8 +31,10 @@ public sealed class BlogApplicationBuilder : IHostApplicationBuilder public BlogApplication Build() { - this.ConfigureBlogApplication(); - return new BlogApplication(_hostApplicationBuilder.Build()); + this.ConfigureDefaultBlogApplicationBuilder(); + BlogApplication application = new(_hostApplicationBuilder.Build()); + application.ConfigureDefaultBlogApplication(); + return application; } public void ConfigureContainer( diff --git a/YaeBlog.Core/Extensions/BlogApplicationBuilderExtension.cs b/YaeBlog.Core/Extensions/BlogApplicationBuilderExtension.cs index e17927c..84d2ed4 100644 --- a/YaeBlog.Core/Extensions/BlogApplicationBuilderExtension.cs +++ b/YaeBlog.Core/Extensions/BlogApplicationBuilderExtension.cs @@ -12,7 +12,7 @@ namespace YaeBlog.Core.Extensions; public static class BlogApplicationBuilderExtension { - internal static void ConfigureBlogApplication(this BlogApplicationBuilder builder) + internal static void ConfigureDefaultBlogApplicationBuilder(this BlogApplicationBuilder builder) { builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", diff --git a/YaeBlog.Core/Extensions/BlogApplicationExtension.cs b/YaeBlog.Core/Extensions/BlogApplicationExtension.cs index a7de84b..18e99ac 100644 --- a/YaeBlog.Core/Extensions/BlogApplicationExtension.cs +++ b/YaeBlog.Core/Extensions/BlogApplicationExtension.cs @@ -7,6 +7,11 @@ namespace YaeBlog.Core.Extensions; public static class BlogApplicationExtension { + internal static void ConfigureDefaultBlogApplication(this BlogApplication application) + { + + } + public static void UsePreRenderProcessor(this BlogApplication application) where T : IPreRenderProcessor { diff --git a/YaeBlog.Core/Models/BlogEssay.cs b/YaeBlog.Core/Models/BlogEssay.cs index 08a3833..5927d64 100644 --- a/YaeBlog.Core/Models/BlogEssay.cs +++ b/YaeBlog.Core/Models/BlogEssay.cs @@ -16,6 +16,22 @@ public class BlogEssay public required string HtmlContent { get; init; } + public BlogEssay WithNewHtmlContent(string newHtmlContent) + { + var essay = new BlogEssay + { + Title = Title, + FileName = FileName, + PublishTime = PublishTime, + Description = Description, + WordCount = WordCount, + HtmlContent = newHtmlContent + }; + essay.Tags.AddRange(Tags); + + return essay; + } + public override string ToString() { return $"{Title}-{PublishTime}";