fix: Use string for date field of markdown metadata POCO.
All checks were successful
Build blog docker image / Build-Blog-Image (push) Successful in 1m40s
All checks were successful
Build blog docker image / Build-Blog-Image (push) Successful in 1m40s
Add new command for build.ps1 script. Signed-off-by: jackfiled <xcrenchangjun@outlook.com>
This commit is contained in:
@@ -110,7 +110,12 @@ public sealed class YaeBlogCommand
|
|||||||
|
|
||||||
await essayScanService.SaveBlogContent(new BlogContent(
|
await essayScanService.SaveBlogContent(new BlogContent(
|
||||||
new FileInfo(Path.Combine(blogOption.Value.Root, "drafts", file + ".md")),
|
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, [], []));
|
string.Empty, true, [], []));
|
||||||
|
|
||||||
Console.WriteLine($"Created new blog '{file}.");
|
Console.WriteLine($"Created new blog '{file}.");
|
||||||
@@ -138,9 +143,8 @@ public sealed class YaeBlogCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
content.Metadata.UpdateTime = DateTimeOffset.Now;
|
content.Metadata.UpdateTime = DateTimeOffset.Now.ToString("o");
|
||||||
await essayScanService.SaveBlogContent(content, content.IsDraft);
|
await essayScanService.SaveBlogContent(content, content.IsDraft);
|
||||||
|
|
||||||
}, filenameArgument,
|
}, filenameArgument,
|
||||||
new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder());
|
new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), 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
|
// 将选中的博客文件复制到posts
|
||||||
await essayScanService.SaveBlogContent(content, isDraft: false);
|
await essayScanService.SaveBlogContent(content, isDraft: false);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@foreach (IGrouping<DateTime, BlogEssay> group in _essays)
|
@foreach (IGrouping<DateTimeOffset, BlogEssay> group in _essays)
|
||||||
{
|
{
|
||||||
<div class="p-2">
|
<div class="p-2">
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
<div class="px-4 py-4 flex flex-col">
|
<div class="px-4 py-4 flex flex-col">
|
||||||
@foreach (BlogEssay essay in group)
|
@foreach (BlogEssay essay in group)
|
||||||
{
|
{
|
||||||
<a target="_blank" href="@($"/blog/essays/{essay.FileName}")">
|
<a href="@($"/blog/essays/{essay.FileName}")">
|
||||||
<div class="flex flex-row p-2 mx-1 rounded-lg hover:bg-gray-300">
|
<div class="flex flex-row p-2 mx-1 rounded-lg hover:bg-gray-300">
|
||||||
<div class="w-20">
|
<div class="w-20">
|
||||||
@(essay.PublishTime.ToString("MM月dd日"))
|
@(essay.PublishTime.ToString("MM月dd日"))
|
||||||
@@ -51,13 +51,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private readonly List<IGrouping<DateTime, BlogEssay>> _essays = [];
|
private readonly List<IGrouping<DateTimeOffset, BlogEssay>> _essays = [];
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
base.OnInitialized();
|
base.OnInitialized();
|
||||||
|
|
||||||
_essays.AddRange(from essay in Contents.Essays
|
_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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
<div class="">
|
<div class="">
|
||||||
<p class="text-lg">
|
<p class="text-lg">
|
||||||
平平无奇的计算机科学与技术学徒,连微小的贡献都没做。
|
学过一些基础的计算机知识,略懂一些代码。
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ public class MarkdownMetadata
|
|||||||
{
|
{
|
||||||
public string? Title { get; set; }
|
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<string>? Tags { get; set; }
|
public List<string>? Tags { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,14 @@ public partial class RendererService(
|
|||||||
foreach (BlogContent content in preProcessedContents)
|
foreach (BlogContent content in preProcessedContents)
|
||||||
{
|
{
|
||||||
(uint wordCount, string readTime) = GetWordCount(content);
|
(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()
|
BlogEssay essay = new()
|
||||||
{
|
{
|
||||||
Title = content.Metadata.Title ?? content.BlogName,
|
Title = content.Metadata.Title ?? content.BlogName,
|
||||||
@@ -47,10 +55,8 @@ public partial class RendererService(
|
|||||||
Description = GetDescription(content),
|
Description = GetDescription(content),
|
||||||
WordCount = wordCount,
|
WordCount = wordCount,
|
||||||
ReadTime = readTime,
|
ReadTime = readTime,
|
||||||
PublishTime = content.Metadata.Date == default ? DateTimeOffset.Now : content.Metadata.Date,
|
PublishTime = publishDate,
|
||||||
// 如果不存在最后的更新时间,就把更新时间设置为发布时间
|
UpdateTime = updateTime,
|
||||||
UpdateTime =
|
|
||||||
content.Metadata.UpdateTime == default ? content.Metadata.Date : content.Metadata.UpdateTime,
|
|
||||||
HtmlContent = content.Content
|
HtmlContent = content.Content
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
[cmdletbinding()]
|
[cmdletbinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory = $true, Position = 0, HelpMessage = "Specify the build target")]
|
[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]$Target,
|
||||||
[string]$Output = "wwwroot",
|
[string]$Output = "wwwroot",
|
||||||
[string]$Essay,
|
[string]$Essay,
|
||||||
@@ -21,6 +21,15 @@ begin {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($Target -eq "new")
|
||||||
|
{
|
||||||
|
if ($Essay -eq "")
|
||||||
|
{
|
||||||
|
Write-Error "No new name, please add with --essay argument."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process {
|
process {
|
||||||
@@ -85,10 +94,6 @@ process {
|
|||||||
pnpm tailwindcss -i wwwroot/tailwind.css -o $Output/tailwind.g.css
|
pnpm tailwindcss -i wwwroot/tailwind.css -o $Output/tailwind.g.css
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
"watch" {
|
|
||||||
dotnet run -- watch
|
|
||||||
break
|
|
||||||
}
|
|
||||||
"publish" {
|
"publish" {
|
||||||
Write-Host "Publish essay $Essay..."
|
Write-Host "Publish essay $Essay..."
|
||||||
dotnet run -- publish $Essay
|
dotnet run -- publish $Essay
|
||||||
@@ -111,6 +116,9 @@ process {
|
|||||||
Start-Develop
|
Start-Develop
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
"new" {
|
||||||
|
dotnet run -- new $Essay
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user