37 lines
No EOL
1.2 KiB
C#
37 lines
No EOL
1.2 KiB
C#
using System;
|
|
using Markdig;
|
|
using Pek.Markdig.HighlightJs;
|
|
using Website.Extensions;
|
|
using Website.Markdig.Extensions;
|
|
using Website.Models;
|
|
|
|
namespace Website.ViewModels
|
|
{
|
|
public class BlogPostViewModel
|
|
{
|
|
public BlogPostViewModel(BlogPost blogPost, bool preview) {
|
|
Id = blogPost.Id;
|
|
Title = blogPost.Title;
|
|
Timestamp = FormatTimestamp(blogPost.Timestamp);
|
|
Url = blogPost.Url;
|
|
Content = preview ? blogPost.Draft : blogPost.Content;
|
|
}
|
|
|
|
private static string FormatTimestamp(DateTime timestamp) => timestamp.ToString($@"dddd \t\h\e d{timestamp.GetDaySuffix()} \o\f MMMM yyyy");
|
|
|
|
private static MarkdownPipeline GetPipeline() => new MarkdownPipelineBuilder()
|
|
//.UseAdvancedExtensions()
|
|
.UseAutoLinks()
|
|
.UseSoftlineBreakAsHardlineBreak()
|
|
.UseHighlightJs()
|
|
.UseBlogRenderer()
|
|
.Build();
|
|
|
|
public int Id { get; }
|
|
public string Title { get; }
|
|
public string Content { get; protected set; }
|
|
public string Timestamp { get; }
|
|
public string Url { get; }
|
|
public string ContentHtml => Markdown.ToHtml(Content, GetPipeline()).Trim();
|
|
}
|
|
} |