Make error handling consistent
This commit is contained in:
parent
21ec2ad89d
commit
e53a83f1d2
|
@ -1,25 +1,21 @@
|
|||
@page "/blog/{post}"
|
||||
@model BlogPostModel
|
||||
@using zotanpw.Backend
|
||||
|
||||
@{
|
||||
if (string.IsNullOrWhiteSpace((string)RouteData.Values["post"]!)) {
|
||||
if (Model.Post == null)
|
||||
return;
|
||||
}
|
||||
var post = BlogModel.Posts.FirstOrDefault(p => p.Shorthand == (string)RouteData.Values["post"]!);
|
||||
if (post == null) {
|
||||
Response.Redirect("/Error");
|
||||
return;
|
||||
}
|
||||
|
||||
ViewData["title"] = "blog";
|
||||
ViewData["subtitle"] = post.Shorthand;
|
||||
ViewData["desc"] = post.Title;
|
||||
ViewData["subtitle"] = Model.Post.Shorthand;
|
||||
ViewData["desc"] = Model.Post.Title;
|
||||
#if (DEBUG)
|
||||
post.UpdateContentAndMetadata();
|
||||
Model.Post.UpdateContentAndMetadata();
|
||||
#endif
|
||||
}
|
||||
|
||||
<b>@post.PublishedOn.ToString("yyyy-MM-dd")</b> - @Utils.a_an(post.ReadTimeMinutes) @post.ReadTimeMinutes minute read (150 wpm)
|
||||
<h1 id="post">@post.Title</h1>
|
||||
<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 style="text-align: justify">
|
||||
@Html.Raw(post.Content)
|
||||
@Html.Raw(Model.Post.Content)
|
||||
</div>
|
||||
|
|
21
Pages/blog/BlogPost.cshtml.cs
Normal file
21
Pages/blog/BlogPost.cshtml.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace zotanpw.Pages.blog;
|
||||
|
||||
public class BlogPostModel : PageModel {
|
||||
public BlogModel.BlogPost? Post;
|
||||
|
||||
public IActionResult OnGet() {
|
||||
if (string.IsNullOrWhiteSpace((string)RouteData.Values["post"]!)) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
Post = BlogModel.Posts.FirstOrDefault(p => p.Shorthand == (string)RouteData.Values["post"]!);
|
||||
if (Post == null) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue