code wiki / _hdl_build / nx_site_build_run.nx
nx_site_build_run.nx source
↩ module page · 56 lines · 3039 B
1// nx_site_build_run.nx -- RUNNABLE publish-build: read a .site blueprint path (from a config file) and an
2// output path, build the site through the SOVEREIGN engine (nx_sitegen_parse + nx_sitegen), and write the
3// HTML to the output path. This is the build half of the autonomous publish loop: a .site DATA file in ->
4// a built page out, no AI. The output is then streamed live by nx_aw_push. Config (persistent, survives WSL
5// /tmp wipes):
6// /mnt/c/Users/elder/AppData/Local/Temp/nx_pub_in = absolute path of the .site blueprint
7// /mnt/c/Users/elder/AppData/Local/Temp/nx_pub_out = absolute path to write the built HTML
8// license_tier: ORIGINAL
9import "nx_site_compose.nx"
10import "nx_syscalls.nx"
11
12const P_IN: *u8 = "/mnt/c/Users/elder/AppData/Local/Temp/nx_pub_in" as *u8
13const P_OUT: *u8 = "/mnt/c/Users/elder/AppData/Local/Temp/nx_pub_out" as *u8
14
15func pr_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
16func pr_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
17
18// read a config file, trim trailing whitespace/newline, null-terminate, return ptr (or 0 on failure)
19func rd_path(p: *u8) -> *u8 {
20 let box: *i64 = sys_mmap(16) as *i64
21 let s: *u8 = sys_read_file(p, box)
22 if (s as i64) == 0 { return 0 as *u8 }
23 var n: i64 = box[0]
24 while n > 0 {
25 let ch: i64 = s[n-1] as i64
26 if ch == 10 { n = n - 1 } else { if ch == 13 { n = n - 1 } else { if ch == 32 { n = n - 1 } else { break } } }
27 }
28 s[n] = 0 as u8
29 return s
30}
31
32func main() -> i64 {
33 let inp: *u8 = rd_path(P_IN)
34 if (inp as i64) == 0 { pr_puts("publish-build: no nx_pub_in\n" as *u8); return 1 }
35 let outp: *u8 = rd_path(P_OUT)
36 if (outp as i64) == 0 { pr_puts("publish-build: no nx_pub_out\n" as *u8); return 2 }
37
38 let tbox: *i64 = sys_mmap(16) as *i64
39 let text: *u8 = sys_read_file(inp, tbox)
40 if (text as i64) == 0 { pr_puts("publish-build: cannot read .site\n" as *u8); return 3 }
41 let tn: i64 = tbox[0]
42
43 let fd: i64 = sys_openat_wr(outp, 0x1a4)
44 if fd < 0 { pr_puts("publish-build: cannot open out\n" as *u8); return 4 }
45 // compose_build picks the page type from the .site `type|` line (legal default = backward-compatible, same
46 // sgp_parse+sg_build_page path as before); game template path is passed for type|game. Returns >=0 built,
47 // <0 refused (legal non-compliant) or template missing (game).
48 let grade: i64 = compose_build(text, tn, fd, "web_assets/_game_build/game_page.tpl.html" as *u8)
49 sys_close(fd)
50
51 pr_puts("PUBLISH-BUILD grade=" as *u8); pr_num(grade)
52 pr_puts(" -> " as *u8); pr_puts(outp); pr_puts("\n" as *u8)
53 if grade < 0 { pr_puts("publish-build: REFUSED / template missing -- nothing written\n" as *u8); return 5 }
54 pr_puts("publish-build: OK\n" as *u8)
55 return 0
56}