bugfix: static site generator

This commit is contained in:
Leon van Kammen 2026-10-15 18:50:08 +02:00
parent dde10e9de2
commit 7dfb0bd2a7
9 changed files with 44 additions and 16 deletions

View file

@ -84,16 +84,17 @@ You can override the default content (embedded in the executable).
Extract and run example 3D content in your browser: Extract and run example 3D content in your browser:
```bash ```bash
$ unzip xrforge.com myverse/* # extract example 3D verse files
$ ./xrforge.com server # run as server $ ./xrforge.com server # run as server
ℹ️ unzipping example content to folder 'myverse'
opening your browser at https://localhost:8080 opening your browser at https://localhost:8080
``` ```
> just look around in `myverse` and get a hunch of how directories + sidecarfiles are used to manage content. > Play around in the browser, and launch a file-explorer with directory `myverse`, and see how directories, sidecarfiles and symlinks are used to manage interconnected virtual worlds.
</div> </div>
<div class="p" id="radical"> <div class="p" id="radical">
## Radical opensource ## Radical opensource
``` ```
@ -116,11 +117,12 @@ Archive: result/bin/xrforge.com
## Adding content ## Adding content
First you need a directory with glTF or JanusXR experiences.<br> First you need a directory with glTF or (JanusXR) JML experiences.<br>
Just run this in the terminal: Luckily, running the server (`./xrforge.com server`) once will produce example-folder `myverse`.<br>
Then run this in the terminal:
```bash ```bash
$ unzip xrforge.com myverse $ unzip xrforge.com myverse/* # optional: unzip example-content manually
$ tree myverse $ tree myverse
myverse myverse
├── janusxr ├── janusxr
@ -138,7 +140,7 @@ myverse
└── tronverse.png └── tronverse.png
``` ```
> optionally you can run `./xrforge.com admin` and change the `myverse` directory if needed. > optionally you can run `./xrforge.com admin` and change default directoryname (`myverse`) if needed.
</div> </div>
<div class="addcontent"> <div class="addcontent">

View file

@ -13,7 +13,7 @@ end
util.readfile = function(filename, mode, silent) util.readfile = function(filename, mode, silent)
local file, err = io.open(filename, mode or "r") local file, err = io.open(filename, mode or "r")
if not file then if not file then
if not silent then print("Error opening file:", err) end if not silent then print("Error opening file:", filename, err) end
return return
end end
local content = file:read("*a") local content = file:read("*a")
@ -24,7 +24,7 @@ end
util.writefile = function(filename, content, mode) util.writefile = function(filename, content, mode)
local file, err = io.open(filename, mode or "w") -- Default write mode local file, err = io.open(filename, mode or "w") -- Default write mode
if not file then if not file then
return print("Error opening file:", err) return print("Error opening file:", filename, err)
end end
file:write(content) file:write(content)
file:close() file:close()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 125 KiB

View file

@ -1 +0,0 @@
../tronverse.png

View file

@ -1 +0,0 @@
../janusxr

View file

@ -59,10 +59,19 @@ end}
{if items then {if items then
function getURL(url, item) function getURL(url, item)
if app.arg[1] == 'generate' or url:match("://") then item = item or {}
url = '?view=3D#janus.url=' .. EscapeFragment( url ) local playable = item.view3D
or (item.janusxr and item.janusxr.room)
or (item.redirect)
if app.arg[1] == 'generate' then
if playable or url:match("://") then
url = 'janusweb/#janus.url=' .. EscapeFragment( url )
end
url = util.baseURLify(url) url = util.baseURLify(url)
else else
if url:match("://") then
url = '?view=3D#janus.url=' .. EscapeFragment( url )
end
url = util.stripPath( url ) url = util.stripPath( url )
end end
return url return url

View file

@ -12,8 +12,13 @@ app.on('init', function()
end end
else else
if not util.fileExist(app.opts.plugin_diskscan_dir) then if not util.fileExist(app.opts.plugin_diskscan_dir) then
print("ℹ️ serving " .. app.opts.plugin_diskscan_dir .. " from internal (executable)") if app.opts.plugin_diskscan_dirname == 'myverse' and util.cmdExist("unzip") then
app.opts.plugin_diskscan_dir = '/zip/' .. util.stripPath(app.opts.plugin_diskscan_dir) print("ℹ️ unzipping example content to folder 'myverse'")
os.execute("unzip " .. argv[-1] .. ' "myverse/*"')
else
print("ℹ️ serving " .. app.opts.plugin_diskscan_dir .. " from internal (executable)")
app.opts.plugin_diskscan_dir = '/zip/' .. util.stripPath(app.opts.plugin_diskscan_dir)
end
app.set('app.opts', app.opts) app.set('app.opts', app.opts)
end end
end end

View file

@ -71,10 +71,13 @@ local plugin = {
print("[!] folder 'www' was already detected..please delete it") print("[!] folder 'www' was already detected..please delete it")
os.exit() os.exit()
end end
local selfbinary = '../' .. argv[-1] local selfbinary = argv[-1]
os.execute("mkdir www www/about") os.execute("mkdir www www/about")
print("cp -Lr " .. app.opts.plugin_diskscan_dir .. " " .. outdir .. "/.")
os.execute("cp -Lr " .. app.opts.plugin_diskscan_dir .. " " .. outdir .. "/.") os.execute("cp -Lr " .. app.opts.plugin_diskscan_dir .. " " .. outdir .. "/.")
print("cd " .. outdir .. " && unzip " .. selfbinary .. " 'img/*' 'css/*' 'janusweb/*' 'shader/*'")
os.execute("cd " .. outdir .. " && unzip " .. selfbinary .. " 'img/*' 'css/*' 'janusweb/*' 'shader/*'") os.execute("cd " .. outdir .. " && unzip " .. selfbinary .. " 'img/*' 'css/*' 'janusweb/*' 'shader/*'")
foreach( app.cache.items, function(k,v) foreach( app.cache.items, function(k,v)
if v.dir then if v.dir then
table.insert(urls, v.url .. ".rss" ) table.insert(urls, v.url .. ".rss" )
@ -90,7 +93,18 @@ local plugin = {
app.on('response', function(opts) app.on('response', function(opts)
local body = opts.res._body -- capture the output local body = opts.res._body -- capture the output
local url = opts.req.url:gsub("//","/") local url = opts.req.url:gsub("//","/")
util.writefile( outdir .. url .. '/index.html', body ) local dir = url:gsub("/$","")
local isfile = url:match("%.[a-zA-Z0-9]+$")
if isfile then
dir = url:gsub("/[^/]+$", "")
end
print("mkdir -p " .. outdir .. dir )
os.execute("mkdir -p " .. outdir .. dir)
if isfile then
util.writefile( outdir .. url, body )
else
util.writefile( outdir .. url .. '/index.html', body )
end
end) end)
foreach( urls, function(k,url) foreach( urls, function(k,url)