Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sovereign-intelligence/blob/main/docs/archive/drakestapleton.com-old/scripts/spa-fallback.mjs # sovereign-intelligence Front door to Drake Stapleton's sovereign stack. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `sovereign-intelligence / docs / archive / drakestapleton.com-old / scripts / spa-fallback.mjs` 256 lines ยท 11448 bytes Raw Blame History 1 import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; 2 import { dirname, join } from "node:path"; 3 4 const mode = process.argv[2] || "portfolio"; 5 if (!new Set(["waitlist", "portfolio"]).has(mode)) { 6 throw new Error(`Unknown site mode: ${mode}`); 7 } 8 9 const dist = "dist"; 10 const indexPath = join(dist, "index.html"); 11 const indexHtml = readFileSync(indexPath, "utf8"); 12 const pageMetadata = JSON.parse(readFileSync(new URL("../site-metadata.json", import.meta.url), "utf8")); 13 const routes = [ 14 { rel: "atlas/index.html", path: "/atlas", ...pageMetadata["/atlas"] }, 15 { rel: "aegis/index.html", path: "/aegis", ...pageMetadata["/aegis"] }, 16 { rel: "aien/index.html", path: "/aien", ...pageMetadata["/aien"] }, 17 { rel: "research/index.html", path: "/research", ...pageMetadata["/research"] }, 18 { rel: "scholar/index.html", path: "/scholar", ...pageMetadata["/scholar"] }, 19 { rel: "scholar/omega/index.html", path: "/scholar/omega", ...pageMetadata["/scholar/omega"] }, 20 { rel: "what-i-learned/index.html", path: "/what-i-learned", ...pageMetadata["/what-i-learned"] }, 21 { rel: "what-broke/index.html", path: "/what-i-learned", ...pageMetadata["/what-i-learned"], redirect: true }, 22 { rel: "path/index.html", path: "/path", ...pageMetadata["/path"] }, 23 { rel: "software/index.html", path: "/software", ...pageMetadata["/software"] }, 24 { rel: "evidence/index.html", path: "/evidence", ...pageMetadata["/evidence"] }, 25 { rel: "interest/index.html", path: "/interest", ...pageMetadata["/interest"] }, 26 { rel: "dad/index.html", path: "/dad", ...pageMetadata["/dad"] }, 27 { rel: "symphony/index.html", path: "/symphony", ...pageMetadata["/symphony"] }, 28 { rel: "symphony/first/index.html", path: "/symphony/first", ...pageMetadata["/symphony/first"] }, 29 { rel: "symphony/workflow/index.html", path: "/symphony/workflow", ...pageMetadata["/symphony/workflow"] }, 30 { rel: "symphony/map/index.html", path: "/symphony/map", ...pageMetadata["/symphony/map"] }, 31 { rel: "atlas-symphony/index.html", path: "/symphony", ...pageMetadata["/symphony"], redirect: true }, 32 { rel: "works/index.html", path: "/works", ...pageMetadata["/works"] }, 33 { rel: "works/atlas-symphony/index.html", path: "/works/atlas-symphony", ...pageMetadata["/works/atlas-symphony"] }, 34 { rel: "works/atlas-harness/index.html", path: "/works/atlas-harness", ...pageMetadata["/works/atlas-harness"] }, 35 { rel: "works/mobdev-panel-arena/index.html", path: "/works/mobdev-panel-arena", ...pageMetadata["/works/mobdev-panel-arena"] }, 36 { rel: "works/defiantmob/index.html", path: "/works/defiantmob", ...pageMetadata["/works/defiantmob"] }, 37 { rel: "works/beltbrain/index.html", path: "/works/beltbrain", ...pageMetadata["/works/beltbrain"] }, 38 { rel: "works/dhg-hive/index.html", path: "/works/dhg-hive", ...pageMetadata["/works/dhg-hive"] }, 39 { rel: "works/foundations-2025/index.html", path: "/works/foundations-2025", ...pageMetadata["/works/foundations-2025"] }, 40 { rel: "works/aien/index.html", path: "/works/aien", ...pageMetadata["/works/aien"] }, 41 { rel: "works/aegis/index.html", path: "/works/aegis", ...pageMetadata["/works/aegis"] }, 42 { rel: "works/research/index.html", path: "/works/research", ...pageMetadata["/works/research"] }, 43 ]; 44 45 function escapeAttribute(value) { 46 return value 47 .replaceAll("&", "&") 48 .replaceAll('"', """) 49 .replaceAll("<", "<") 50 .replaceAll(">", ">"); 51 } 52 53 function escapeText(value) { 54 return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); 55 } 56 57 function noscriptSummary(page) { 58 const links = [ 59 ["/", "Home"], 60 ["/path", "Path"], 61 ["/software", "Software"], 62 ["/works", "Works"], 63 ["/evidence", "Evidence"], 64 ["/atlas", "Atlas"], 65 ["/interest", "Conversation"], 66 ["/aegis", "AEGIS"], 67 ["/aien", "AIEN"], 68 ["/research", "Research"], 69 ["/symphony", "Symphony"], 70 ]; 71 const nav = links.map(([href, label]) => `${label}`).join(" "); 72 return ``; 73 } 74 75 function structuredData(page) { 76 const canonical = `https://www.drakestapleton.com${page.path}`; 77 const person = { 78 "@type": "Person", 79 "@id": "https://www.drakestapleton.com/#person", 80 name: "Drake Stapleton", 81 jobTitle: "AI Architect & Operator", 82 description: "Freedom Fighter, AI Architect & Operator documenting projects, research, and the life behind the work.", 83 url: "https://www.drakestapleton.com/", 84 image: "https://www.drakestapleton.com/og.png?v=`20260820`", 85 sameAs: ["https://github.com/dhgmonkey"], 86 alumniOf: { 87 "@type": "CollegeOrUniversity", 88 name: "Western Kentucky University", 89 url: "https://www.wku.edu/", 90 }, 91 subjectOf: [ 92 { 93 "@type": "Thesis", 94 name: "Master of Science in Chemistry thesis", 95 datePublished: "2018", 96 url: "https://digitalcommons.wku.edu/theses/2101/", 97 }, 98 { 99 "@type": "ScholarlyArticle", 100 name: "2019 peer-reviewed nanomaterials paper", 101 datePublished: "2019", 102 url: "https://pubmed.ncbi.nlm.nih.gov/`30931213`/", 103 }, 104 ], 105 }; 106 107 const graph = page.path === "/" 108 ? [ 109 { 110 "@type": "WebSite", 111 "@id": "https://www.drakestapleton.com/#website", 112 name: "Drake Stapleton", 113 url: "https://www.drakestapleton.com/", 114 }, 115 person, 116 { 117 "@type": "FAQPage", 118 "@id": "https://www.drakestapleton.com/#faq", 119 mainEntity: [ 120 { 121 "@type": "Question", 122 name: "Why did Drake Stapleton build this site?", 123 acceptedAnswer: { 124 "@type": "Answer", 125 text: "This site documents Drake Stapleton's projects, the work behind them, and the life that shaped them.", 126 }, 127 }, 128 { 129 "@type": "Question", 130 name: "What work does Drake Stapleton do?", 131 acceptedAnswer: { 132 "@type": "Answer", 133 text: "I design, operate, and audit production orchestration, GPU systems, and verifiable AI architecture.", 134 }, 135 }, 136 { 137 "@type": "Question", 138 name: "What is Atlas?", 139 acceptedAnswer: { 140 "@type": "Answer", 141 text: "Atlas is Drake Stapleton's personal R&D program in accountable AI architecture, continuity, model training, and orchestration.", 142 }, 143 }, 144 ], 145 }, 146 ] 147 : [ 148 { 149 "@type": "WebPage", 150 "@id": `${canonical}#webpage`, 151 name: page.title, 152 description: page.description, 153 url: canonical, 154 isPartOf: { "@id": "https://www.drakestapleton.com/#website" }, 155 about: { "@id": "https://www.drakestapleton.com/#person" }, 156 }, 157 person, 158 ]; 159 160 return JSON.stringify({ "@context": "https://schema.org", "@graph": graph }).replaceAll("<", "\\u003c"); 161 } 162 163 let ssrRender = null; 164 const ssrPath = join(process.cwd(), "dist-ssr/entry-server.js"); 165 if (existsSync(ssrPath)) { 166 try { 167 const ssrModule = await import(ssrPath); 168 ssrRender = ssrModule.render; 169 console.log("SSR pre-rendering active: pre-rendering full semantic HTML for all routes"); 170 } catch (err) { 171 console.warn("SSR module failed to load, using noscript fallback:", err.message); 172 } 173 } 174 175 function withMetadata(html, page) { 176 const title = escapeText(page.title); 177 const description = escapeAttribute(page.description); 178 const canonical = `https://www.drakestapleton.com${page.path}`; 179 const jsonLd = structuredData(page); 180 let renderedBody = ""; 181 let headPreloads = ""; 182 if (ssrRender && !page.redirect) { 183 try { 184 renderedBody = ssrRender(page.path); 185 renderedBody = renderedBody.replace(/]*\/?>/g, (match) => { 186 headPreloads += ` ${match}\n`; 187 return ""; 188 }); 189 } catch (e) { 190 console.warn(`SSR render failed for ${page.path}:`, e.message); 191 renderedBody = noscriptSummary(page); 192 } 193 } else { 194 renderedBody = noscriptSummary(page); 195 } 196 return html 197 .replace(/