From f61b1ed4ab6ea4f3b2c3c602267bdb724f0ad157 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Mon, 10 Aug 2026 13:16:30 +0200 Subject: [PATCH] global plugin: set 2D vs 3D homepage (+added test) --- src/.init.lua | 5 +---- src/.lua/config.lua | 2 +- src/.lua/opendirectory.lua | 1 + src/css/xrforge.css | 1 + src/page/admin/index.lua | 2 +- src/page/dir.lua | 16 +++++++++------- src/page/footer.html | 2 +- src/page/header.html | 3 +-- src/page/index.lua | 17 ----------------- src/plugin/global.lua | 19 ++++++++++++++++++- src/test/main.lua | 13 +++++++++++++ src/test/plugin_global.lua | 36 ++++++++++++++++++++++++++++++++++++ 12 files changed, 83 insertions(+), 34 deletions(-) delete mode 100644 src/page/index.lua create mode 100644 src/test/plugin_global.lua diff --git a/src/.init.lua b/src/.init.lua index d4b469c..7616493 100644 --- a/src/.init.lua +++ b/src/.init.lua @@ -74,10 +74,7 @@ print = function(...) Log(kLogInfo, ... or "''") end -- nice redbean logging fro -- init URL router app.url['^/data'] = '/data.lua' -- setup custom file endpoint -app.get('^/$', function(req,res,next) - res.template = 'page/index.html' - next() -end) +app.get('^/$', app.plugin.global.middleware.homepage_2D_or_3D ) app.url['^/admin[/]?$'] = '/page/admin/index.lua' app.get('^/design[/]?$', util.pagerender('page/design.html')) diff --git a/src/.lua/config.lua b/src/.lua/config.lua index dffd1e7..87b5fd1 100644 --- a/src/.lua/config.lua +++ b/src/.lua/config.lua @@ -5,7 +5,7 @@ return function(app) local config = { -- default name = "XRForge", baseurl="/", - admin_title = "xrforge admin panel", + admin_title = "admin panel", admin_subtitle = "Manage your XR experiences here", } diff --git a/src/.lua/opendirectory.lua b/src/.lua/opendirectory.lua index 30e0914..1b9537c 100644 --- a/src/.lua/opendirectory.lua +++ b/src/.lua/opendirectory.lua @@ -34,6 +34,7 @@ dir.scan = function(path) if not stat or not unix.S_ISDIR( stat:mode() ) then return nil,nil, "not a dir" end -- let redbean take care of serving static file + path = unix.realpath(path) state,err = assert(unix.opendir(path)) return stat, state, err end diff --git a/src/css/xrforge.css b/src/css/xrforge.css index 6a57737..f30721e 100644 --- a/src/css/xrforge.css +++ b/src/css/xrforge.css @@ -14,6 +14,7 @@ .col5{ color:#447; } .col6{ color:#224; } .col7{ color:#112; } +.col8{ color:#000; } .page{ width:640px; } diff --git a/src/page/admin/index.lua b/src/page/admin/index.lua index 94998fd..9137315 100644 --- a/src/page/admin/index.lua +++ b/src/page/admin/index.lua @@ -55,7 +55,7 @@ end app.on('set', function(k,v) -- clear url cache if k:match("app.opts") then -- after (admin) updates to app.opts.* foreach( app.cache.url, function(k,v) - app.cache.url = nil + app.cache.url = {} end) end end) diff --git a/src/page/dir.lua b/src/page/dir.lua index 9c5d30e..fe7483d 100644 --- a/src/page/dir.lua +++ b/src/page/dir.lua @@ -12,21 +12,23 @@ return { local isdir = urlpath:sub(-1) == "/" local nslashes = util.countChar('/',urlpath) local match = function(a,b) return util.stripPath(a) == util.stripPath(b) end + local urlhash = urlpath .. util.dump( req.param ) + if urlpath == "/" or urlpath:match("^"..rootpath) and not urlpath:gsub(".*/",""):match("%.") then local redirect = false - if not app.cache.url[ urlpath ] then + if not app.cache.url[ urlhash ] or util.count(req.params) > 0 then local matchpath = urlpath if urlpath == '/' then matchpath = rootpath end -- generate janusxr footer for root url foreach( app.cache.items, function(k,v) if req.authenticated or app.plugin.moderation.isAllowed(v) then if v.parent then - trace( "path = " .. util.stripPath(v.path) .. " " .. - "parent = " .. util.stripPath(v.parent.path) .. " " .. - "matchpath = " .. util.stripPath(matchpath) - ) + --trace( "path = " .. util.stripPath(v.path) .. " " .. + -- "parent = " .. util.stripPath(v.parent.path) .. " " .. + -- "matchpath = " .. util.stripPath(matchpath) + --) if match(v.path, matchpath) then -- show parent folder if any local parent = app.cache.items[ v.parent.id ] if v.portal then @@ -75,7 +77,7 @@ return { end app.pub("dir", nil, {res=res,data=data, urlpath=urlpath, isdir=isdir}) if not redirect then - app.cache.url[ urlpath ] = util.templateFile( res.template, data) + app.cache.url[ urlhash ] = util.templateFile( res.template, data) end end if redirect then @@ -86,7 +88,7 @@ return { else res.status(200) res.header('content-type','text/html') - res.body( app.cache.url[ urlpath ] ) + res.body( app.cache.url[ urlhash ] ) next() end else diff --git a/src/page/footer.html b/src/page/footer.html index 6ff05ad..6699b77 100644 --- a/src/page/footer.html +++ b/src/page/footer.html @@ -18,7 +18,7 @@ NLNET
- View from XR Device
+ View from XR Device
Content overview
About
diff --git a/src/page/header.html b/src/page/header.html index 89b58e6..ddf66d7 100644 --- a/src/page/header.html +++ b/src/page/header.html @@ -20,8 +20,7 @@