41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using System.Text.RegularExpressions;
|
|
using Markdig;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace zotanpw_web.Pages.blog;
|
|
|
|
public class BlogModel : PageModel {
|
|
public static readonly List<BlogPost> Posts = new() {
|
|
new BlogPost("adhd-and-notes", "ADHD & Notetaking: an autistic perspective", DateOnly.Parse("2021-08-07")),
|
|
new BlogPost("ipv6-networking", "IPv6-native networking: a project report", DateOnly.Parse("2021-08-23")),
|
|
};
|
|
|
|
static BlogModel() {
|
|
Posts = Posts.OrderByDescending(p => p.PublishedOn).ToList();
|
|
}
|
|
|
|
public void OnGet() { }
|
|
|
|
public class BlogPost {
|
|
public readonly string Title;
|
|
public readonly string Shorthand;
|
|
public readonly DateOnly PublishedOn;
|
|
public int ReadTimeMinutes;
|
|
public string Content = "";
|
|
|
|
public BlogPost(string shorthand, string title, DateOnly publishedOn) {
|
|
Title = title;
|
|
PublishedOn = publishedOn;
|
|
Shorthand = shorthand;
|
|
UpdateContent();
|
|
}
|
|
|
|
public void UpdateContent() {
|
|
var markdownText = System.IO.File.ReadAllText($"Pages/blog/posts/{Shorthand}.md");
|
|
|
|
Content = Markdown.ToHtml(markdownText, new MarkdownPipelineBuilder().UseGenericAttributes().Build());
|
|
ReadTimeMinutes = Regex.Matches(markdownText, @"\b\w+\b").Count / 150;
|
|
}
|
|
}
|
|
}
|