diff --git a/YaeBlog.Core/Services/EssayContentService.cs b/YaeBlog.Core/Services/EssayContentService.cs index bfcbfe8..2fcef74 100644 --- a/YaeBlog.Core/Services/EssayContentService.cs +++ b/YaeBlog.Core/Services/EssayContentService.cs @@ -14,9 +14,7 @@ public class EssayContentService public bool TryAdd(string key, BlogEssay essay) => _essays.TryAdd(key, essay); - public IEnumerable> Essays => _essays; - - public int Count => _essays.Count; + public IDictionary Essays => _essays; public void RefreshTags() { diff --git a/YaeBlog/Components/BlogInformationCard.razor b/YaeBlog/Components/BlogInformationCard.razor new file mode 100644 index 0000000..98903e3 --- /dev/null +++ b/YaeBlog/Components/BlogInformationCard.razor @@ -0,0 +1,4 @@ +
+

“奇奇怪怪东西的聚合地”

+
+ diff --git a/YaeBlog/Components/BlogInformationCard.razor.css b/YaeBlog/Components/BlogInformationCard.razor.css new file mode 100644 index 0000000..e69de29 diff --git a/YaeBlog/Layout/BlogLayout.razor b/YaeBlog/Layout/BlogLayout.razor index 59f5cba..97e0e9c 100644 --- a/YaeBlog/Layout/BlogLayout.razor +++ b/YaeBlog/Layout/BlogLayout.razor @@ -1,9 +1,11 @@ @inherits LayoutComponentBase -
+@attribute [StreamRendering] + +
-
+
@Body -
+
- + diff --git a/YaeBlog/Layout/MainLayout.razor b/YaeBlog/Layout/MainLayout.razor index 5c5f7ec..27ee167 100644 --- a/YaeBlog/Layout/MainLayout.razor +++ b/YaeBlog/Layout/MainLayout.razor @@ -1,6 +1,6 @@ @inherits LayoutComponentBase - - + diff --git a/YaeBlog/Layout/MainLayout.razor.css b/YaeBlog/Layout/MainLayout.razor.css index 8f55588..94874ec 100644 --- a/YaeBlog/Layout/MainLayout.razor.css +++ b/YaeBlog/Layout/MainLayout.razor.css @@ -1,6 +1,7 @@ .center { margin: 0 auto; max-width: 48em; + min-height: calc(100vh - 80px); position: relative; display: flex; flex-direction: column; diff --git a/YaeBlog/Pages/BlogIndex.razor b/YaeBlog/Pages/BlogIndex.razor index 59d0b77..a3f9467 100644 --- a/YaeBlog/Pages/BlogIndex.razor +++ b/YaeBlog/Pages/BlogIndex.razor @@ -1,3 +1,144 @@ @page "/blog" +@using YaeBlog.Core.Models +@using YaeBlog.Core.Services +@inject EssayContentService EssayContentInstance +@inject NavigationManager NavigationInstance +@inject ILogger Logger +
+
+
+ @foreach (KeyValuePair pair in _essays) + { +
+ + +
+
+ @(pair.Value.PublishTime.ToString("yyyy-MM-dd")) +
+ + @foreach (string key in pair.Value.Tags) + { + + } +
+ +
+
+ @(pair.Value.Description) +
+
+ +
+
+ +
+
+
+ } + +
+ @if (_page == 1) + { +
上一页
+ } + else + { +
+ 上一页 +
+ } + + @if (_page == 1) + { +
+ 1 +
+
+ 2 +
+
+ 3 +
+ } + else if (_page == _pageCount) + { + + + + } + else + { + +
+ @(_page) +
+ + } + + @if (_page == _pageCount) + { +
+ 下一页 +
+ } + else + { +
+ 下一页 +
+ } +
+
+ +
+ +
+
+
+ +@code { + + [SupplyParameterFromQuery] private int? Page { get; set; } + + private readonly List> _essays = []; + private const int EssaysPerPage = 8; + private int _pageCount = 1; + private int _page = 1; + + protected override void OnInitialized() + { + _page = Page ?? 1; + _pageCount = EssayContentInstance.Essays.Count / EssaysPerPage + 1; + + if (EssaysPerPage * _page > EssayContentInstance.Essays.Count + EssaysPerPage) + { + NavigationInstance.NavigateTo("/NotFount"); + return; + } + + _essays.AddRange(EssayContentInstance.Essays + .OrderByDescending(p => p.Value.PublishTime) + .Skip((_page - 1) * EssaysPerPage) + .Take(EssaysPerPage)); + } + +} diff --git a/YaeBlog/Pages/BlogIndex.razor.css b/YaeBlog/Pages/BlogIndex.razor.css index e69de29..ffb2673 100644 --- a/YaeBlog/Pages/BlogIndex.razor.css +++ b/YaeBlog/Pages/BlogIndex.razor.css @@ -0,0 +1,7 @@ +.essay-title a { + color: var(--bs-body-color); +} + +.read-more a { + color: var(--bs-body-color); +} diff --git a/YaeBlog/Pages/Essays.razor b/YaeBlog/Pages/Essays.razor new file mode 100644 index 0000000..abface1 --- /dev/null +++ b/YaeBlog/Pages/Essays.razor @@ -0,0 +1,34 @@ +@page "/blog/essays/{BlogKey}" +@using YaeBlog.Core.Models +@using YaeBlog.Core.Services + +@inject NavigationManager NavigationInstance +@inject EssayContentService EssayContentInstance + +
+ +
+ +@code { + [Parameter] + public string? BlogKey { get; set; } + + private BlogEssay? _essay; + + protected override void OnInitialized() + { + base.OnInitialized(); + + if (string.IsNullOrWhiteSpace(BlogKey)) + { + NavigationInstance.NavigateTo("/NotFound"); + return; + } + + if (!EssayContentInstance.TryGet(BlogKey, out _essay)) + { + NavigationInstance.NavigateTo("/NotFound"); + } + } + +} diff --git a/YaeBlog/Pages/Essays.razor.css b/YaeBlog/Pages/Essays.razor.css new file mode 100644 index 0000000..e69de29 diff --git a/YaeBlog/Pages/NotFound.razor b/YaeBlog/Pages/NotFound.razor new file mode 100644 index 0000000..cd87b0d --- /dev/null +++ b/YaeBlog/Pages/NotFound.razor @@ -0,0 +1,9 @@ +@page "/NotFound" + +
+

NotFound!

+
+ +@code { + +} diff --git a/YaeBlog/Pages/NotFound.razor.css b/YaeBlog/Pages/NotFound.razor.css new file mode 100644 index 0000000..e69de29 diff --git a/YaeBlog/wwwroot/globals.css b/YaeBlog/wwwroot/globals.css index f655aa1..1926a42 100644 --- a/YaeBlog/wwwroot/globals.css +++ b/YaeBlog/wwwroot/globals.css @@ -2,6 +2,12 @@ body a { text-decoration: none; } +body main { + flex: 1; + min-height: 100vh; + overflow-x: visible; +} + @font-face { font-family: "Font Awesome 6 Free"; font-style: normal;