@@ -19,6 +19,7 @@ public class BlogPage : ComponentBase
1919 public string ? PreviousSlug { get ; set ; } = null ;
2020 public string ? NextSlug { get ; set ; } = null ;
2121 public string ? Title { get ; private set ; }
22+ public string ? ListTitle { get ; private set ; }
2223 public MarkupString ? PageContent { get ; private set ; }
2324 public Post ? CurrentPost { get ; set ; }
2425
@@ -31,6 +32,8 @@ protected override async Task OnInitializedAsync()
3132 IsLoading = true ;
3233 try
3334 {
35+ NavigationManager . LocationChanged += NavigationManager_LocationChanged ;
36+
3437 Categories = ( await BlogProvider . GetCategories ( ) ) ;
3538 Tags = await BlogProvider . GetTags ( ) ;
3639
@@ -49,6 +52,11 @@ protected override async Task OnInitializedAsync()
4952 await base . OnInitializedAsync ( ) ;
5053 }
5154
55+ private void NavigationManager_LocationChanged ( object ? sender , Microsoft . AspNetCore . Components . Routing . LocationChangedEventArgs e )
56+ {
57+ Logger . LogInformation ( e . Location ) ;
58+ }
59+
5260 protected MarkupString GetCategories ( )
5361 {
5462 var categories = CurrentPost ? . Categories ? . Select ( x => $ "<a href=\" /Blog/Categories/{ x } \" >{ x } </a>") ?? Enumerable . Empty < string > ( ) ;
@@ -86,8 +94,22 @@ protected override async Task OnParametersSetAsync()
8694 private async Task LoadPageData ( )
8795 {
8896 PageContent = null ;
89- Posts = await BlogProvider . GetPosts ( ) ;
97+ Posts = await BlogProvider . GetPosts ( Category , Tag ! ) ;
9098 Posts = Posts . OrderByDescending ( x => x . Posted ) ;
99+
100+ if ( ! string . IsNullOrEmpty ( Category ) )
101+ {
102+ ListTitle = $ "Posts by category '{ Category } '";
103+ }
104+ else if ( ! string . IsNullOrEmpty ( Tag ) )
105+ {
106+ ListTitle = $ "Posts by tag '{ Tag } '";
107+ }
108+ else
109+ {
110+ ListTitle = "All Posts" ;
111+ }
112+
91113 if ( ! string . IsNullOrEmpty ( Slug ) )
92114 {
93115 try
@@ -97,17 +119,17 @@ private async Task LoadPageData()
97119 Title = CurrentPost . Title ;
98120 CurrentSlug = Slug ;
99121
100- var index = 0 ;
122+ var index = 0 ;
101123 var indexedPosts = Posts . ToDictionary ( x => index ++ , x => x ) ;
102124 var currentPost = indexedPosts . FirstOrDefault ( x => x . Value . Slug . Equals ( Slug , StringComparison . InvariantCultureIgnoreCase ) ) ;
103125 var currentIndex = currentPost . Key ;
104126
105127 PreviousSlug = currentIndex < Posts . Count ( ) - 1 && currentIndex >= 0 ? indexedPosts [ currentIndex + 1 ] . Slug : null ;
106- NextSlug = currentIndex > 0 ? indexedPosts [ currentIndex - 1 ] . Slug : null ;
128+ NextSlug = currentIndex > 0 ? indexedPosts [ currentIndex - 1 ] . Slug : null ;
107129 }
108130 catch ( FileNotFoundException ex )
109131 {
110- Console . WriteLine ( ex . Message ) ;
132+ Logger . LogError ( ex , "LoadPageData" ) ;
111133 NavigationManager . NavigateTo ( "/" ) ;
112134 }
113135 }
0 commit comments