Add news post type with list and detail routes
This commit is contained in:
1 parent
bed2db5972
commit
908a03a1f6
10 files changed
+295
-31
No files matched your search
@@ -0,0 +1,46 @@
|
||||
@page "/beitraege/{Slug}"
|
||||
@using System.Globalization
|
||||
@using Elternbeirat.Web.Services
|
||||
@inject PostService PostService
|
||||
|
||||
@if (_post is null)
|
||||
{
|
||||
<PageTitle>Nicht gefunden</PageTitle>
|
||||
}
|
||||
else
|
||||
{
|
||||
<PageTitle>@_post.Title</PageTitle>
|
||||
<article>
|
||||
<p class="post-meta">
|
||||
<a href="/beitraege">← Alle Beiträge</a>
|
||||
<time datetime="@_post.Date.ToString("yyyy-MM-dd")">
|
||||
@_post.Date.ToString("d. MMMM yyyy", _german)
|
||||
</time>
|
||||
</p>
|
||||
@((MarkupString)_post.ContentHtml)
|
||||
</article>
|
||||
}
|
||||
|
||||
@code {
|
||||
private static readonly CultureInfo _german = CultureInfo.GetCultureInfo("de-DE");
|
||||
|
||||
[Parameter]
|
||||
public string Slug { get; set; } = "";
|
||||
|
||||
private Post? _post;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
_post = PostService.Find(Slug);
|
||||
|
||||
// Unknown slug -> 404, so UseStatusCodePagesWithReExecute serves the
|
||||
// /not-found page instead of an empty 200 response.
|
||||
if (_post is null && HttpContext is not null)
|
||||
{
|
||||
HttpContext.Response.StatusCode = StatusCodes.Status404NotFound;
|
||||
}
|
||||
}
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext? HttpContext { get; set; }
|
||||
}
|
||||
Reference in new issue
Block a user