using System; using Markdig; using Markdig.SyntaxHighlighting; using Website.Models; namespace Website.ViewModels { public class BlogPostViewModel { public BlogPostViewModel(BlogPost blogPost) { Title = blogPost.Title; 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() .UseSoftlineBreakAsHardlineBreak() .UseSyntaxHighlighting() .Build(); public string Title { get; private set; } public string Content { get; protected set; } public string Timestamp { get; private set; } public string Url { get; private set; } } }