YaeBlog/YaeBlog.Core/Models/BlogEssay.cs

53 lines
1.2 KiB
C#
Raw Normal View History

2024-01-17 13:20:32 +08:00
namespace YaeBlog.Core.Models;
2024-01-26 20:54:35 +08:00
public class BlogEssay : IComparable<BlogEssay>
2024-01-17 13:20:32 +08:00
{
public required string Title { get; init; }
2024-01-23 14:33:35 +08:00
public required string FileName { get; init; }
2024-01-17 13:20:32 +08:00
public required DateTime PublishTime { get; init; }
2024-01-24 14:00:55 +08:00
public required string Description { get; init; }
public required uint WordCount { get; init; }
2024-07-29 22:04:28 +08:00
public required string ReadTime { get; init; }
2024-01-19 20:33:41 +08:00
public List<string> Tags { get; } = [];
2024-01-17 13:20:32 +08:00
public required string HtmlContent { get; init; }
2024-01-19 20:33:41 +08:00
public BlogEssay WithNewHtmlContent(string newHtmlContent)
{
var essay = new BlogEssay
{
Title = Title,
FileName = FileName,
PublishTime = PublishTime,
Description = Description,
WordCount = WordCount,
2024-07-29 22:04:28 +08:00
ReadTime = ReadTime,
HtmlContent = newHtmlContent
};
essay.Tags.AddRange(Tags);
return essay;
}
2024-01-26 20:54:35 +08:00
public int CompareTo(BlogEssay? other)
{
if (other is null)
{
return 1;
}
return PublishTime.CompareTo(other.PublishTime);
}
2024-01-19 20:33:41 +08:00
public override string ToString()
{
return $"{Title}-{PublishTime}";
}
2024-01-17 13:20:32 +08:00
}