@page "/blog/{year:int}/{month:int}/{day:int}/{slug}" @using Humanizer @using Markdig @using Microsoft.AspNetCore.Mvc.TagHelpers @using OliverBooth.Common.Data @using OliverBooth.Common.Data.Blog @using OliverBooth.Common.Services @inject IBlogPostService BlogPostService @inject MarkdownPipeline MarkdownPipeline @model Article @if (Model.ShowPasswordPrompt) {
This post is private and can only be viewed by those with the password.
return; } @if (Model.Post is not { } post) { return; } @{ ViewData["Post"] = post; ViewData["Title"] = post.Title; IBlogAuthor author = post.Author; DateTimeOffset published = post.Published; } @switch (post.Visibility) { case Visibility.Private:
This post is private and can only be viewed by those with the password.
break; case Visibility.Unlisted:
This post is unlisted and can only be viewed by those with the link.
break; }

@post.Title

@author.DisplayName @author.DisplayName • Published @published.Humanize() @if (post.Updated is { } updated) { Updated @updated.Humanize() }

@foreach (string tag in post.Tags) { @tag }

@Html.Raw(BlogPostService.RenderPost(post))

@if (BlogPostService.GetPreviousPost(post) is { } previousPost) { Previous Post

@previousPost.Title

}
@if (BlogPostService.GetNextPost(post) is { } nextPost) { Next Post

@nextPost.Title

}

@if (post.EnableComments) {
@section Scripts { } int commentCount = BlogPostService.GetLegacyCommentCount(post); if (commentCount > 0) {
var nestLevelMap = new Dictionary(); IReadOnlyList legacyComments = BlogPostService.GetLegacyComments(post); var commentStack = new Stack(legacyComments.OrderByDescending(c => c.CreatedAt));

@("legacy comment".ToQuantity(commentCount))

Legacy comments are comments that were posted using a commenting system that I no longer use. This exists for posterity.

while (commentStack.Count > 0) { ILegacyComment comment = commentStack.Pop(); foreach (ILegacyComment reply in BlogPostService.GetLegacyReplies(comment).OrderByDescending(c => c.CreatedAt)) { if (nestLevelMap.TryGetValue(comment, out int currentLevel)) { nestLevelMap[reply] = currentLevel + 1; } else { nestLevelMap[reply] = 1; } commentStack.Push(reply); } int padding = 0; if (nestLevelMap.TryGetValue(comment, out int nestLevel)) { padding = 50 * nestLevel; }
@comment.Author @comment.Author • @comment.CreatedAt.Humanize()
@Html.Raw(Markdown.ToHtml(comment.Body, MarkdownPipeline))
} } } else {

Comments are not enabled for this post.

}