alpha commit
This commit is contained in:
44
fsd.vxserver.dev/www/reader.lua
Normal file
44
fsd.vxserver.dev/www/reader.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
local fes = require("fes")
|
||||
local std = fes.std
|
||||
local u = fes.util
|
||||
|
||||
local site = fes.fes()
|
||||
|
||||
local title = "Free Software Distributions"
|
||||
|
||||
site.title = title .. " - Random Article"
|
||||
site:banner(std.center(std.h3(std.a("javascript:window.history.back();", "Return"))))
|
||||
|
||||
math.randomseed(os.time())
|
||||
|
||||
local articles_dir = "article"
|
||||
local files = {}
|
||||
|
||||
local p = io.popen("ls -1 " .. articles_dir)
|
||||
if p then
|
||||
for file in p:lines() do
|
||||
if file:match("%.md$") then
|
||||
files[#files + 1] = file
|
||||
end
|
||||
end
|
||||
p:close()
|
||||
end
|
||||
|
||||
local chosen = files[math.random(#files or 1)]
|
||||
local content = ""
|
||||
|
||||
if chosen then
|
||||
local f = io.open(articles_dir .. "/" .. chosen, "r")
|
||||
if f then
|
||||
content = f:read("*a")
|
||||
f:close()
|
||||
end
|
||||
end
|
||||
|
||||
local html = fes.markdown_to_html(content or "")
|
||||
|
||||
site:note(u.cc({
|
||||
std.div(html)
|
||||
}))
|
||||
|
||||
return site
|
||||
Reference in New Issue
Block a user