zotan.pw-web/Controllers/AtomFeed.cs
2022-11-26 15:51:29 +01:00

36 lines
1.3 KiB
C#

using System.ServiceModel.Syndication;
using Microsoft.AspNetCore.Mvc;
using zotanpw.Backend;
using zotanpw.Pages.blog;
namespace zotanpw.Controllers;
[ApiController]
public class AtomFeed : Controller {
private static readonly string AtomXml;
static AtomFeed() {
var feed = new SyndicationFeed {
Id = "https://zotan.pw/blog",
Title = new TextSyndicationContent("zotan.pw >> blog"),
Description = new TextSyndicationContent("Blog of a disabled neurodivergent queer person unhappy with the state of the world"),
LastUpdatedTime = DateTimeOffset.Now,
Authors = { new SyndicationPerson("zotan@zotan.pw", "zotan", "https://zotan.pw") },
Items = BlogModel.Posts.Take(10)
.Select(post => new SyndicationItem(post.Title, new TextSyndicationContent(post.Content, TextSyndicationContentKind.Html),
new Uri($"https://zotan.pw/blog/{post.Shorthand}"), $"https://zotan.pw/blog/{post.Shorthand}",
post.PublishedOn.ToDateTime(TimeOnly.MinValue)))
.ToList(),
Links = { SyndicationLink.CreateSelfLink(new Uri("https://zotan.pw/blog/feed.atom")) }
};
AtomXml = new Atom10FeedFormatter(feed).ToXmlString();
}
[HttpGet, Route("/blog/feed.atom")]
public ActionResult GetAtomFeed() {
Response.ContentType = "application/atom+xml";
return Content(AtomXml);
}
}