Read heading and intro from the pages record on /posts and /events
This commit is contained in:
1 parent
666614a3b2
commit
4fa17429b5
7 files changed
+87
-7
No files matched your search
@@ -1,8 +1,19 @@
|
||||
@page "/posts"
|
||||
|
||||
<PageTitle>Beiträge</PageTitle>
|
||||
@{
|
||||
// Heading and intro come from the "posts" page record; fall back to a sensible
|
||||
// default only if that record is missing, so the page still renders.
|
||||
var title = _page?.Title ?? "Beiträge";
|
||||
}
|
||||
|
||||
<h1>Beiträge</h1>
|
||||
<PageTitle>@title</PageTitle>
|
||||
|
||||
<h1>@title</h1>
|
||||
|
||||
@if (_page is not null && !string.IsNullOrWhiteSpace(_page.Body))
|
||||
{
|
||||
<article>@Body</article>
|
||||
}
|
||||
|
||||
@if (_unavailable)
|
||||
{
|
||||
|
||||
@@ -23,6 +23,11 @@ public partial class PostList
|
||||
[CascadingParameter]
|
||||
private HttpContext? HttpContext { get; set; }
|
||||
|
||||
// The "posts" page record supplies the heading and intro text, so an editor owns
|
||||
// them in PocketBase like every other page, instead of them being hard-coded here.
|
||||
// Null until loaded, or when no such page exists.
|
||||
private Page? _page;
|
||||
|
||||
private IReadOnlyList<Post> _posts = [];
|
||||
|
||||
// Set when the content source could not be reached or read. The markup then
|
||||
@@ -30,11 +35,18 @@ public partial class PostList
|
||||
// 503 this sets on the response.
|
||||
private bool _unavailable;
|
||||
|
||||
// The page body rendered from Markdown to HTML, ready to emit as a MarkupString.
|
||||
private MarkupString Body => (MarkupString)Markdown.ToHtml(_page?.Body);
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_posts = await PocketBase.GetPostsAsync(HttpContext?.RequestAborted ?? CancellationToken.None);
|
||||
var token = HttpContext?.RequestAborted ?? CancellationToken.None;
|
||||
var pages = await PocketBase.GetPagesAsync(token);
|
||||
_page = pages.FirstOrDefault(
|
||||
page => string.Equals(page.Slug, "posts", StringComparison.OrdinalIgnoreCase));
|
||||
_posts = await PocketBase.GetPostsAsync(token);
|
||||
}
|
||||
catch (PocketBaseUnavailableException exception)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user