nx_wiki_search_render.nx source
↩ module page · 96 lines · 3925 B
1// nx_wiki_search_render.nx -- WIKI-SPECIFIC THIN ADAPTER.
2// All actual render logic lives in hub/nx_search_render_html.nx
3// (HUB primitive; site-agnostic; reusable across wiki, obd-config,
4// sprinkler-config, future Nishi-hosted third-party sites).
5//
6// This file ONLY:
7// 1. Builds the wiki-themed NxSearchRenderTheme constant
8// 2. Adapts NxWikiDocCtx -> raw byte writer for hub render
9// 3. Delegates to nx_search_render_html
10//
11// Per operator cardinal 2026-05-27: "make sure you make the onsite and
12// offsite search reusable and not just tied to the wiki but with
13// capabilities to be used on other sites" -- enforced structurally by
14// moving render logic to hub/, keeping per-site files THIN.
15//
16// COMPOSES:
17// hub/nx_search_render_html (all logic; this file is glue)
18// wiki/nx_wiki_doc_render (NxWikiDocCtx writer cursor)
19//
20// COMPOSED BY:
21// wiki/nx_wiki_search_wiring (next commit)
22
23import "nx_syscalls.nx"
24import "hub/nx_search_render_html.nx"
25import "wiki/nx_wiki_doc_render.nx"
26import "nx_search_query_parser.nx"
27import "nx_search_onsite_engine.nx"
28
29// ===== Wiki theme literals =================================================
30
31const NX_WIKI_THEME_CONTAINER: *u8 = "wiki-search-results" as *u8
32const NX_WIKI_THEME_CONTAINER_N: i64 = 19
33const NX_WIKI_THEME_BANNER: *u8 = "wiki-search-banner" as *u8
34const NX_WIKI_THEME_BANNER_N: i64 = 18
35const NX_WIKI_THEME_RESULT: *u8 = "wiki-search-result" as *u8
36const NX_WIKI_THEME_RESULT_N: i64 = 18
37const NX_WIKI_THEME_META: *u8 = "wiki-search-meta" as *u8
38const NX_WIKI_THEME_META_N: i64 = 16
39const NX_WIKI_THEME_SNIPPET: *u8 = "wiki-search-snippet" as *u8
40const NX_WIKI_THEME_SNIPPET_N: i64 = 19
41const NX_WIKI_THEME_EMPTY: *u8 = "wiki-search-empty" as *u8
42const NX_WIKI_THEME_EMPTY_N: i64 = 17
43
44// Sealed verdict surface: reuses hub/nx_search_render_html's
45// NX_SRH_* codes; this file emits 2000-2001 for the adapter-specific
46// errors.
47const NX_WSR_OK: i64 = 0
48const NX_WSR_BAD_INPUT: i64 = 2000
49const NX_WSR_CTX_INVALID: i64 = 2001
50
51// ===== Sealed wiki theme constructor =================================================
52//
53// Caller pre-allocates an NxSearchRenderTheme; this function stamps
54// every field with the wiki literals. Idempotent.
55
56func nx_wiki_search_theme_init(t: *NxSearchRenderTheme) -> i64 {
57 return nx_srh_theme_init(t,
58 NX_WIKI_THEME_CONTAINER, NX_WIKI_THEME_CONTAINER_N,
59 NX_WIKI_THEME_BANNER, NX_WIKI_THEME_BANNER_N,
60 NX_WIKI_THEME_RESULT, NX_WIKI_THEME_RESULT_N,
61 NX_WIKI_THEME_META, NX_WIKI_THEME_META_N,
62 NX_WIKI_THEME_SNIPPET, NX_WIKI_THEME_SNIPPET_N,
63 NX_WIKI_THEME_EMPTY, NX_WIKI_THEME_EMPTY_N)
64}
65
66// ===== Adapter: NxWikiDocCtx -> hub render =================================================
67//
68// NxWikiDocCtx exposes its internal byte cursor; we hand it to the
69// hub render, then write back the advanced cursor.
70
71func nx_wiki_search_render(ctx: *NxWikiDocCtx,
72 q: *NxSearchQuery,
73 r: *NxSearchResults,
74 inp: *NxSearchRenderInputs) -> i64 {
75 if (ctx as i64) == 0 { return 0 - NX_WSR_CTX_INVALID }
76 if q.valid != 1 { return 0 - NX_WSR_BAD_INPUT }
77
78 // Build wiki theme on the fly (caller doesn't have to know about it).
79 let t: *NxSearchRenderTheme = (sys_mmap(128)) as *NxSearchRenderTheme
80 let rc_theme: i64 = nx_wiki_search_theme_init(t)
81 if rc_theme != NX_SRH_OK { return rc_theme }
82
83 // Pull byte cursor from NxWikiDocCtx (out_buf/out_cap/out_off).
84 let out: *u8 = ctx.out_buf
85 let cap: i64 = ctx.out_cap
86 let off: i64 = ctx.out_off
87 let out_off_p: *i64 = (sys_mmap(8)) as *i64
88 out_off_p[0] = off
89
90 let rc: i64 = nx_search_render_html(out, cap, off, q, r, inp, t, out_off_p)
91 if rc != NX_SRH_OK { return rc }
92
93 // Advance NxWikiDocCtx cursor by what hub render wrote.
94 ctx.out_off = out_off_p[0]
95 return NX_WSR_OK
96}