diff --git a/PancakesWeb/Controllers/FeedController.cs b/PancakesWeb/Controllers/FeedController.cs new file mode 100644 index 0000000..ee35304 --- /dev/null +++ b/PancakesWeb/Controllers/FeedController.cs @@ -0,0 +1,48 @@ +using System.Net.Mime; +using System.ServiceModel.Syndication; +using System.Xml; +using Microsoft.AspNetCore.Mvc; +using PancakesWeb.Components.UI; + +namespace PancakesWeb.Controllers; + +[ApiController] +public class FeedController : ControllerBase +{ + [HttpGet("/feed.atom")] + [Produces("application/atom+xml")] + public ContentResult GetAtomFeed() + { + var feed = new SyndicationFeed + { + Title = new TextSyndicationContent("pancakes' blog"), + Description = new TextSyndicationContent("🐈‍⬛"), + Id = "https://pancakes.gay/feed.atom", + BaseUri = new Uri("https://pancakes.gay/feed.atom"), + Authors = { new SyndicationPerson("p@pancakes.gay", "pancakes", "https://pancakes.gay") }, + Items = BlogPosts.Posts.OrderByDescending(post => post.Published).Select(post => + new SyndicationItem(post.Title, SyndicationContent.CreateHtmlContent(post.Content), + new Uri($"https://pancakes.gay/{post.Slug}"), $"https://pancakes.gay/{post.Slug}", + new DateTimeOffset(post.Edited ?? post.Published)) + { + Copyright = post.Footer is BlogPosts.PostFooter.CcBy + ? new TextSyndicationContent( + $"{post.Title} © {post.Published.Year} by pancakes is licensed under CC BY 4.0") + : null, + PublishDate = new DateTimeOffset(post.Published), + Summary = new TextSyndicationContent(post.Description) + }), + Links = + { + SyndicationLink.CreateSelfLink(new Uri("https://pancakes.gay/feed.atom")), + SyndicationLink.CreateAlternateLink(new Uri("https://pancakes.gay"), MediaTypeNames.Text.Html), + } + }; + + var stringWriter = new StringWriter(); + var writer = new XmlTextWriter(stringWriter); + feed.SaveAsAtom10(writer); + + return Content(stringWriter.ToString(), "application/atom+xml"); + } +} \ No newline at end of file diff --git a/PancakesWeb/Data/Button.cs b/PancakesWeb/Data/Button.cs index fe50183..442b8e5 100644 --- a/PancakesWeb/Data/Button.cs +++ b/PancakesWeb/Data/Button.cs @@ -187,6 +187,12 @@ public static class Buttons { Image = "wii.webp", Title = "Wii" + }, + new Button + { + Image = "valid_atom.webp", + Title = "Valid Atom 1.0", + Href = "/feed.atom" } ]; } \ No newline at end of file diff --git a/PancakesWeb/PancakesWeb.csproj b/PancakesWeb/PancakesWeb.csproj index 13d4c41..224fc7f 100644 --- a/PancakesWeb/PancakesWeb.csproj +++ b/PancakesWeb/PancakesWeb.csproj @@ -8,6 +8,7 @@ + diff --git a/PancakesWeb/Program.cs b/PancakesWeb/Program.cs index 2f7d3fa..fa321a8 100644 --- a/PancakesWeb/Program.cs +++ b/PancakesWeb/Program.cs @@ -6,6 +6,7 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); builder.Services.AddHttpClient(); +builder.Services.AddControllers(); builder.Configuration.AddEnvironmentVariables(); @@ -32,5 +33,6 @@ app.UseAntiforgery(); app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode(); +app.MapControllers(); app.Run(); \ No newline at end of file diff --git a/PancakesWeb/wwwroot/imgs/buttons/valid_atom.webp b/PancakesWeb/wwwroot/imgs/buttons/valid_atom.webp new file mode 100644 index 0000000..2de0455 Binary files /dev/null and b/PancakesWeb/wwwroot/imgs/buttons/valid_atom.webp differ