-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/NielsPilgaard/Pilgaard.Blog
- Loading branch information
Showing
13 changed files
with
168 additions
and
37 deletions.
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
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
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,7 @@ | ||
namespace Pilgaard.Blog.Features.Feed; | ||
|
||
public static class DateOnlyExtensions | ||
{ | ||
public static DateTimeOffset ToDateTimeOffset(this DateOnly dateOnly) | ||
=> new(dateOnly.ToDateTime(new TimeOnly(0, 0, 0))); | ||
} |
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,72 @@ | ||
using Microsoft.SyndicationFeed; | ||
using System.Xml; | ||
using Microsoft.SyndicationFeed.Atom; | ||
using Pilgaard.Blog.Features.BlogPost; | ||
using Pilgaard.Blog.Features.SEO; | ||
|
||
namespace Pilgaard.Blog.Features.Feed; | ||
|
||
public static class FeedApi | ||
{ | ||
public static WebApplication MapRssFeed(this WebApplication app) | ||
{ | ||
app.MapGet("/feed.xml", async (HttpContext context) => | ||
{ | ||
context.Response.ContentType = "application/xml"; | ||
var stringWriter = new Utf8StringWriter(); | ||
await using var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings | ||
{ | ||
Async = true, | ||
Indent = true | ||
}); | ||
var writer = new AtomFeedWriter(xmlWriter); | ||
await writer.WriteTitle(DefaultMetadata.Title); | ||
var lastUpdated = BlogPostData | ||
.AllBlogPostSeries | ||
.SelectMany(blogPostSeries => blogPostSeries.BlogPosts.Select(blogPost => blogPost.LastUpdated)) | ||
.Max(); | ||
await writer.WriteUpdated(lastUpdated); | ||
await writer.Write(new SyndicationLink(new Uri(FeedConstants.BlogUrl))); | ||
foreach (var blogPostSeries in BlogPostData.AllBlogPostSeries) | ||
{ | ||
foreach (var blogPost in blogPostSeries.BlogPosts) | ||
{ | ||
var link = $"{FeedConstants.BlogUrl}/{blogPostSeries.GetRelativePath(blogPost)}"; | ||
var item = new SyndicationItem | ||
{ | ||
Id = link, | ||
Title = blogPost.Title, | ||
Description = blogPost.Description, | ||
Published = blogPost.PublishDate, | ||
LastUpdated = blogPost.LastUpdated, | ||
}; | ||
item.AddLink(new SyndicationLink(new Uri(link))); | ||
item.AddContributor(new SyndicationPerson("Niels Pilgaard Grøndahl", "[email protected]")); | ||
foreach (var blogPostTag in blogPost.Tags) | ||
{ | ||
item.AddCategory(new SyndicationCategory(blogPostTag)); | ||
} | ||
await writer.Write(item); | ||
} | ||
} | ||
// This closes the <content> element | ||
await xmlWriter.WriteEndElementAsync(); | ||
await xmlWriter.FlushAsync(); | ||
return stringWriter.ToString(); | ||
}); | ||
|
||
return app; | ||
} | ||
} |
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,6 @@ | ||
namespace Pilgaard.Blog.Features.Feed; | ||
|
||
internal static class FeedConstants | ||
{ | ||
internal const string BlogUrl = "https://pilgaard-blog.azurewebsites.net"; | ||
} |
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,8 @@ | ||
using System.Text; | ||
|
||
namespace Pilgaard.Blog.Features.Feed; | ||
|
||
internal sealed class Utf8StringWriter : StringWriter | ||
{ | ||
public override Encoding Encoding => Encoding.UTF8; | ||
} |
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
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 @@ | ||
Making an RSS feed is (apparently) fairly | ||
|
||
## Summary | ||
|
||
We learned how to use MudBlazor to keep dark/light mode settings in sync with system preference. | ||
|
||
Thank you [TDroogers](https://github.com/TDroogers) for [adding this feature to MudBlazor](https://github.com/MudBlazor/MudBlazor/pull/6320)! | ||
|
||
### See the code | ||
|
||
[Pull Request implementing the changes in this post](https://github.com/NielsPilgaard/Pilgaard.Blog/pull/29) | ||
|
||
### The state of the blog | ||
|
||
![State of the blog](https://user-images.githubusercontent.com/21295394/224152139-cd53b1a6-a89f-4b85-b10a-4beae4b83a22.png) |
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
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
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
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
Binary file not shown.