zotan.pw-web/Pages/BlogPost.cshtml

35 lines
1.1 KiB
Plaintext
Raw Normal View History

2022-11-20 03:06:41 +01:00
@page "/blog/{post}"
2023-02-03 21:45:07 +01:00
@using System.Text.RegularExpressions
2022-11-26 13:23:58 +01:00
@using zotanpw.Backend
2022-12-02 04:19:01 +01:00
@model BlogPostModel
2022-11-20 03:06:41 +01:00
@{
2022-11-26 17:17:38 +01:00
if (Model.Post == null)
2022-11-20 03:06:41 +01:00
return;
2022-11-26 17:17:38 +01:00
2022-11-20 20:48:22 +01:00
ViewData["title"] = "blog";
2022-11-26 17:17:38 +01:00
ViewData["subtitle"] = Model.Post.Shorthand;
2023-02-03 21:45:07 +01:00
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][^>]*>", ""); // remove <a>, <i>, <b> and <u> 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;
2022-11-20 03:06:41 +01:00
#if (DEBUG)
2022-11-26 17:17:38 +01:00
Model.Post.UpdateContentAndMetadata();
2022-11-20 03:06:41 +01:00
#endif
}
2022-11-26 17:17:38 +01:00
<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>
2022-11-26 17:17:38 +01:00
@Html.Raw(Model.Post.Content)
2022-11-20 23:34:41 +01:00
</div>