Skip to content

Commit

Permalink
System.ServiceModel.Syndication
Browse files Browse the repository at this point in the history
  • Loading branch information
danzuep committed Jan 24, 2024
1 parent b1911b2 commit 9563eca
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Bible.Web/Bible.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RunAOTCompilation>true</RunAOTCompilation>
<WasmStripILAfterAOT>false</WasmStripILAfterAOT>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.1" PrivateAssets="all" />
<PackageReference Include="System.ServiceModel.Syndication" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'!='Release'">
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
</ItemGroup>

</Project>
51 changes: 48 additions & 3 deletions Bible.Web/Pages/Feed.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,55 @@
@page "/feed"
@using System.ServiceModel.Syndication
@using System.Xml

<PageTitle>Verse of the Day</PageTitle>

<h1>Verse of the Day</h1>
<h1>@pageTitle</h1>

<hr />

<div id="dailyVersesWrapper"></div>
<script async defer src="https://dailyverses.net/get/verse.js?language=niv"></script>
@if (feedItems == null)
{
@* <p><em>Loading...</em></p> *@
<div id="dailyVersesWrapper"></div>
<script async defer src="https://dailyverses.net/get/verse.js?language=niv"></script>
}
else
{
foreach (var feedItem in feedItems)
{
<h4>@feedItem.Title</h4>
<p>@feedItem.Content</p>
<hr />
}
}

@code {
static readonly string defaultFeed = "https://www.biblegateway.com/votd/get/?format=atom";

Check warning on line 28 in Bible.Web/Pages/Feed.razor

View workflow job for this annotation

GitHub Actions / build / 🧱 Bible.Web 🏗 0.1.3-spa.1

The field 'Feed.defaultFeed' is assigned but its value is never used
string pageTitle = "Verse of the Day";
List<FeedItem>? feedItems;
HttpClient httpClient = new();

// protected override async Task OnInitializedAsync()
// {
// await GetFeedAsync(defaultFeed);
// }
private async Task GetFeedAsync(string feedUrl)
{
using var xmlStream = await httpClient.GetStreamAsync(feedUrl);
using var xmlReader = XmlReader.Create(xmlStream);
var feed = SyndicationFeed.Load(xmlReader);
pageTitle = feed.Title.Text;
feedItems = new List<FeedItem>();
foreach (var item in feed.Items)
{
if (item?.Content is TextSyndicationContent content && !string.IsNullOrWhiteSpace(content.Text))
feedItems.Add(new(item.Title.Text, (MarkupString)content.Text));
else if (!string.IsNullOrWhiteSpace(item?.Title.Text))
feedItems.Add(new(item.Title.Text, new()));
}
}

record FeedItem(string? Title, MarkupString Content);
}
2 changes: 1 addition & 1 deletion Bible.Web/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/"

<PageTitle>Home</PageTitle>
<PageTitle>Bible</PageTitle>

<h1>@reference</h1>

Expand Down
4 changes: 4 additions & 0 deletions Bible.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public static async Task Main(string[] args)

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

#if DEBUG
builder.Services.AddLogging(o => o.AddDebug());
#endif

await builder.Build().RunAsync();
}
}
Expand Down

0 comments on commit 9563eca

Please sign in to comment.