add rss endpoint

This commit is contained in:
dreamer 2026-03-26 14:32:42 +01:00
parent ef04458cd8
commit 5c7626db66
3 changed files with 46 additions and 0 deletions

View File

@ -49,6 +49,11 @@ app:get("/latest.json", function(self)
return handlers.Latesthandler(self)
end)
app:get("/latest.rss", function(self)
self.titles = page_titles
return handlers.RSShandler(self)
end)
app:get("/*", function(self)
self.titles = page_titles
return handlers.Roothandler(self)

View File

@ -0,0 +1,23 @@
local to_json = require("lapis.util").to_json
local escape = require("lapis.util").escape
local autoload = require("lapis.util").autoload
local config = require("lapis.config")
local hotmixes = autoload("hotmixes")
local function RSShandler(self)
local path = config.get().mount .. self.titles.url
local latest_path, latest_name = hotmixes.utils.these_latest( path )
local host = self.req.parsed_url.scheme .. '://' .. self.req.parsed_url.host
local data_path = host .. '/data/' .. self.titles.url .. '/'
local latest_json = {}
latest_json["files"] = {}
self.latestpath = latest_path
self.latestname = latest_name
return { content_type = "text/rss", layout = require "views.rss" }
end
return RSShandler

18
code/views/rss.etlua Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="https://<%= titles['url'] %>/latest.xml" rel="self" type="application/rss+xml" />
<title>Hotmixes</title>
<link><%= titles['url'] %></link>
<description>Latest uploads</description>
<% for i, file in ipairs(latestpath) do %>
<item>
<title><%= latestname[i] %></title>
<link><%= 'https://' .. titles.url .. '/data/' .. titles.url .. '/' .. file:gsub("#", "%%23") %></link>
<description><![CDATA[<%= latestname[i] %>]]></description>
<guid><%= 'https://' .. titles.url .. '/data/' .. titles.url .. '/' .. file:gsub("#", "%%23") %></guid>
</item>
<% end %>
</channel>
</rss>