code wiki / _hdl_build / nx_site_migrate.nx
nx_site_migrate.nx source
↩ module page · 45 lines · 2028 B
1// nx_site_migrate.nx -- CLOSE the migration loop: foreign site -> import (nx_site_import) -> our blueprint -> REBUILD
2// through the branded builder. The rebuilt site is SOVEREIGN (0 JS), token-driven, and ACCESSIBLE by construction
3// (lang/title/viewport/landmarks/44px targets/focus-visible from wb_doc_open_branded + header/footer) -- so we don't
4// just migrate a lock-in site, we IMPROVE it. REUSE: nx_site_import (mi_find_from), nx_web_builder, nx_brand_tokens.
5// license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_site_import.nx"
8import "nx_web_builder.nx"
9import "nx_brand_tokens.nx"
10const K_MAGIC_4096: i64 = 4096
11const K_MAGIC_4095: i64 = 4095
12const K_MAGIC_262144: i64 = 262144
13const K_MAGIC_262143: i64 = 262143
14
15// read the value after `key` in the blueprint, up to newline.
16func mig_field(bp: *u8, n: i64, key: *u8, out: *u8, cap: i64) -> i64 {
17 let s0: i64 = mi_find_from(bp, 0, n, key)
18 if s0 < 0 { return 0 }
19 var i: i64 = s0 + mi_strlen(key)
20 var o: i64 = 0
21 while i < n {
22 if bp[i] == (10 as u8) { return o }
23 if o < cap { out[o] = bp[i]; o = o + 1 }
24 i = i + 1
25 }
26 return o
27}
28// rebuild the imported blueprint into a sovereign, accessible, token-driven page.
29func mig_rebuild(bp: *u8, n: i64, brand: *u8, blen: i64, fd: i64) -> i64 {
30 let title: *u8 = sys_mmap(K_MAGIC_4096)
31 let tl: i64 = mig_field(bp, n, "site|title|" as *u8, title, K_MAGIC_4095)
32 title[tl] = 0 as u8
33 let content: *u8 = sys_mmap(K_MAGIC_262144)
34 let cl: i64 = mig_field(bp, n, "block|content|" as *u8, content, K_MAGIC_262143)
35 wb_doc_open_branded(fd, title, brand, blen)
36 wb_header(fd, title, "Contact" as *u8, "#contact" as *u8)
37 wb_w(fd, "<main class=\"wrap\"><h1>" as *u8)
38 sys_write(fd, title, tl)
39 wb_w(fd, "</h1>\n<section><p>" as *u8)
40 sys_write(fd, content, cl)
41 wb_w(fd, "</p></section></main>\n" as *u8)
42 wb_w(fd, "<footer><div class=\"wrap\">Migrated sovereignly by Nishi</div></footer>\n" as *u8)
43 wb_doc_close(fd)
44 return 0
45}