@page "/blog/{post}"
@using System.Text.RegularExpressions
@using zotanpw.Backend
@model BlogPostModel

@{
	if (Model.Post == null)
		return;

	ViewData["title"] = "blog";
	ViewData["subtitle"] = Model.Post.Shorthand;
	ViewData["og-sitename"] = $"zotan.pw >> {ViewData["title"]}";
	ViewData["og-title"] = Model.Post.Title;

	if (System.IO.File.Exists($"wwwroot/files/blog/{Model.Post.Shorthand}.webp"))
		ViewData["og-image"] = $"/files/blog/{Model.Post.Shorthand}.webp";

	var desc = Model.Post.Content;
	desc = Regex.Replace(desc, @"\s+", " "); // collapse whitespace
	desc = Regex.Replace(desc, @"(?i)<\/?(?:[aibu]|em)[^>]*>", ""); // remove <a>, <i>, <b>, <u> and <em> html tags
	desc = desc.Trim(); // remove leading and trailing whitespace
	desc = Regex.Match(desc, @"<p>([^<].*?)<\/p>").Groups[1].ToString().GetUntil("."); // get first sentence
	ViewData["og-desc"] = desc;

	#if (DEBUG)
	Model.Post.UpdateContentAndMetadata();
	#endif
}

<b>@Model.Post.PublishedOn.ToString("yyyy-MM-dd")</b> - @Utils.a_an(Model.Post.ReadTimeMinutes) @Model.Post.ReadTimeMinutes minute read (150 wpm)
<h1 id="post">@Model.Post.Title</h1>
<div>
	@Html.Raw(Model.Post.Content)
</div>
