diff --git a/build.lua b/build.lua index 8a65de6..0d97102 100644 --- a/build.lua +++ b/build.lua @@ -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) diff --git a/config/me.yaml b/config/me.yaml new file mode 100644 index 0000000..eb537f9 --- /dev/null +++ b/config/me.yaml @@ -0,0 +1,2 @@ +name: Talia +link: https://tech.lgbt/@darkwiiplayer diff --git a/lib/feed/atom.lua b/lib/feed/atom.lua new file mode 100644 index 0000000..a4ba634 --- /dev/null +++ b/lib/feed/atom.lua @@ -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 [[]] .. 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 diff --git a/lib/feed/rss.lua b/lib/feed/rss.lua index 00801b7..8697fb8 100644 --- a/lib/feed/rss.lua +++ b/lib/feed/rss.lua @@ -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)); diff --git a/templates/main.html.skooma.yue b/templates/main.html.skooma.yue index 79c2bc8..2699c10 100644 --- a/templates/main.html.skooma.yue +++ b/templates/main.html.skooma.yue @@ -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"