diff --git a/code/app.lua b/code/app.lua index b741f02..b422535 100644 --- a/code/app.lua +++ b/code/app.lua @@ -34,6 +34,11 @@ app:get("/", function(self) return handlers.Roothandler(self) end) +app:get("/latest.json", function(self) + self.titles = page_titles + return handlers.Latesthandler(self) +end) + app:get("/*", function(self) self.titles = page_titles return handlers.Roothandler(self) diff --git a/code/handlers/latesthandler.lua b/code/handlers/latesthandler.lua new file mode 100644 index 0000000..9bfbf76 --- /dev/null +++ b/code/handlers/latesthandler.lua @@ -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 Latesthandler(self) + + local path = config.get().mount .. self.titles.url + local latest_path, latest_name = hotmixes.utils.these_latest( path ) + + data_path = 'https://' .. self.titles.url .. '/data/' .. self.titles.url .. '/' + + latest_json = {} + + for i, file in ipairs(latest_path) do + latest_json[latest_name[i]] = data_path .. escape(file) + end + + return { json = latest_json } +end + +return Latesthandler