local json = require("dkjson") local http = require("ssl.https") local lom = require("lxp.lom") math.randomseed(os.time()) local function read(path) local f = assert(io.open(path, "r")) local data = f:read("*a") f:close() data = data:gsub("[\xC0-\xC1\xF5-\xFF]", "?") return data end local function write(path, lines) os.execute("mkdir -p docs") local f = io.open(path, "w") for _, line in ipairs(lines) do f:write(line, "\n") end f:close() end local function escape(s) return (s or "") :gsub("&", "&") :gsub("<", "<") :gsub(">", ">") :gsub('"', """) :gsub("'", "'") end local function strip(s) return (s or ""):gsub("<[^>]+>", ""):match("^%s*(.-)%s*$") end local function getTag(item, name) for _, child in ipairs(item) do if child.tag == name then return child[1] or "" end end return "" end local function parseItems(tree) for _, node in ipairs(tree) do if node.tag == "channel" then local items = {} for _, child in ipairs(node) do if child.tag == "item" then table.insert(items, child) end end return items end end return {} end local function getDomain(url) local domain = url:match("https?://([^/]+)") return domain or "codeberg.org" end local function isToday(date_str) if not date_str then return false end local today = os.date("!%d %b %Y") return date_str:find(today, 1, true) ~= nil end local sources = json.decode(read("sources.json")) local current_time = os.date("%H:%M") local rss_out = { '', '', '', 'Paperboy: ' .. current_time .. '', 'News feeds aggregated from multiple sources', 'https://moz75.codeberg.page/feeds-aggregator/feeds/docs/newsfeeds.xml', '' .. os.date("!%a, %d %b %Y %H:%M:%S GMT") .. '', '', } for _, source in ipairs(sources) do local body, code, headers = http.request(source.url) if body and body:match("") table.insert(rss_out, "" .. escape(strip(title)) .. "") table.insert(rss_out, "" .. escape(link) .. "") table.insert(rss_out, "" .. escape(link) .. "") table.insert(rss_out, "" .. date .. "") table.insert(rss_out, "" .. escape(domain) .. "") table.insert(rss_out, "") end end end end end table.insert(rss_out, "") table.insert(rss_out, "") write("docs/newsfeeds.xml", rss_out) os.execute("xsltproc docs/newsfeeds.xsl docs/newsfeeds.xml > docs/newsfeeds.html")