added git + staticwebgen plugin

This commit is contained in:
Leon van Kammen 2026-08-12 15:00:42 +02:00
parent 70e03b2b71
commit d859033164
13 changed files with 158 additions and 16 deletions

View file

@ -67,6 +67,7 @@ app.plugin.manyfold = app.addPlugin('plugin/manyfold')
app.plugin.git = app.addPlugin('plugin/git') app.plugin.git = app.addPlugin('plugin/git')
app.plugin.webhook = app.addPlugin('plugin/webhook') app.plugin.webhook = app.addPlugin('plugin/webhook')
app.plugin.markdown = app.addPlugin('plugin/markdown') app.plugin.markdown = app.addPlugin('plugin/markdown')
app.plugin.staticwebgen = app.addPlugin('plugin/staticwebgen') -- should always be last
app.runcmd(app) -- run clicmds app.runcmd(app) -- run clicmds

View file

@ -299,15 +299,20 @@ function util.fetchInstall(app)
app.post('/bus',function(req,res,next) app.post('/bus',function(req,res,next)
local reqid = GetParam('id') local reqid = GetParam('id')
local cb = app.expectedreq[reqid] local cb = app.expectedreq[reqid]
if cb then cb(req,res,next) end if cb then cb(res,req,next) end -- important: flipped req,res
end) end)
end end
function util.fetchServer(url, opts, cb)
util.fetch( util.getURL(url,{server=true}), nil, cb )
end
function util.fetch(url, opts, cb) function util.fetch(url, opts, cb)
local reqid = tostring( Rdrand() ) local reqid = tostring( Rdrand() )
app.expectedreq[reqid] = cb app.expectedreq[reqid] = cb
local urlret = util.getURL('/bus?id=' .. reqid, {server=true} ) local urlret = util.getURL('/bus?id=' .. reqid, {server=true} )
if assert(unix.fork()) == 0 then if assert(unix.fork()) == 0 then
print('🤞 fetch ' .. url)
local ok, headers, body = Fetch(url, opts) local ok, headers, body = Fetch(url, opts)
if ok then if ok then
Fetch(urlret, body) -- post back to ourselves Fetch(urlret, body) -- post back to ourselves

View file

@ -1,6 +1,7 @@
return function(app,argv) return function(app,argv)
print('generating..') print('generating..')
app.plugin.clouddrive.mount() -- do nothing here, as this is handled by the src/plugin/staticwebgen.lua
--app.plugin.diskscan.scan( app.opts.plugin_diskscan_dir ) -- AFTER all plugins are loaded
print('TODO: disabled for now..not stable')
os.exit() os.exit()
end end

View file

@ -1,6 +1,5 @@
<title>world 1 title</title> <title>world 1 title</title>
<fireboxroom> <fireboxroom>
<room use_local_asset="room-plane"> <room use_local_asset="room2">
</room> </room>
</fireboxroom> </fireboxroom>

View file

@ -65,7 +65,7 @@ end)
function pluginUI(seen,data) function pluginUI(seen,data)
return function(name,plugin) return function(name,plugin)
if seen[ plugin.name ] then return end -- already processed if plugin.hide or seen[ plugin.name ] then return end -- already processed
table.insert( data.tabs, plugin.name ) -- insert tabname table.insert( data.tabs, plugin.name ) -- insert tabname
seen[ plugin.name ] = true seen[ plugin.name ] = true
local plugindata = {plugin=plugin} local plugindata = {plugin=plugin}
@ -92,7 +92,6 @@ function saveData()
else else
data.notification = '<div class="notification">no changes detected</div>' data.notification = '<div class="notification">no changes detected</div>'
end end
print(app.opts.plugin_global_homepage)
end end
end end

View file

@ -21,13 +21,18 @@ ${header}
end} end}
<script> <script>
// minimal JS to sync parent/iframe URL-locations // Title- and URL-sync between parent/iframe to foster addressibility
const iframe = document.querySelector("#viewer") const iframe = document.querySelector("#viewer")
iframe.addEventListener('load', () => { iframe.addEventListener('load', () => {
const iframeWindow = iframe.contentWindow; const iframeWindow = iframe.contentWindow;
iframeWindow.addEventListener('hashchange', (event) => { iframeWindow.addEventListener('hashchange', (event) => {
const params = new URLSearchParams( String(iframeWindow.location.hash).replace(/^#/,'?') ) const params = new URLSearchParams( String(iframeWindow.location.hash).replace(/^#/,'?') )
const url = params.get('janus.url') let url = params.get('janus.url')
if( url == document.location.href ) return
try{ // handle external urls via ?url=
let urlObj = new URL(url)
url = document.location.origin + document.location.pathname + '?url=' + url
}catch(e){}
window.history.replaceState( url, iframe.contentDocument.title, url ); window.history.replaceState( url, iframe.contentDocument.title, url );
setTimeout( () => { setTimeout( () => {
document.title = iframe.contentDocument.title document.title = iframe.contentDocument.title

View file

@ -42,7 +42,7 @@ end}
{if true then {if true then
function addPortal(id,x,v,url,i,z,thumb,rotation,scale) function addPortal(id,x,v,url,i,z,thumb,rotation,scale)
print('\t<object js_id="' .. id .. '_' .. i .. '" pos="' .. x .. ' 0 ' .. z .. '" rotation="' .. rotation .. '">') print('\t<object js_id="' .. id .. '_' .. i .. '" pos="' .. x .. ' 0 ' .. z .. '" rotation="' .. rotation .. '">')
print('\t <link url="' .. url .. '" ' .. thumb .. ' title_col="0.4 0.37 0.4" pos="0 0 0.001" draw_glow="true" scale="3 3 0.1" />') print('\t <link url="' .. url .. '" ' .. thumb .. ' title_col="0.4 0.37 0.4" pos="0 0 0.001" draw_glow="' .. (thumb:match("shader") and 'false' or 'true') .. '" scale="3 3 0.1" />')
print('\t <text text="' .. v.title .. '" pos="0 3.4 0" col="1 1 1" font_scale="false" scale="' .. scale .. '" />') print('\t <text text="' .. v.title .. '" pos="0 3.4 0" col="1 1 1" font_scale="false" scale="' .. scale .. '" />')
print('\t</object>') print('\t</object>')
end end
@ -82,7 +82,7 @@ end}
for i,fediurl in pairs(portals) do for i,fediurl in pairs(portals) do
local width = 3.2 local width = 3.2
local center = -((#portals*width)/1.3) + (i*width) local center = -((#portals*width)/1.3) + (i*width)
local thumb = ' image_id="federated' .. i .. '"' local thumb = ' thumb_id="federated' .. i .. '"'
addPortal('federated',center, {title=fediurl}, fediurl,i, 4, thumb, '0 180 0', '0.1 0.1 0.1') addPortal('federated',center, {title=fediurl}, fediurl,i, 4, thumb, '0 180 0', '0.1 0.1 0.1')
end end
end} end}

View file

@ -10,16 +10,29 @@ end)
app.on('set', function(k,v) app.on('set', function(k,v)
end) end)
app.on('init', function()
for i=1,5 do
local repourl = app.opts['plugin_git_repo_' .. i]
if repourl and #repourl > 0 then
local repodir = repourl:gsub(".*/","")
local destdir = app.opts.plugin_diskscan_dir .. '/' .. repodir
if not util.fileExist( destdir ) then
local retcode = os.execute("git clone --depth=1 " .. repourl:gsub(" ", "_") .. " " .. destdir )
end
end
end
end)
-- this registers the plugin UI -- this registers the plugin UI
local plugin = { local plugin = {
name = 'Git <b class="tag">disabled</b>', name = 'Git',
info = '', info = '',
opts = { opts = {
{ {
key='app.opts.plugin_git_repo_1', key='app.opts.plugin_git_repo_1',
title='Git repo 1 URL', title='Git repo 1 URL',
info='git repository to scan experiences', info='git repository to scan experiences',
default="https://codeberg.org/myuser/reponame", default="",
values='' values=''
}, },
{ {
@ -35,6 +48,20 @@ local plugin = {
info='git repository to scan experiences', info='git repository to scan experiences',
default="", default="",
values='' values=''
},
{
key='app.opts.plugin_git_repo_4',
title='Git repo 4 URL',
info='git repository to scan experiences',
default="",
values=''
},
{
key='app.opts.plugin_git_repo_5',
title='Git repo 5 URL',
info='git repository to scan experiences',
default="",
values=''
} }
} }
} }

View file

@ -41,7 +41,7 @@ local plugin = {
key='app.opts.plugin_global_homepage', key='app.opts.plugin_global_homepage',
title='Homepage', title='Homepage',
info='Display 3D or 2D experiences on homepage', info='Display 3D or 2D experiences on homepage',
default = "3D", default = "2D",
values={ ['3D'] = '3D', ['2D'] = '2D' }, values={ ['3D'] = '3D', ['2D'] = '2D' },
}, },
{ {

View file

@ -21,7 +21,7 @@ end)
-- this registers the plugin UI -- this registers the plugin UI
local plugin = { local plugin = {
name = 'Markdown <b class="tag">disabled</b>', name = 'Markdown',
info = 'extract experience title and description from markdown file', info = 'extract experience title and description from markdown file',
opts = { opts = {
{ {

View file

@ -0,0 +1,83 @@
local util = require('util')
app.on('scan_experience', function(exp) end)
app.on('scan_experience_file', function(exp) end)
app.on('set', function(k,v)
end)
app.on('init', function()
local outdir = 'www'
local url = {"/"}
if util.contains(argv, 'generate') then
if util.fileExist(outdir) then
print("[!] folder 'www' was already detected..please delete it")
os.exit()
end
local selfbinary = '../' .. argv[-1]
os.execute("mkdir www")
os.execute("cp -Lr " .. app.opts.plugin_diskscan_dir .. " " .. outdir .. "/.")
os.execute("cd " .. outdir .. " && unzip " .. selfbinary .. " 'img/*' 'css/*' 'janusweb/*' 'shader/*'")
foreach( app.cache.items, function(k,v)
if v.dir then
table.insert(url, v.url )
end
end)
foreach( url, function(k,url)
url = url:gsub("//","/")
util.fetchServer( url, nil, function(req,res,next)
print( outdir .. url .. '/index.html')
util.writefile( outdir .. url .. '/index.html', res.body )
end)
end)
end
--print("files generated in 'www' folder")
--os.exit()
end)
-- this registers the plugin UI
local plugin = {
name = 'Static webgenerator',
hide = true,
info = '',
opts = {
{
key='app.opts.plugin_git_repo_1',
title='Git repo 1 URL',
info='git repository to scan experiences',
default="",
values=''
},
{
key='app.opts.plugin_git_repo_2',
title='Git repo 2 URL',
info='git repository to scan experiences',
default="",
values=''
},
{
key='app.opts.plugin_git_repo_3',
title='Git repo 3 URL',
info='git repository to scan experiences',
default="",
values=''
},
{
key='app.opts.plugin_git_repo_4',
title='Git repo 4 URL',
info='git repository to scan experiences',
default="",
values=''
},
{
key='app.opts.plugin_git_repo_5',
title='Git repo 5 URL',
info='git repository to scan experiences',
default="",
values=''
}
}
}
return plugin

View file

@ -14,7 +14,7 @@ lust.queueServerRequest = function(method, path, params, host, headers, body, sc
end end
require('test/plugin_global')(lust) require('test/plugin_global')(lust)
os.exit() require('test/plugin_git')(lust)
require('test/plugin_diskscan')(lust) require('test/plugin_diskscan')(lust)
require('test/plugin_xrfragment')(lust) require('test/plugin_xrfragment')(lust)

22
src/test/plugin_git.lua Normal file
View file

@ -0,0 +1,22 @@
return function(lust)
local describe, it, expect = lust.describe, lust.it, lust.expect
describe('src/plugin/git.lua', function()
describe('clone repo', function() -- Can be nested
app.opts.plugin_git_repo_1 = 'https://codeberg.org/coderofsalvation/xrfragment'
it('opts.plugin_git_repo_1 (clone repo)', function()
app.init()
local destdir = app.opts.plugin_diskscan_dir .. '/' .. 'xrfragment'
expect( util.fileExist( destdir ) ).to.be.truthy()
end)
end)
end)
end