Set friendly date for blog posts

This commit is contained in:
Robert Marshall 2019-04-28 11:43:05 +01:00
parent fa143f5ab4
commit 035f442ba0
5 changed files with 61 additions and 5 deletions

View file

@ -10,12 +10,34 @@ namespace Website.ViewModels
public BlogPostViewModel(BlogPost blogPost)
{
Title = blogPost.Title;
Timestamp = blogPost.Timestamp;
Timestamp = FormatTimestamp(blogPost.Timestamp);
Url = blogPost.Url;
Content = Markdown.ToHtml(blogPost.Content, GetPipeline()).Trim();
}
string GetDaySuffix(int day) {
switch (day) {
case 1:
case 21:
case 31:
return @"\s\t";
case 2:
case 22:
return @"\n\d";
case 3:
case 23:
return @"\r\d";
default:
return @"\t\h";
}
}
private string FormatTimestamp(DateTime timestamp) {
var suffix = GetDaySuffix(timestamp.Day);
return timestamp.ToString($@"dddd \t\h\e d{suffix} \o\f MMMM yyyy");
}
protected MarkdownPipeline GetPipeline()=>new MarkdownPipelineBuilder()
//.UseAdvancedExtensions()
.UseAutoLinks()
@ -25,7 +47,7 @@ namespace Website.ViewModels
public string Title { get; private set; }
public string Content { get; protected set; }
public DateTime Timestamp { get; private set; }
public string Timestamp { get; private set; }
public string Url { get; private set; }
}
}