Centralize the home slug check on Page, case-insensitively

This commit is contained in:
tleininger committed 2026-09-24 10:23:30 +02:00
1 parent 66bc76af1c
commit d06af2891a
3 files changed
+36 -10

No files matched your search

+20
View File
@@ -13,6 +13,12 @@ namespace Elternbeirat.Contracts;
/// </remarks>
public record Page
{
/// <summary>
/// The slug of the home page, which is served at the site root <c>/</c> rather
/// than at <c>/home</c>. Reserved: no other page may use it.
/// </summary>
private const string HomeSlug = "home";
/// <summary>
/// Gets the PocketBase record id.
/// </summary>
@@ -76,4 +82,18 @@ public record Page
/// </summary>
[JsonPropertyName("public")]
public bool Public { get; init; }
/// <summary>
/// Tests whether a slug is the home page's, ignoring case. This is the single
/// definition of that comparison, so every caller treats <c>home</c> and
/// <c>Home</c> alike.
/// </summary>
/// <param name="slug">
/// The slug to test.
/// </param>
/// <returns>
/// <see langword="true"/> if <paramref name="slug"/> is the home page's slug.
/// </returns>
public static bool IsHomeSlug(string slug) =>
string.Equals(slug, HomeSlug, StringComparison.OrdinalIgnoreCase);
}