-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37a77c4
commit 99e6f0b
Showing
3 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@page "/Blog" | ||
@inject HttpClient Http | ||
|
||
<h3>@feedTitle</h3> | ||
<ul> | ||
@foreach (var post in posts) | ||
{ | ||
<li> | ||
<strong>@post.Title</strong><br/> | ||
Date Published: @post.DatePublished.ToLocalTime().ToString("f") | ||
<div>@(new MarkupString(post.ContentHtml))</div> | ||
<a href="@post.Url" target="_blank">Read more</a> | ||
</li> | ||
} | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace AboutMe.Wasm.Pages; | ||
|
||
// ReSharper disable once UnusedType.Global | ||
public partial class Blog | ||
{ | ||
private string feedTitle = string.Empty; | ||
private List<Item> posts = []; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
try | ||
{ | ||
const string feedUrl = "https://micro.bondcodes.com/feed.json"; | ||
var jsonResponse = await Http.GetStringAsync(feedUrl); | ||
|
||
var feed = JsonSerializer.Deserialize<Feed>(jsonResponse, | ||
new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); | ||
|
||
if (feed != null) | ||
{ | ||
feedTitle = feed.Title; | ||
posts = feed.Items.Take(10).ToList(); // Get the last 10 posts | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"Error loading feed: {ex.Message}"); | ||
} | ||
} | ||
} | ||
|
||
[JsonSerializable(typeof(Feed))] | ||
public class Feed | ||
Check warning on line 36 in AboutMe/Wasm/Pages/Blog.razor.cs GitHub Actions / Build and Deploy
Check warning on line 36 in AboutMe/Wasm/Pages/Blog.razor.cs GitHub Actions / Build and Deploy
|
||
{ | ||
[JsonPropertyName("version")] | ||
public string Version { get; set; } = ""; | ||
[JsonPropertyName("title")] | ||
public string Title { get; set; } = ""; | ||
[JsonPropertyName("icon")] | ||
public string Icon { get; set; } = ""; | ||
[JsonPropertyName("home_page_url")] | ||
public string HomePageUrl { get; set; } = ""; | ||
[JsonPropertyName("feed_url")] | ||
public string FeedUrl { get; set; } = ""; | ||
|
||
// ReSharper disable once CollectionNeverUpdated.Global | ||
[JsonPropertyName("items")] | ||
public List<Item> Items { get; set; } = []; | ||
} | ||
|
||
// ReSharper disable once ClassNeverInstantiated.Global | ||
public class Item | ||
{ | ||
// ReSharper disable once UnusedMember.Global | ||
[JsonPropertyName("id")] | ||
public string Id { get; set; } = ""; | ||
[JsonPropertyName("title")] | ||
public string Title { get; set; } = ""; | ||
[JsonPropertyName("content_text")] | ||
public string ContentHtml { get; set; } = ""; | ||
[JsonPropertyName("date_published")] | ||
public DateTime DatePublished { get; set; } | ||
[JsonPropertyName("url")] | ||
public string Url { get; set; } = ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters