style: guard clause article page

This commit is contained in:
Oliver Booth 2023-08-08 01:34:27 +01:00
parent 83e5757429
commit b584bb84a2
Signed by: oliverbooth
GPG Key ID: 725DB725A0D9EE61
1 changed files with 64 additions and 60 deletions

View File

@ -2,24 +2,29 @@
@using Humanizer @using Humanizer
@model OliverBooth.Pages.Blog.Article @model OliverBooth.Pages.Blog.Article
@if (Model.Post is { } post) @if (Model.Post is not { } post)
{ {
return;
}
@{
bool isLegacyPost = Model.IsWordPressLegacyPost; bool isLegacyPost = Model.IsWordPressLegacyPost;
string disqusDomain = isLegacyPost ? "https://blog.oliverbooth.dev" : "https://oliverbooth.dev/blog"; string disqusDomain = isLegacyPost ? "https://blog.oliverbooth.dev" : "https://oliverbooth.dev/blog";
string disqusId = isLegacyPost ? $"{post.WordPressId} {disqusDomain}/?p={post.WordPressId}" : post.Id.ToString(); string disqusId = isLegacyPost ? $"{post.WordPressId} {disqusDomain}/?p={post.WordPressId}" : post.Id.ToString();
var disqusUrl = $"{disqusDomain}/{post.Published:yyyy/MM/dd}/{post.Slug}/"; var disqusUrl = $"{disqusDomain}/{post.Published:yyyy/MM/dd}/{post.Slug}/";
}
<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb"> <nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"> <li class="breadcrumb-item">
<a asp-page="/blog/index">Blog</a> <a asp-page="/blog/index">Blog</a>
</li> </li>
<li class="breadcrumb-item active" aria-current="page">@post.Title</li> <li class="breadcrumb-item active" aria-current="page">@post.Title</li>
</ol> </ol>
</nav> </nav>
<h1>@post.Title</h1> <h1>@post.Title</h1>
<p class="text-muted"> <p class="text-muted">
<img class="blog-author-icon" src="https://gravatar.com/avatar/@Model.Author?.AvatarHash?s=28"> <img class="blog-author-icon" src="https://gravatar.com/avatar/@Model.Author?.AvatarHash?s=28">
@Model.Author?.Name @Model.Author?.Name
&bull; &bull;
@ -31,22 +36,22 @@
<span>&bull;</span> <span>&bull;</span>
<a href="#disqus_thread" data-disqus-identifier="@disqusId">0 Comments</a> <a href="#disqus_thread" data-disqus-identifier="@disqusId">0 Comments</a>
} }
</p> </p>
<article> <article>
@Html.Raw(Model.SanitizeContent(post.Body)) @Html.Raw(Model.SanitizeContent(post.Body))
</article> </article>
<hr> <hr>
@if (post.EnableComments) @if (post.EnableComments)
{ {
<div id="disqus_thread"></div> <div id="disqus_thread"></div>
<script> <script>
var disqus_config = function () { var disqus_config = function () {
this.page.url = "@(disqusUrl)"; this.page.url = "@disqusUrl";
this.page.identifier = "@(disqusId)"; this.page.identifier = "@disqusId";
this.page.title = "@(post.Title)"; this.page.title = "@post.Title";
this.page.postId = "@(post.WordPressId ?? post.Id)"; this.page.postId = "@(post.WordPressId ?? post.Id)";
}; };
@ -66,9 +71,8 @@
comments powered by Disqus. comments powered by Disqus.
</a> </a>
</noscript> </noscript>
} }
else else
{ {
<p class="text-center text-muted">Comments are not enabled for this post.</p> <p class="text-center text-muted">Comments are not enabled for this post.</p>
}
} }