@page "/" @using YaeBlog.Core.Models @using YaeBlog.Core.Services @inject BlogOptions BlogOptionsInstance @inject EssayContentService EssayContentInstance @inject NavigationManager NavigationManagerInstance @(BlogOptionsInstance.Author)'s Blog
@foreach (KeyValuePair essay in _essays) {
@(essay.Value.Title) @(essay.Value.PublishTime.ToString("yyyy-MM-dd HH:mm:ss")) @if (essay.Value.Tags.Count != 0) { @foreach (string tag in essay.Value.Tags) { @tag } }
}
@code { [SupplyParameterFromQuery] private int? Page { get; set; } private readonly List> _essays = []; private int _pageCount; protected override void OnInitialized() { Page ??= 1; IEnumerable[]> chunks = EssayContentInstance.Essays .OrderByDescending(pair => pair.Value.PublishTime) .Chunk(10); var count = 1; var flag = false; foreach (KeyValuePair[] chunk in chunks) { if (Page == count) { flag = true; _essays.AddRange(chunk); } count += 1; } _pageCount = count - 1; if (flag is false) { NavigationManagerInstance.NavigateTo("NotFount"); } } }