Compare commits
No commits in common. "d32d46e221ef06e2d019ac8a53267667ba7cf118" and "d3ac89d0719b8d144d09b87e32a63ed4df208146" have entirely different histories.
d32d46e221
...
d3ac89d071
@ -24,9 +24,8 @@ public interface IBlogPostService
|
||||
/// Returns the total number of blog posts.
|
||||
/// </summary>
|
||||
/// <param name="visibility">The post visibility filter.</param>
|
||||
/// <param name="tags">The tags of the posts to return.</param>
|
||||
/// <returns>The total number of blog posts.</returns>
|
||||
int GetBlogPostCount(Visibility visibility = Visibility.None, string[]? tags = null);
|
||||
int GetBlogPostCount(Visibility visibility = Visibility.None);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of blog posts from the specified page, optionally limiting the number of posts
|
||||
@ -34,9 +33,8 @@ public interface IBlogPostService
|
||||
/// </summary>
|
||||
/// <param name="page">The zero-based index of the page to return.</param>
|
||||
/// <param name="pageSize">The maximum number of posts to return per page.</param>
|
||||
/// <param name="tags">The tags of the posts to return.</param>
|
||||
/// <returns>A collection of blog posts.</returns>
|
||||
IReadOnlyList<IBlogPost> GetBlogPosts(int page, int pageSize = 10, string[]? tags = null);
|
||||
IReadOnlyList<IBlogPost> GetBlogPosts(int page, int pageSize = 10);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of legacy comments for the specified post.
|
||||
@ -72,9 +70,8 @@ public interface IBlogPostService
|
||||
/// </summary>
|
||||
/// <param name="pageSize">The page size. Defaults to 10.</param>
|
||||
/// <param name="visibility">The post visibility filter.</param>
|
||||
/// <param name="tags">The tags of the posts to return.</param>
|
||||
/// <returns>The page count.</returns>
|
||||
int GetPageCount(int pageSize = 10, Visibility visibility = Visibility.None, string[]? tags = null);
|
||||
int GetPageCount(int pageSize = 10, Visibility visibility = Visibility.None);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the previous blog post from the specified blog post.
|
||||
|
@ -12,7 +12,7 @@
|
||||
@await Html.PartialAsync("Partials/_MastodonStatus")
|
||||
|
||||
<div id="all-blog-posts">
|
||||
@foreach (IBlogPost post in BlogPostService.GetBlogPosts(0, tags: Model.Tag))
|
||||
@foreach (IBlogPost post in BlogPostService.GetBlogPosts(0))
|
||||
{
|
||||
@await Html.PartialAsync("Partials/_BlogCard", post)
|
||||
}
|
||||
@ -22,6 +22,5 @@
|
||||
{
|
||||
["UrlRoot"] = "/blog",
|
||||
["Page"] = 1,
|
||||
["Tags"] = Model.Tag,
|
||||
["PageCount"] = BlogPostService.GetPageCount(visibility: Visibility.Published, tags: Model.Tag)
|
||||
["PageCount"] = BlogPostService.GetPageCount(visibility: Visibility.Published)
|
||||
})
|
@ -15,15 +15,11 @@ 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 = "tag")] string? tag = null)
|
||||
[FromQuery(Name = "p")] int? wpPostId = null)
|
||||
{
|
||||
if (postId.HasValue == wpPostId.HasValue)
|
||||
{
|
||||
Tag = tag?.Split('+').Select(t => t.Replace("%20", " ")).ToArray() ?? [];
|
||||
return Page();
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
@await Html.PartialAsync("Partials/_MastodonStatus")
|
||||
|
||||
<div id="all-blog-posts">
|
||||
@foreach (IBlogPost post in BlogPostService.GetBlogPosts(Model.PageNumber - 1, tags: Model.Tag))
|
||||
@foreach (IBlogPost post in BlogPostService.GetBlogPosts(Model.PageNumber - 1))
|
||||
{
|
||||
@await Html.PartialAsync("Partials/_BlogCard", post)
|
||||
}
|
||||
@ -19,6 +19,5 @@
|
||||
{
|
||||
["UrlRoot"] = "/blog",
|
||||
["Page"] = Model.PageNumber,
|
||||
["Tags"] = Model.Tag,
|
||||
["PageCount"] = BlogPostService.GetPageCount(visibility: Visibility.Published, tags: Model.Tag)
|
||||
["PageCount"] = BlogPostService.GetPageCount(visibility: Visibility.Published)
|
||||
})
|
@ -14,15 +14,12 @@ public class List : PageModel
|
||||
/// <value>The requested page number.</value>
|
||||
public int PageNumber { get; private set; }
|
||||
|
||||
public string[] Tag { get; private set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Handles the incoming GET request to the page.
|
||||
/// </summary>
|
||||
/// <param name="page">The requested page number, starting from 1.</param>
|
||||
/// <param name="tag">The tag by which to filter results.</param>
|
||||
/// <returns></returns>
|
||||
public IActionResult OnGet([FromRoute(Name = "pageNumber")] int page = 1, [FromQuery(Name = "tag")] string? tag = null)
|
||||
public IActionResult OnGet([FromRoute(Name = "pageNumber")] int page = 1)
|
||||
{
|
||||
if (page < 2)
|
||||
{
|
||||
@ -30,7 +27,6 @@ public class List : PageModel
|
||||
}
|
||||
|
||||
PageNumber = page;
|
||||
Tag = tag?.Split('+').Select(t => t.Replace("%20", " ")).ToArray() ?? [];
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,6 @@ public class PageTabsUtility
|
||||
set => _urlRoot = string.IsNullOrWhiteSpace(value) ? string.Empty : value.Trim();
|
||||
}
|
||||
|
||||
public string[]? Tags { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Shows the bound chevrons for the specified bounds type.
|
||||
/// </summary>
|
||||
@ -131,9 +129,7 @@ public class PageTabsUtility
|
||||
private string GetLinkForPage(int page)
|
||||
{
|
||||
// page 1 doesn't use /page/n route
|
||||
return page == 1
|
||||
? $"{_urlRoot}{(Tags is { Length: > 0 } ? $"?tag={string.Join('+', Tags)}" : "")}"
|
||||
: $"{_urlRoot}/page/{page}{(Tags is { Length: > 0 } ? $"?tag={string.Join('+', Tags)}" : "")}";
|
||||
return page == 1 ? _urlRoot : $"{_urlRoot}/page/{page}";
|
||||
}
|
||||
|
||||
private string ShowLowerBound()
|
||||
|
@ -7,23 +7,15 @@
|
||||
{
|
||||
CurrentPage = page,
|
||||
PageCount = pageCount,
|
||||
UrlRoot = urlRoot,
|
||||
Tags = ViewData["Tags"] as string[]
|
||||
UrlRoot = urlRoot
|
||||
};
|
||||
}
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
@if (pageCount == 1)
|
||||
{
|
||||
@Html.Raw(utility.ShowTab(1)) @* always visible *@
|
||||
}
|
||||
else
|
||||
{
|
||||
@Html.Raw(utility.ShowBounds(PageTabsUtility.BoundsType.Lower))
|
||||
@Html.Raw(utility.ShowTab(1)) @* always visible *@
|
||||
@Html.Raw(utility.ShowTabWindow())
|
||||
@Html.Raw(utility.ShowTab(pageCount)) @* always visible *@
|
||||
@Html.Raw(utility.ShowBounds(PageTabsUtility.BoundsType.Upper))
|
||||
}
|
||||
</ul>
|
||||
</nav>
|
@ -36,16 +36,9 @@ internal sealed class BlogPostService : IBlogPostService
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int GetBlogPostCount(Visibility visibility = Visibility.None, string[]? tags = null)
|
||||
public int GetBlogPostCount(Visibility visibility = Visibility.None)
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
if (tags is { Length: > 0 })
|
||||
{
|
||||
return visibility == Visibility.None
|
||||
? context.BlogPosts.AsEnumerable().Count(p => !p.IsRedirect && p.Tags.Intersect(tags).Any())
|
||||
: context.BlogPosts.AsEnumerable().Count(p => !p.IsRedirect && p.Visibility == visibility && p.Tags.Intersect(tags).Any());
|
||||
}
|
||||
|
||||
return visibility == Visibility.None
|
||||
? context.BlogPosts.Count(p => !p.IsRedirect)
|
||||
: context.BlogPosts.Count(p => !p.IsRedirect && p.Visibility == visibility);
|
||||
@ -67,20 +60,13 @@ internal sealed class BlogPostService : IBlogPostService
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<IBlogPost> GetBlogPosts(int page, int pageSize = 10, string[]? tags = null)
|
||||
public IReadOnlyList<IBlogPost> GetBlogPosts(int page, int pageSize = 10)
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
IEnumerable<BlogPost> posts = context.BlogPosts
|
||||
return context.BlogPosts
|
||||
.Where(p => p.Visibility == Visibility.Published && !p.IsRedirect)
|
||||
.OrderByDescending(post => post.Published)
|
||||
.AsEnumerable();
|
||||
|
||||
if (tags is { Length: > 0 })
|
||||
{
|
||||
posts = posts.Where(p => p.Tags.Intersect(tags).Any());
|
||||
}
|
||||
|
||||
return posts.Skip(page * pageSize)
|
||||
.Skip(page * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToArray().Select(CacheAuthor).ToArray();
|
||||
}
|
||||
@ -117,9 +103,9 @@ internal sealed class BlogPostService : IBlogPostService
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int GetPageCount(int pageSize = 10, Visibility visibility = Visibility.None, string[]? tags = null)
|
||||
public int GetPageCount(int pageSize = 10, Visibility visibility = Visibility.None)
|
||||
{
|
||||
float postCount = GetBlogPostCount(visibility, tags);
|
||||
float postCount = GetBlogPostCount(visibility);
|
||||
return (int)MathF.Ceiling(postCount / pageSize);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user