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();
|
||||
}
|
||||
}
|
|
@ -8,32 +8,32 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="linq2db" Version="4.3.0"/>
|
||||
<PackageReference Include="Markdig" Version="0.30.4"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.0"/>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.0"/>
|
||||
<PackageReference Include="System.Data.SQLite" Version="1.0.115"/>
|
||||
<PackageReference Include="System.ServiceModel.Syndication" Version="7.0.0"/>
|
||||
<PackageReference Include="YamlDotNet" Version="12.0.2"/>
|
||||
<PackageReference Include="linq2db" Version="4.3.0" />
|
||||
<PackageReference Include="Markdig" Version="0.30.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.0" />
|
||||
<PackageReference Include="System.Data.SQLite" Version="1.0.115" />
|
||||
<PackageReference Include="System.ServiceModel.Syndication" Version="7.0.0" />
|
||||
<PackageReference Include="YamlDotNet" Version="12.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Pages\blog\posts"/>
|
||||
<Folder Include="Pages\blog\posts" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove=".gitignore"/>
|
||||
<None Remove=".bearer_token"/>
|
||||
<None Remove="database.db"/>
|
||||
<None Remove=".gitignore" />
|
||||
<None Remove=".bearer_token" />
|
||||
<None Remove="database.db" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_ContentIncludedByDefault Remove="Pages\ErrorPages\404.cshtml"/>
|
||||
<_ContentIncludedByDefault Remove="Pages\ErrorPages\404.cshtml" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
|
||||
<Exec Command="git describe --long --always --dirty --exclude=* --abbrev=8" ConsoleToMSBuild="True" IgnoreExitCode="False">
|
||||
<Output PropertyName="SourceRevisionId" TaskParameter="ConsoleOutput"/>
|
||||
<Output PropertyName="SourceRevisionId" TaskParameter="ConsoleOutput" />
|
||||
</Exec>
|
||||
</Target>
|
||||
|
||||
|
|
Loading…
Reference in a new issue