This commit is contained in:
Leon van Kammen 2026-07-28 08:50:24 +02:00
parent 1ff5f22e51
commit f99c2e502f
7 changed files with 70 additions and 34 deletions

View file

@ -18,6 +18,7 @@ app = require("soakbean") {
cache = { items = {} }, cache = { items = {} },
plugin = {}, plugin = {},
opts = {}, opts = {},
forkpids = {},
cmd={ cmd={
help = {file="cmd/help.lua", info="display all possible flags"}, help = {file="cmd/help.lua", info="display all possible flags"},
server = {file="cmd/server.lua", info="starts the webserver"}, server = {file="cmd/server.lua", info="starts the webserver"},
@ -68,7 +69,6 @@ print = function(...) Log(kLogInfo, ... or "''") end -- nice redbean logging fro
app.url['^/data'] = '/data.lua' -- setup custom file endpoint app.url['^/data'] = '/data.lua' -- setup custom file endpoint
app.url['^/$'] = '/page/index.lua' app.url['^/$'] = '/page/index.lua'
app.url['^/experiences[/]?$'] = '/page/experiences.lua'
app.url['^/admin[/]?$'] = '/page/admin/index.lua' app.url['^/admin[/]?$'] = '/page/admin/index.lua'
app.get('^/design[/]?$', util.pagerender('page/design.html')) app.get('^/design[/]?$', util.pagerender('page/design.html'))
@ -85,19 +85,33 @@ end)
app -- app --
.use( require("middleware/httpauth")() ) .use( require("middleware/httpauth")() )
.use( function(req,res,next)
local diskpath = app.opts.plugin_diskscan_dir
local urlpath = GetPath()
print( urlpath .. " => " .. diskpath)
foreach( app.cache.items, function(k,v)
print(v.path)
--local itempath = v.path:gsub("^.","")
--if itempath:sub(0,#diskpath) == diskpath then
-- local _, nslashes = itempath:gsub("/","")
-- local _, diskslashes = diskpath:gsub("/","")
-- if nslashes == diskslashes + 1 then
-- print("slashes = " .. nslashes .. " => " .. diskslashes)
-- table.insert(items,v)
-- end
--end
end)
end)
.use( require("json").middleware() ) -- try plug'n'play json API middleware .use( require("json").middleware() ) -- try plug'n'play json API middleware
.use( app.router( app.url ) ) -- try url router .use( app.router( app.url ) ) -- try url router
.use( app.response() ) -- try serve app response (if any) .use( app.response() ) -- try serve app response (if any)
.use( function(req,next) Route() end) -- fallback default redbean fileserver .use( function(req,next) Route() end) -- fallback default redbean fileserver
app.on('init', function() app.on('init', function()
if assert(unix.fork()) == 0 then --if assert(unix.fork()) == 0 then
app.plugin.diskscan.scan(app.opts.plugin_diskscan_dir)
print_r(app.cache)
--os.execute("ls ; sleep 5")
print("ok")
-- local ok, headers, body = Fetch('http://127.0.0.1:8080/test') -- local ok, headers, body = Fetch('http://127.0.0.1:8080/test')
end -- print_r({ok=ok,header=headers,body=body})
--end
end) end)
function OnHttpRequest() app.run() end function OnHttpRequest() app.run() end
@ -105,3 +119,7 @@ function OnHttpRequest() app.run() end
OnServerStart = function() OnServerStart = function()
app.init() -- this triggers init event app.init() -- this triggers init event
end end
OnServerStop = function()
print("todo: kill threads")
end

35
src/page/dir.lua Normal file
View file

@ -0,0 +1,35 @@
local util = require("util")
local tile = require('page/partial/tile')
--if not app.cache['experiences.html'] and util.count(app.cache.items) > 0 then
-- print("processing! " .. util.count(app.cache.items) .. " items")
-- app.cache['experiences.html'] = util.memoize(
-- function()
-- local data = util.merge({tiles=''},{ opts = app.opts })
-- foreach(app.cache.items, function(k,v)
-- data.tiles = data.tiles .. tile( util.flatten(v,"item") )
-- end)
-- local html = util.template( LoadAsset("page/experiences.html"),data)
-- return html
-- end,
-- 60*5 -- re-run every 5 mins (otherwise return cache)
-- )
--end
if util.count(app.cache.items) == 0 then
SetStatus(200)
SetHeader('Content-Type', 'text/html; charset=utf-8')
local html = util.template( [[
${header}
<br/>
<h2>Indexing files: please try again in few seconds</h2>
${footer}
]],data)
Write( html )
else
SetStatus(200)
SetHeader('Content-Type', 'text/html; charset=utf-8')
--Write( app.cache['experiences.html']() )
end

View file

@ -1,22 +0,0 @@
local util = require("util")
local tile = require('page/partial/tile')
if not app.cache['experiences.html'] then
print("processing! " .. util.count(app.cache.items) .. " items")
app.cache['experiences.html'] = util.memoize(
function()
local data = util.merge({tiles=''},{ opts = app.opts })
foreach(app.cache.items, function(k,v)
data.tiles = data.tiles .. tile( util.flatten(v,"item") )
end)
local html = util.template( LoadAsset("page/experiences.html"),data)
return html
end,
60*5 -- re-run every 5 mins (otherwise return cache)
)
end
SetStatus(200)
SetHeader('Content-Type', 'text/html; charset=utf-8')
Write( app.cache['experiences.html']() )

View file

@ -26,7 +26,8 @@
<td class="menu"> <td class="menu">
<div class="margin1L"> <div class="margin1L">
<!-- important: no spaces between anchor tags for older browsers without flexbox --> <!-- important: no spaces between anchor tags for older browsers without flexbox -->
<a href="/experiences">experiences</a><a href="/about">about</a><a class="xl" href="/howto">Howto</a></div> <a href="/dir">/myverse</a><a href="/about">/about</a>
<!--<a class="xl" href="/howto">Howto</a></div>-->
</td> </td>
</tr> </tr>
</table> </table>

View file

@ -1,5 +1,10 @@
local dir = require "opendirectory" local dir = require "opendirectory"
app.on('init', function()
print("scanning experiences (this make take a while..)")
app.plugin.diskscan.scan(app.opts.plugin_diskscan_dir)
end)
-- this registers the plugin UI /funcs -- this registers the plugin UI /funcs
return { return {
name = "Content (from disk)", name = "Content (from disk)",
@ -28,7 +33,7 @@ return {
local dref, derr = dir.foreach( scandir, function(path,stat,state,name,kind,ino,off,attr,fullpath) local dref, derr = dir.foreach( scandir, function(path,stat,state,name,kind,ino,off,attr,fullpath)
local experience = { local experience = {
path = fullpath, path = fullpath:gsub("^.",""), -- strip .
name = name, name = name,
title = name, title = name,
tag = {}, tag = {},

View file

@ -20,9 +20,8 @@ download(){
} }
janusweb(){ janusweb(){
version=1.7.4
test -f janusweb-${version}.tar.gz || { test -f janusweb-${version}.tar.gz || {
wget "https://github.com/jbaicoianu/janusweb/releases/download/v${version}/janusweb-${version}.tar.gz" wget "https://github.com/coderofsalvation/janusweb/releases/download/v1.7.5-rc/janusweb-1.7.5.tar.gz"
tar -xvf janusweb-${version}.tar.gz tar -xvf janusweb-${version}.tar.gz
mv janusweb-${version} src/v mv janusweb-${version} src/v
} }