Generate navigation and render page embeds from PocketBase
This commit is contained in:
1 parent
6b5d9dda55
commit
3fd3796d73
26 files changed
+544
-114
No files matched your search
@@ -0,0 +1,31 @@
|
||||
using Elternbeirat.Contracts;
|
||||
|
||||
namespace Elternbeirat.Web.Features.Layout;
|
||||
|
||||
/// <summary>
|
||||
/// Builds the header and footer navigation from the public pages. Pages carry a
|
||||
/// <see cref="Page.Location"/> ("header"/"footer"/"") and an <see cref="Page.Order"/>;
|
||||
/// pages without a location are sub-pages and never appear in a menu.
|
||||
/// </summary>
|
||||
public static class NavBuilder
|
||||
{
|
||||
/// <summary>Header links, ordered, built from pages with location "header".</summary>
|
||||
public static IReadOnlyList<NavLinkItem> Header(IReadOnlyList<Page> pages) =>
|
||||
Build(pages, "header");
|
||||
|
||||
/// <summary>Footer links, ordered, built from pages with location "footer".</summary>
|
||||
public static IReadOnlyList<NavLinkItem> Footer(IReadOnlyList<Page> pages) =>
|
||||
Build(pages, "footer");
|
||||
|
||||
private static List<NavLinkItem> Build(IReadOnlyList<Page> pages, string location) =>
|
||||
[.. pages
|
||||
.Where(page => string.Equals(page.Location, location, StringComparison.Ordinal))
|
||||
.OrderBy(page => page.Order)
|
||||
.Select(page => new NavLinkItem(HrefFor(page.Slug), page.Title))];
|
||||
|
||||
// The home page owns "/" (served by the Home component); every other slug is
|
||||
// reached at "/{slug}", where either a literal route or the catch-all content
|
||||
// page renders it.
|
||||
private static string HrefFor(string slug) =>
|
||||
string.Equals(slug, "home", StringComparison.Ordinal) ? "/" : $"/{slug}";
|
||||
}
|
||||
Reference in new issue
Block a user