added 'janus optimize'
This commit is contained in:
parent
861de3c576
commit
e1f1e91483
2 changed files with 48 additions and 9 deletions
26
README.md
26
README.md
|
|
@ -7,15 +7,16 @@ Portable swiss-army knife to automate [janusXR](https://janusxr.org) / JML thing
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
Usage: ./janusxr --health <room_url> [--max-time-per-asset 5]
|
Usage: ./janusxr health <room_url> [--max-time-per-asset 5]
|
||||||
./janusxr --scrape <room_url> <outdir>
|
./janusxr scrape <room_url> <outdir>
|
||||||
|
./janusxr optimize <room_url>
|
||||||
```
|
```
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
> scan a room URL for broken links in JML+HTML
|
> scan a room URL for broken links in JML+HTML
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ ./janusxr --health http://localhost:8790/models/m5gr26w0wqqs
|
$ ./janusxr health http://localhost:8790/models/m5gr26w0wqqs
|
||||||
|
|
||||||
✅ http://localhost:8791/templates/xrfragment/%232/website.glb
|
✅ http://localhost:8791/templates/xrfragment/%232/website.glb
|
||||||
✅ http://localhost:8790/models/assets/offscreen_renderer-186b8c52.js
|
✅ http://localhost:8790/models/assets/offscreen_renderer-186b8c52.js
|
||||||
|
|
@ -36,7 +37,7 @@ $ ./janusxr --health http://localhost:8790/models/m5gr26w0wqqs
|
||||||
> scrape a room URL and rewrite JML to serve local assets (usecase: preservation/local-first/prototyping)
|
> scrape a room URL and rewrite JML to serve local assets (usecase: preservation/local-first/prototyping)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ ./janusxr --scrape https://www.janusxr.org/newlobby/index.html mydir
|
$ ./janusxr scrape https://www.janusxr.org/newlobby/index.html mydir
|
||||||
🔗 http://dizzket.com/archive/dotmatrix/
|
🔗 http://dizzket.com/archive/dotmatrix/
|
||||||
🔗 https://vesta.janusvr.com/nazrin/minecraft-sandbox
|
🔗 https://vesta.janusvr.com/nazrin/minecraft-sandbox
|
||||||
✅ http://www.janusvr.com/newlobby/scripts/home.txt
|
✅ http://www.janusvr.com/newlobby/scripts/home.txt
|
||||||
|
|
@ -48,6 +49,23 @@ home.txt
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> optimize a room by adding tags to your JML
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ ./janusxr optimize https://janusvr.com/newlobby/index.html
|
||||||
|
|
||||||
|
<!-- copy/paste below into your HTML/JML-file -->
|
||||||
|
|
||||||
|
<a href='http://www.janusvr.com/newlobby/scripts/home.txt'/>
|
||||||
|
<link rel='preload' href='http://www.janusvr.com'/>
|
||||||
|
<a href='http://www.janusvr.com/newlobby/images/skybox/dds/LobbyRadience.dds'/>
|
||||||
|
...
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
* `preconnect` speeds up loading remote resources (DNS lookup, TCP handshake, TLS negotiation)
|
||||||
|
* `<a href=".."> allows archive.org to fully capture the room (resources)
|
||||||
|
|
||||||
## Awk?
|
## Awk?
|
||||||
|
|
||||||
Why not some superfancy scripting for this task?
|
Why not some superfancy scripting for this task?
|
||||||
|
|
|
||||||
31
janusxr
31
janusxr
|
|
@ -1,8 +1,9 @@
|
||||||
#!/usr/bin/env -S awk -f
|
#!/usr/bin/env -S awk -f
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
print "Usage: ./janusxr --health <room_url> [--max-time-per-asset 5] \n" \
|
print "Usage: ./janusxr health <room_url> [--max-time-per-asset 5] \n" \
|
||||||
" ./janusxr --scrape <room_url> <outdir>\n"
|
" ./janusxr scrape <room_url> <outdir>\n" \
|
||||||
|
" ./janusxr optimize <room_url>\n"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -12,9 +13,12 @@ function usage() {
|
||||||
BEGIN {
|
BEGIN {
|
||||||
if (ARGC < 2) usage()
|
if (ARGC < 2) usage()
|
||||||
command = ARGV[1]
|
command = ARGV[1]
|
||||||
if (command == "--health" || command == "--scrape") {
|
if (command == "health" || command == "scrape" || command == "optimize" ) {
|
||||||
scrape(command)
|
scrape(command)
|
||||||
} else {
|
} else {
|
||||||
|
printf("1:"ARGV[0])
|
||||||
|
printf("1:"ARGV[1])
|
||||||
|
printf("2:"ARGV[2])
|
||||||
printf("Unknown command: %s\n", command)
|
printf("Unknown command: %s\n", command)
|
||||||
usage()
|
usage()
|
||||||
}
|
}
|
||||||
|
|
@ -47,7 +51,7 @@ function scrape( arg, tmpfile, line, attr, check, u) {
|
||||||
close(tmpfile)
|
close(tmpfile)
|
||||||
|
|
||||||
# Check each extracted links
|
# Check each extracted links
|
||||||
if( arg == "--health" ){
|
if( arg == "health" ){
|
||||||
maxtime = ARGV[3]
|
maxtime = ARGV[3]
|
||||||
if ( maxtime == "" ) maxtime = 5
|
if ( maxtime == "" ) maxtime = 5
|
||||||
nlinks = 0
|
nlinks = 0
|
||||||
|
|
@ -65,7 +69,7 @@ function scrape( arg, tmpfile, line, attr, check, u) {
|
||||||
if( nlinks != nlinksok ) exit(1)
|
if( nlinks != nlinksok ) exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if( arg == "--scrape" ) {
|
if( arg == "scrape" ) {
|
||||||
outdir = ARGV[3]
|
outdir = ARGV[3]
|
||||||
if ( outdir == "" ) outdir = "."
|
if ( outdir == "" ) outdir = "."
|
||||||
system("mkdir "outdir" || true ")
|
system("mkdir "outdir" || true ")
|
||||||
|
|
@ -86,6 +90,23 @@ function scrape( arg, tmpfile, line, attr, check, u) {
|
||||||
nlinks+=1
|
nlinks+=1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( arg == "optimize" ) {
|
||||||
|
printf("<!-- copy/paste below into your HTML/JML-file -->\n")
|
||||||
|
for (u in links) {
|
||||||
|
if( substr(u,1,1) == "/" ) u = rooturl""u
|
||||||
|
check = "curl -L --max-time 20 -I -s \"" u "\" > /dev/null"
|
||||||
|
if (system(check) == 0 && has_non_html_ext(u) ){
|
||||||
|
printf("<a href='"u"'/>\n")
|
||||||
|
split(u,urlpart,"/")
|
||||||
|
domain=urlpart[1]"//"urlpart[3]
|
||||||
|
if( !domains[domain] ){
|
||||||
|
printf("<link rel='preload' href='"domain"'/>\n")
|
||||||
|
domains[domain]=1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function: has_non_html_ext
|
# Function: has_non_html_ext
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue