2022-11-26 15:51:29 +01:00
|
|
|
using System.ServiceModel.Syndication;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using zotanpw.Backend;
|
2022-12-02 04:19:01 +01:00
|
|
|
using zotanpw.Pages;
|
2022-11-26 15:51:29 +01:00
|
|
|
|
|
|
|
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(),
|
2022-11-26 18:32:06 +01:00
|
|
|
Generator = $"zotan.pw-web {Utils.Version}",
|
|
|
|
ImageUrl = new Uri("https://zotan.pw/favicon.ico"),
|
|
|
|
Links = { SyndicationLink.CreateSelfLink(new Uri("https://zotan.pw/blog/feed.atom")), SyndicationLink.CreateAlternateLink(new Uri("https://zotan.pw/blog")) }
|
2022-11-26 15:51:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
AtomXml = new Atom10FeedFormatter(feed).ToXmlString();
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet, Route("/blog/feed.atom")]
|
|
|
|
public ActionResult GetAtomFeed() {
|
|
|
|
Response.ContentType = "application/atom+xml";
|
|
|
|
return Content(AtomXml);
|
|
|
|
}
|
|
|
|
}
|