add rss endpoint
This commit is contained in:
parent
ef04458cd8
commit
5c7626db66
@ -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)
|
||||
|
||||
23
code/handlers/RSShandler.lua
Normal file
23
code/handlers/RSShandler.lua
Normal 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
18
code/views/rss.etlua
Normal 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>
|
||||
Loading…
Reference in New Issue
Block a user