Add atom feed too because cool

This commit is contained in:
Talia 2023-10-26 10:12:49 +02:00
parent 4628cab3f8
commit 2fb681d121
Signed by: darkwiiplayer
GPG key ID: 7808674088232B3E
5 changed files with 65 additions and 5 deletions

View file

@ -6,6 +6,7 @@ local shapeshift = require 'shapeshift'
-- Project-specific stuff
local rss = require 'feed.rss'
local atom = require 'feed.atom'
local paramparser = require 'paramparser'
local params = paramparser(...)
package.loaded.params = params
@ -36,6 +37,7 @@ for idx, post in ipairs(posts) do
end
scaffold.deep(tree, "feeds/all.rss.xml", rss(posts))
scaffold.deep(tree, "feeds/all.atom.xml", atom(posts))
if params.delete then
restia.utils.delete(params.output)

2
config/me.yaml Normal file
View file

@ -0,0 +1,2 @@
name: Talia
link: https://tech.lgbt/@darkwiiplayer

60
lib/feed/atom.lua Normal file
View file

@ -0,0 +1,60 @@
local skooma = require 'skooma'
local config = require 'config'
local xml = skooma.env()
local rfc3339 = "%Y-%m-%dT%H:%M:%SZ"
local function map(sequence, fun)
local new = {}
for key, value in ipairs(sequence) do
new[key] = fun(value)
end
return new
end
return function(posts)
return [[<?xml version="1.0" encoding="utf-8"?>]] .. tostring(xml.feed{
xmlns="http://www.w3.org/2005/Atom";
xml.id("https://blog.but.gay/");
xml.title(config.title:gsub("\n$", ""));
xml.link { rel="alternate", href = "https://blog.but.gay/", type="text/html" };
xml.link { rel="self", href = "https://blog.but.gay/feeds/all.atom.xml" };
xml.updated(os.date(rfc3339));
xml.author(
xml.name(config.me.name),
xml.uri(config.me.link)
);
xml.generator {
uri = "https://github.com/darkwiiplayer/blog";
"Home-grown SSG"
};
--xml.description(config.description);
map(posts, function(post)
local link = "https://blog.but.gay"..post.head.uri
return xml.entry {
xml.id(link);
xml.title(post.head.title);
function()
if post.head.updates then
return xml.updated(os.date(rfc3339, post.head.updates[#post.head.updates]));
else
return xml.updated(os.date(rfc3339, post.head.timestamp));
end
end;
--
xml.summary(post.head.description);
xml.content {
type="html";
post.body;
};
xml.link { href = link };
--
xml.published(os.date(rfc3339, post.head.timestamp));
map(post.head.tags, function(tag)
return xml.category { term = tag }
end)
}
end)
})
end

View file

@ -14,7 +14,6 @@ end
return function(posts)
return tostring(xml.rss{
version="2.0";
["xmlns:atom"]="http://www.w3.org/2005/Atom";
xml.channel {
xml.title(config.title);
xml.link "https://blog.but.gay/";
@ -26,10 +25,6 @@ return function(posts)
return xml.item {
xml.title(post.head.title);
xml.description(post.head.description);
xml.content {
type="html";
post.body;
};
xml.link(link);
xml.guid(link);
xml.pubDate(os.date("%d %b %Y", post.head.timestamp));

View file

@ -40,6 +40,7 @@ html
lang: "english"
* head
* link rel: 'alternate', type: 'application/rss+xml', title: 'RSS 2.0 feed', href: "/feeds/all.rss.xml"
* link rel: 'alternate', type: 'application/atom+xml', title: 'Atom feed', href: "/feeds/all.atom.xml"
* meta name: "view-transition", content: "same-origin"
* meta charset: "UTF-8"
* meta name: "viewport", content: "width=device-width"