diff --git a/YaeBlog/Commands/YaeBlogCommand.cs b/YaeBlog/Commands/YaeBlogCommand.cs index b71539e..770b339 100644 --- a/YaeBlog/Commands/YaeBlogCommand.cs +++ b/YaeBlog/Commands/YaeBlogCommand.cs @@ -110,7 +110,12 @@ public sealed class YaeBlogCommand await essayScanService.SaveBlogContent(new BlogContent( new FileInfo(Path.Combine(blogOption.Value.Root, "drafts", file + ".md")), - new MarkdownMetadata { Title = file, Date = DateTimeOffset.Now, UpdateTime = DateTimeOffset.Now }, + new MarkdownMetadata + { + Title = file, + Date = DateTimeOffset.Now.ToString("o"), + UpdateTime = DateTimeOffset.Now.ToString("o") + }, string.Empty, true, [], [])); Console.WriteLine($"Created new blog '{file}."); @@ -138,9 +143,8 @@ public sealed class YaeBlogCommand return; } - content.Metadata.UpdateTime = DateTimeOffset.Now; + content.Metadata.UpdateTime = DateTimeOffset.Now.ToString("o"); await essayScanService.SaveBlogContent(content, content.IsDraft); - }, filenameArgument, new BlogOptionsBinder(), new LoggerBinder(), new EssayScanServiceBinder()); } @@ -239,7 +243,8 @@ public sealed class YaeBlogCommand } // 设置发布的时间 - content.Metadata.Date = DateTime.Now; + content.Metadata.Date = DateTimeOffset.Now.ToString("o"); + content.Metadata.UpdateTime = DateTimeOffset.Now.ToString("o"); // 将选中的博客文件复制到posts await essayScanService.SaveBlogContent(content, isDraft: false); diff --git a/YaeBlog/Components/Pages/Archives.razor b/YaeBlog/Components/Pages/Archives.razor index 883f33b..55204f0 100644 --- a/YaeBlog/Components/Pages/Archives.razor +++ b/YaeBlog/Components/Pages/Archives.razor @@ -19,7 +19,7 @@ - @foreach (IGrouping group in _essays) + @foreach (IGrouping group in _essays) {
@@ -30,7 +30,7 @@
@foreach (BlogEssay essay in group) { - +
@(essay.PublishTime.ToString("MM月dd日")) @@ -51,13 +51,13 @@
@code { - private readonly List> _essays = []; + private readonly List> _essays = []; protected override void OnInitialized() { base.OnInitialized(); _essays.AddRange(from essay in Contents.Essays - group essay by new DateTime(essay.PublishTime.Year, 1, 1)); + group essay by new DateTimeOffset(essay.PublishTime.Year, 1, 1,0, 0, 0, TimeSpan.Zero)); } } diff --git a/YaeBlog/Components/Pages/Index.razor b/YaeBlog/Components/Pages/Index.razor index dab799c..96c96b1 100644 --- a/YaeBlog/Components/Pages/Index.razor +++ b/YaeBlog/Components/Pages/Index.razor @@ -26,7 +26,7 @@

- 平平无奇的计算机科学与技术学徒,连微小的贡献都没做。 + 学过一些基础的计算机知识,略懂一些代码。

diff --git a/YaeBlog/Models/MarkdownMetadata.cs b/YaeBlog/Models/MarkdownMetadata.cs index 7ef93fa..9aab220 100644 --- a/YaeBlog/Models/MarkdownMetadata.cs +++ b/YaeBlog/Models/MarkdownMetadata.cs @@ -4,9 +4,9 @@ public class MarkdownMetadata { public string? Title { get; set; } - public DateTimeOffset Date { get; set; } + public string? Date { get; set; } - public DateTimeOffset UpdateTime { get; set; } + public string? UpdateTime { get; set; } public List? Tags { get; set; } } diff --git a/YaeBlog/Services/RendererService.cs b/YaeBlog/Services/RendererService.cs index 7069a10..69b648c 100644 --- a/YaeBlog/Services/RendererService.cs +++ b/YaeBlog/Services/RendererService.cs @@ -39,6 +39,14 @@ public partial class RendererService( foreach (BlogContent content in preProcessedContents) { (uint wordCount, string readTime) = GetWordCount(content); + DateTimeOffset publishDate = content.Metadata.Date is null + ? DateTimeOffset.Now + : DateTimeOffset.Parse(content.Metadata.Date); + // 如果不存在最后的更新时间,就把更新时间设置为发布时间 + DateTimeOffset updateTime = content.Metadata.UpdateTime is null + ? publishDate + : DateTimeOffset.Parse(content.Metadata.UpdateTime); + BlogEssay essay = new() { Title = content.Metadata.Title ?? content.BlogName, @@ -47,10 +55,8 @@ public partial class RendererService( Description = GetDescription(content), WordCount = wordCount, ReadTime = readTime, - PublishTime = content.Metadata.Date == default ? DateTimeOffset.Now : content.Metadata.Date, - // 如果不存在最后的更新时间,就把更新时间设置为发布时间 - UpdateTime = - content.Metadata.UpdateTime == default ? content.Metadata.Date : content.Metadata.UpdateTime, + PublishTime = publishDate, + UpdateTime = updateTime, HtmlContent = content.Content }; diff --git a/YaeBlog/build.ps1 b/YaeBlog/build.ps1 index 088c7f0..7e4b350 100755 --- a/YaeBlog/build.ps1 +++ b/YaeBlog/build.ps1 @@ -3,7 +3,7 @@ [cmdletbinding()] param( [Parameter(Mandatory = $true, Position = 0, HelpMessage = "Specify the build target")] - [ValidateSet("tailwind", "watch", "publish", "compress", "build", "dev")] + [ValidateSet("tailwind", "publish", "compress", "build", "dev", "new")] [string]$Target, [string]$Output = "wwwroot", [string]$Essay, @@ -21,6 +21,15 @@ begin { exit 1 } } + + if ($Target -eq "new") + { + if ($Essay -eq "") + { + Write-Error "No new name, please add with --essay argument." + exit 1 + } + } } process { @@ -85,10 +94,6 @@ process { pnpm tailwindcss -i wwwroot/tailwind.css -o $Output/tailwind.g.css break } - "watch" { - dotnet run -- watch - break - } "publish" { Write-Host "Publish essay $Essay..." dotnet run -- publish $Essay @@ -111,6 +116,9 @@ process { Start-Develop break } + "new" { + dotnet run -- new $Essay + } } }