diff --git a/OliverBooth.Common/Services/IBlogPostService.cs b/OliverBooth.Common/Services/IBlogPostService.cs index 5517539..48bd1fb 100644 --- a/OliverBooth.Common/Services/IBlogPostService.cs +++ b/OliverBooth.Common/Services/IBlogPostService.cs @@ -24,8 +24,9 @@ public interface IBlogPostService /// Returns the total number of blog posts. /// /// The post visibility filter. + /// The tags of the posts to return. /// The total number of blog posts. - int GetBlogPostCount(Visibility visibility = Visibility.None); + int GetBlogPostCount(Visibility visibility = Visibility.None, string[]? tags = null); /// /// Returns a collection of blog posts from the specified page, optionally limiting the number of posts @@ -33,8 +34,9 @@ public interface IBlogPostService /// /// The zero-based index of the page to return. /// The maximum number of posts to return per page. + /// The tags of the posts to return. /// A collection of blog posts. - IReadOnlyList GetBlogPosts(int page, int pageSize = 10); + IReadOnlyList GetBlogPosts(int page, int pageSize = 10, string[]? tags = null); /// /// Returns the number of legacy comments for the specified post. @@ -70,8 +72,9 @@ public interface IBlogPostService /// /// The page size. Defaults to 10. /// The post visibility filter. + /// The tags of the posts to return. /// The page count. - int GetPageCount(int pageSize = 10, Visibility visibility = Visibility.None); + int GetPageCount(int pageSize = 10, Visibility visibility = Visibility.None, string[]? tags = null); /// /// Returns the previous blog post from the specified blog post. diff --git a/OliverBooth/Pages/Blog/Index.cshtml b/OliverBooth/Pages/Blog/Index.cshtml index 876e06f..379ec92 100644 --- a/OliverBooth/Pages/Blog/Index.cshtml +++ b/OliverBooth/Pages/Blog/Index.cshtml @@ -12,7 +12,7 @@ @await Html.PartialAsync("Partials/_MastodonStatus")
- @foreach (IBlogPost post in BlogPostService.GetBlogPosts(0)) + @foreach (IBlogPost post in BlogPostService.GetBlogPosts(0, tags: Model.Tag)) { @await Html.PartialAsync("Partials/_BlogCard", post) } @@ -22,5 +22,6 @@ { ["UrlRoot"] = "/blog", ["Page"] = 1, - ["PageCount"] = BlogPostService.GetPageCount(visibility: Visibility.Published) + ["Tags"] = Model.Tag, + ["PageCount"] = BlogPostService.GetPageCount(visibility: Visibility.Published, tags: Model.Tag) }) \ No newline at end of file diff --git a/OliverBooth/Pages/Blog/Index.cshtml.cs b/OliverBooth/Pages/Blog/Index.cshtml.cs index 378ceb2..f825701 100644 --- a/OliverBooth/Pages/Blog/Index.cshtml.cs +++ b/OliverBooth/Pages/Blog/Index.cshtml.cs @@ -15,11 +15,15 @@ public class Index : PageModel _blogPostService = blogPostService; } + public string[] Tag { get; private set; } = []; + public IActionResult OnGet([FromQuery(Name = "pid")] Guid? postId = null, - [FromQuery(Name = "p")] int? wpPostId = null) + [FromQuery(Name = "p")] int? wpPostId = null, + [FromQuery(Name = "tag")] string? tag = null) { if (postId.HasValue == wpPostId.HasValue) { + Tag = tag?.Split('+').Select(t => t.Replace("%20", " ")).ToArray() ?? []; return Page(); } diff --git a/OliverBooth/Pages/Blog/List.cshtml b/OliverBooth/Pages/Blog/List.cshtml index c0839e2..ad14947 100644 --- a/OliverBooth/Pages/Blog/List.cshtml +++ b/OliverBooth/Pages/Blog/List.cshtml @@ -9,7 +9,7 @@ @await Html.PartialAsync("Partials/_MastodonStatus")
- @foreach (IBlogPost post in BlogPostService.GetBlogPosts(Model.PageNumber - 1)) + @foreach (IBlogPost post in BlogPostService.GetBlogPosts(Model.PageNumber - 1, tags: Model.Tag)) { @await Html.PartialAsync("Partials/_BlogCard", post) } @@ -19,5 +19,6 @@ { ["UrlRoot"] = "/blog", ["Page"] = Model.PageNumber, - ["PageCount"] = BlogPostService.GetPageCount(visibility: Visibility.Published) + ["Tags"] = Model.Tag, + ["PageCount"] = BlogPostService.GetPageCount(visibility: Visibility.Published, tags: Model.Tag) }) \ No newline at end of file diff --git a/OliverBooth/Pages/Blog/List.cshtml.cs b/OliverBooth/Pages/Blog/List.cshtml.cs index f0aa6dd..4660b20 100644 --- a/OliverBooth/Pages/Blog/List.cshtml.cs +++ b/OliverBooth/Pages/Blog/List.cshtml.cs @@ -14,12 +14,15 @@ public class List : PageModel /// The requested page number. public int PageNumber { get; private set; } + public string[] Tag { get; private set; } = []; + /// /// Handles the incoming GET request to the page. /// /// The requested page number, starting from 1. + /// The tag by which to filter results. /// - public IActionResult OnGet([FromRoute(Name = "pageNumber")] int page = 1) + public IActionResult OnGet([FromRoute(Name = "pageNumber")] int page = 1, [FromQuery(Name = "tag")] string? tag = null) { if (page < 2) { @@ -27,6 +30,7 @@ public class List : PageModel } PageNumber = page; + Tag = tag?.Split('+').Select(t => t.Replace("%20", " ")).ToArray() ?? []; return Page(); } } diff --git a/OliverBooth/Pages/Shared/Partials/PageTabsUtility.cs b/OliverBooth/Pages/Shared/Partials/PageTabsUtility.cs index 833cd77..c97482f 100644 --- a/OliverBooth/Pages/Shared/Partials/PageTabsUtility.cs +++ b/OliverBooth/Pages/Shared/Partials/PageTabsUtility.cs @@ -32,6 +32,8 @@ public class PageTabsUtility set => _urlRoot = string.IsNullOrWhiteSpace(value) ? string.Empty : value.Trim(); } + public string[]? Tags { get; set; } = []; + /// /// Shows the bound chevrons for the specified bounds type. /// @@ -129,7 +131,9 @@ public class PageTabsUtility private string GetLinkForPage(int page) { // page 1 doesn't use /page/n route - return page == 1 ? _urlRoot : $"{_urlRoot}/page/{page}"; + return page == 1 + ? $"{_urlRoot}{(Tags is { Length: > 0 } ? $"?tag={string.Join('+', Tags)}" : "")}" + : $"{_urlRoot}/page/{page}{(Tags is { Length: > 0 } ? $"?tag={string.Join('+', Tags)}" : "")}"; } private string ShowLowerBound() diff --git a/OliverBooth/Pages/Shared/Partials/_PageTabs.cshtml b/OliverBooth/Pages/Shared/Partials/_PageTabs.cshtml index b3a8950..db4d5aa 100644 --- a/OliverBooth/Pages/Shared/Partials/_PageTabs.cshtml +++ b/OliverBooth/Pages/Shared/Partials/_PageTabs.cshtml @@ -7,7 +7,8 @@ { CurrentPage = page, PageCount = pageCount, - UrlRoot = urlRoot + UrlRoot = urlRoot, + Tags = ViewData["Tags"] as string[] }; }