@page "/tutorial/{**slug}" @using Humanizer @using Markdig @using Microsoft.AspNetCore.Mvc.TagHelpers @using OliverBooth.Common.Data @using OliverBooth.Common.Data.Blog @using OliverBooth.Common.Data.Web @using OliverBooth.Common.Services @inject ITutorialService TutorialService @inject MarkdownPipeline MarkdownPipeline @model Article @if (Model.CurrentArticle is not { } article) { return; } @{ ViewData["Post"] = article; ViewData["Title"] = article.Title; DateTimeOffset published = article.Published; }

@article.Title

Published @published.Humanize() @if (article.Updated is { } updated) { Updated @updated.Humanize() }


@Html.Raw(TutorialService.RenderArticle(article))
@if (article.HasOtherParts) {
@if (article.PreviousPart is { } previousPartId && TutorialService.TryGetArticle(previousPartId, out ITutorialArticle? previousPart) && previousPart.Visibility == Visibility.Published) { Previous Part

@previousPart.Title

}
@if (article.NextPart is { } nextPartId && TutorialService.TryGetArticle(nextPartId, out ITutorialArticle? nextPart) && nextPart.Visibility == Visibility.Published) { Next Part

@nextPart.Title

}
}
@if (article.EnableComments) {
@section Scripts { } int commentCount = TutorialService.GetLegacyCommentCount(article); if (commentCount > 0) {
var nestLevelMap = new Dictionary(); IReadOnlyList legacyComments = TutorialService.GetLegacyComments(article); 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 TutorialService.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.

}