Skip to content

Commit 87621e2

Browse files
committed
Broke Blog page into components.
1 parent a940ff7 commit 87621e2

14 files changed

Lines changed: 147 additions & 87 deletions

Source/Dove.Blog.WebApp/Components/Pages/Blog.razor

Lines changed: 6 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
@page "/blog/Categories/{*category}"
44
@page "/blog/Tags/{*tag}"
55

6+
@using Dove.Blog.WebApp.Components.Parts
7+
68
@inherits BlogPage
79

810
<PageTitle>@Title</PageTitle>
@@ -17,98 +19,17 @@ else
1719
<div class="post col-9">
1820
@if (PageContent != null)
1921
{
20-
<h1>@Title</h1>
21-
<div>
22-
@PageContent
23-
</div>
24-
25-
<hr />
26-
27-
<div>
28-
<p>
29-
<span>Posted in @GetCategories()</span>
30-
<span>on @CurrentPost?.Posted.ToString("g")</span>
31-
<span>by @CurrentPost?.Author</span>
32-
</p>
33-
<p><span>Tags: </span>@GetTags()</p>
34-
</div>
35-
36-
<hr />
37-
38-
<div class="d-flex justify-content-between">
39-
@if (PreviousSlug != null)
40-
{
41-
<a href="/Blog/@PreviousSlug">&lt;&lt; Previous</a>
42-
}
43-
else
44-
{
45-
<span class="text-secondary">&lt;&lt; Previous</span>
46-
}
47-
48-
<a href="/Blog">Back to Blog</a>
49-
50-
@if (NextSlug != null)
51-
{
52-
<a href="/Blog/@NextSlug">Next &gt;&gt;</a>
53-
}
54-
else
55-
{
56-
<span class="text-secondary">Next &gt;&gt;</span>
57-
}
58-
</div>
22+
<BlogContent CurrentPost="@CurrentPost" PageContent="@PageContent" />
23+
<BlogNavigation PreviousSlug="@PreviousSlug" NextSlug="@NextSlug" />
5924
}
6025
else
6126
{
62-
<h2>Latest Blog Posts</h2>
63-
@foreach (var post in Posts.Take(10))
64-
{
65-
<div class="card mb-3 shadow p-2">
66-
<h3><a href="/Blog/@post.Slug">@post.Title</a></h3>
67-
<p>@post.Summary</p>
68-
<a href="/Blog/@post.Slug">Read more...</a>
69-
</div>
70-
}
71-
@if (Posts.Count() > 10)
72-
{
73-
<div class="load-more">
74-
<a href="#">Load more posts...</a>
75-
</div>
76-
}
27+
<BlogPostList Posts="@Posts" />
7728
}
7829
</div>
7930

8031
<div class="sidebar col-3">
81-
<h4>Categories</h4>
82-
<ul>
83-
@foreach (var category in Categories.Take(8))
84-
{
85-
<li>
86-
<a href="">@category</a>
87-
</li>
88-
}
89-
@if (Categories.Count() > 8)
90-
{
91-
<li>
92-
<a href="">More...</a>
93-
</li>
94-
}
95-
</ul>
96-
97-
<h4>Frequently Used Tags</h4>
98-
<ul>
99-
@foreach (var tag in Tags.Take(8))
100-
{
101-
<li>
102-
<a href="">@tag</a>
103-
</li>
104-
}
105-
@if (Tags.Count() > 8)
106-
{
107-
<li>
108-
<a href="">More...</a>
109-
</li>
110-
}
111-
</ul>
32+
<BlogSidebar Categories="@Categories" Tags="@Tags" />
11233
</div>
11334
</div>
11435
}

Source/Dove.Blog.WebApp/Components/Pages/Blog.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class BlogPage : ComponentBase
2222
public MarkupString? PageContent { get; private set; }
2323
public Post? CurrentPost { get; set; }
2424

25-
public IEnumerable<string> Categories { get; private set; } = Enumerable.Empty<string>();
25+
public IEnumerable<(string Category, int Posts)> Categories { get; private set; } = Enumerable.Empty<(string Category, int Posts)>();
2626
public IEnumerable<string> Tags { get; private set; } = Enumerable.Empty<string>();
2727
public IEnumerable<PostSummary> Posts { get; private set; } = null!;
2828

@@ -31,7 +31,7 @@ protected override async Task OnInitializedAsync()
3131
IsLoading = true;
3232
try
3333
{
34-
Categories = (await BlogProvider.GetCategories()).Select(x => x.category);
34+
Categories = (await BlogProvider.GetCategories());
3535
Tags = await BlogProvider.GetTags();
3636

3737
await LoadPageData();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@inherits BlogContentBase
2+
3+
<h1>@CurrentPost?.Title</h1>
4+
<div>
5+
@PageContent
6+
</div>
7+
8+
<hr />
9+
10+
<div>
11+
<p>
12+
<span>Posted in @GetCategories()</span>
13+
<span>on @CurrentPost?.Posted.ToString("g")</span>
14+
<span>by @CurrentPost?.Author</span>
15+
</p>
16+
<p><span>Tags: </span>@GetTags()</p>
17+
</div>
18+
19+
<hr />
20+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Dove.Blog.Data;
2+
using Microsoft.AspNetCore.Components;
3+
4+
namespace Dove.Blog.WebApp.Components.Parts;
5+
6+
public partial class BlogContentBase : ComponentBase
7+
{
8+
[Parameter]public Post? CurrentPost { get; set; }
9+
[Parameter] public MarkupString? PageContent { get; set; }
10+
11+
protected MarkupString GetCategories()
12+
{
13+
var categories = CurrentPost?.Categories?.Select(x => $"<a href=\"/Blog/Categories/{x}\">{x}</a>") ?? Enumerable.Empty<string>();
14+
return new MarkupString(string.Join(", ", categories));
15+
}
16+
17+
protected MarkupString GetTags()
18+
{
19+
var tags = CurrentPost?.Tags?.Select(x => $"<a href=\"/Blog/Tags/{x}\">{x}</a>") ?? Enumerable.Empty<string>();
20+
return new MarkupString(string.Join(", ", tags));
21+
}
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@inherits BlogNavigationBase
2+
3+
<div class="d-flex justify-content-between">
4+
@if (PreviousSlug != null)
5+
{
6+
<a href="/Blog/@PreviousSlug">&lt;&lt; Previous</a>
7+
}
8+
else
9+
{
10+
<span class="text-secondary">&lt;&lt; Previous</span>
11+
}
12+
13+
<a href="/Blog">Back to Blog</a>
14+
15+
@if (NextSlug != null)
16+
{
17+
<a href="/Blog/@NextSlug">Next &gt;&gt;</a>
18+
}
19+
else
20+
{
21+
<span class="text-secondary">Next &gt;&gt;</span>
22+
}
23+
</div>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Microsoft.AspNetCore.Components;
2+
3+
namespace Dove.Blog.WebApp.Components.Parts;
4+
public partial class BlogNavigationBase : ComponentBase
5+
{
6+
[Parameter] public string? PreviousSlug { get; set; } = null;
7+
[Parameter] public string? NextSlug { get; set; } = null;
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@inherits BlogPostListBase
2+
3+
<h2>Latest Blog Posts</h2>
4+
@foreach (var post in Posts.Take(10))
5+
{
6+
<div class="card mb-3 shadow p-2">
7+
<h3><a href="/Blog/@post.Slug">@post.Title</a></h3>
8+
<p>@post.Summary</p>
9+
<a href="/Blog/@post.Slug">Read more...</a>
10+
</div>
11+
}
12+
13+
@if (Posts.Count() > 10)
14+
{
15+
<div class="load-more">
16+
<a href="#">Load more posts...</a>
17+
</div>
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Dove.Blog.Data;
2+
using Microsoft.AspNetCore.Components;
3+
4+
namespace Dove.Blog.WebApp.Components.Parts;
5+
public partial class BlogPostListBase : ComponentBase
6+
{
7+
[Parameter] public IEnumerable<PostSummary> Posts { get; set; } = null!;
8+
}

0 commit comments

Comments
 (0)