Add Atom 1.0 feed syndication
This commit is contained in:
parent
fa9500eb81
commit
fb4d9fa0aa
5 changed files with 57 additions and 0 deletions
48
PancakesWeb/Controllers/FeedController.cs
Normal file
48
PancakesWeb/Controllers/FeedController.cs
Normal file
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -187,6 +187,12 @@ public static class Buttons
|
||||||
{
|
{
|
||||||
Image = "wii.webp",
|
Image = "wii.webp",
|
||||||
Title = "Wii"
|
Title = "Wii"
|
||||||
|
},
|
||||||
|
new Button
|
||||||
|
{
|
||||||
|
Image = "valid_atom.webp",
|
||||||
|
Title = "Valid Atom 1.0",
|
||||||
|
Href = "/feed.atom"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Markdig" Version="0.42.0" />
|
<PackageReference Include="Markdig" Version="0.42.0" />
|
||||||
|
<PackageReference Include="System.ServiceModel.Syndication" Version="9.0.9" />
|
||||||
<PackageReference Include="YamlDotNet" Version="16.3.0" />
|
<PackageReference Include="YamlDotNet" Version="16.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ var builder = WebApplication.CreateBuilder(args);
|
||||||
builder.Services.AddRazorComponents()
|
builder.Services.AddRazorComponents()
|
||||||
.AddInteractiveServerComponents();
|
.AddInteractiveServerComponents();
|
||||||
builder.Services.AddHttpClient();
|
builder.Services.AddHttpClient();
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
builder.Configuration.AddEnvironmentVariables();
|
builder.Configuration.AddEnvironmentVariables();
|
||||||
|
|
||||||
|
@ -32,5 +33,6 @@ app.UseAntiforgery();
|
||||||
app.MapStaticAssets();
|
app.MapStaticAssets();
|
||||||
app.MapRazorComponents<App>()
|
app.MapRazorComponents<App>()
|
||||||
.AddInteractiveServerRenderMode();
|
.AddInteractiveServerRenderMode();
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
BIN
PancakesWeb/wwwroot/imgs/buttons/valid_atom.webp
Normal file
BIN
PancakesWeb/wwwroot/imgs/buttons/valid_atom.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 2 KiB |
Loading…
Add table
Reference in a new issue