code wiki / _hdl_build / nx_site_import.nx

nx_site_import.nx source

↩ module page · 86 lines · 4513 B

1// nx_site_import.nx -- the MIGRATION IMPORTER: the no-lock-in CAPABILITY (not architecture). Ingest a foreign site's 2// HTML (e.g., a Wix/Webflow/any export) and produce our PORTABLE, SOVEREIGN blueprint: title + structure counts + 3// stripped visible content, with all third-party JS/tracking REMOVED. Lock-in platforms can't import a competitor's 4// site; we can -- so "no-lock-in" becomes a thing you can DO (migrate TO us from anywhere), measurably better-at-job. 5// 100% sovereign string processing. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7const K_MAGIC_65536: i64 = 65536 8 9func mi_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 10func mi_match_at(h: *u8, i: i64, n: i64, lit: *u8) -> i64 { 11 let ll: i64 = mi_strlen(lit) 12 if i + ll > n { return 0 } 13 var j: i64 = 0 14 while j < ll { if h[i+j] != lit[j] { return 0 } j = j + 1 } 15 return 1 16} 17func mi_find_from(h: *u8, start: i64, n: i64, lit: *u8) -> i64 { 18 let ll: i64 = mi_strlen(lit) 19 if ll == 0 { return 0 - 1 } 20 var i: i64 = start 21 while i + ll <= n { if mi_match_at(h, i, n, lit) == 1 { return i } i = i + 1 } 22 return 0 - 1 23} 24func mi_count(h: *u8, n: i64, lit: *u8) -> i64 { 25 let ll: i64 = mi_strlen(lit) 26 if ll == 0 { return 0 } 27 var c: i64 = 0; var i: i64 = 0 28 while i + ll <= n { if mi_match_at(h, i, n, lit) == 1 { c = c + 1; i = i + ll } else { i = i + 1 } } 29 return c 30} 31// extract visible text: skip <script>/<style> bodies entirely, drop all tags, collapse whitespace. 32func mi_strip_tags(h: *u8, n: i64, out: *u8, cap: i64) -> i64 { 33 var i: i64 = 0; var o: i64 = 0; var in_tag: i64 = 0; var last_space: i64 = 1 34 while i < n { 35 let c: u8 = h[i] 36 if c == (60 as u8) { // '<' 37 if mi_match_at(h, i, n, "<script" as *u8) == 1 { let e: i64 = mi_find_from(h, i, n, "</script>" as *u8); if e < 0 { return o } i = e + 9; in_tag = 0; continue } 38 if mi_match_at(h, i, n, "<style" as *u8) == 1 { let e: i64 = mi_find_from(h, i, n, "</style>" as *u8); if e < 0 { return o } i = e + 8; in_tag = 0; continue } 39 in_tag = 1; i = i + 1; continue 40 } 41 if c == (62 as u8) { // '>' 42 in_tag = 0; i = i + 1 43 if last_space == 0 { if o < cap { out[o] = 32 as u8; o = o + 1 } last_space = 1 } 44 continue 45 } 46 if in_tag == 0 { 47 var sp: i64 = 0 48 if c == (32 as u8) { sp = 1 } 49 if c == (10 as u8) { sp = 1 } 50 if c == (9 as u8) { sp = 1 } 51 if c == (13 as u8) { sp = 1 } 52 if sp == 1 { if last_space == 0 { if o < cap { out[o] = 32 as u8; o = o + 1 } last_space = 1 } } 53 else { if o < cap { out[o] = c; o = o + 1 } last_space = 0 } 54 } 55 i = i + 1 56 } 57 return o 58} 59func mi_extract_between(h: *u8, n: i64, open: *u8, close: *u8, out: *u8, cap: i64) -> i64 { 60 let s0: i64 = mi_find_from(h, 0, n, open) 61 if s0 < 0 { return 0 } 62 let s: i64 = s0 + mi_strlen(open) 63 let e: i64 = mi_find_from(h, s, n, close) 64 if e < 0 { return 0 } 65 var o: i64 = 0; var i: i64 = s 66 while i < e { if o < cap { out[o] = h[i]; o = o + 1 } i = i + 1 } 67 return o 68} 69 70func mi_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 71func mi_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)} 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(fd,bb,k); return 0 } 72 73// emit our portable, sovereign blueprint from foreign HTML. 74func mi_to_blueprint(h: *u8, n: i64, fd: i64) -> i64 { 75 let buf: *u8 = sys_mmap(K_MAGIC_65536) 76 mi_w(fd, "site|title|" as *u8) 77 let tl: i64 = mi_extract_between(h, n, "<title>" as *u8, "</title>" as *u8, buf, K_MAGIC_65536) 78 sys_write(fd, buf, tl); mi_w(fd, "\n" as *u8) 79 mi_w(fd, "site|headings|" as *u8); mi_wn(fd, mi_count(h, n, "<h1" as *u8) + mi_count(h, n, "<h2" as *u8) + mi_count(h, n, "<h3" as *u8)); mi_w(fd, "\n" as *u8) 80 mi_w(fd, "site|paragraphs|" as *u8); mi_wn(fd, mi_count(h, n, "<p" as *u8)); mi_w(fd, "\n" as *u8) 81 mi_w(fd, "site|links|" as *u8); mi_wn(fd, mi_count(h, n, "<a " as *u8)); mi_w(fd, "\n" as *u8) 82 mi_w(fd, "block|content|" as *u8) 83 let cl: i64 = mi_strip_tags(h, n, buf, K_MAGIC_65536) 84 sys_write(fd, buf, cl); mi_w(fd, "\n" as *u8) 85 return 0 86}