|
| 1 | +/** |
| 2 | + * The API's own webpage — served from the deployed worker at `/` (to |
| 3 | + * browsers, via content negotiation) and at `/docs` (always). Deployed |
| 4 | + * content belongs to the api.interscript.org deployment, not the main |
| 5 | + * website. Self-contained HTML: no external assets, system font stack. |
| 6 | + */ |
| 7 | + |
| 8 | +const ENDPOINTS: { method: string; path: string; note: string }[] = [ |
| 9 | + { method: "GET", path: "/v1/info", note: "version + capability summary" }, |
| 10 | + { method: "GET", path: "/v1/maps", note: "every transliteration system code" }, |
| 11 | + { method: "GET", path: "/v1/maps/{code}", note: "one system's compiled map (JSON IR)" }, |
| 12 | + { method: "POST", path: "/v1/transliterate", note: "{system, input} → {output}" }, |
| 13 | + { method: "POST", path: "/v1/detect", note: "{input, output} → ranked systems" }, |
| 14 | + { method: "GET", path: "/v1/models", note: "neural model index (IMF v1)" }, |
| 15 | + { method: "GET", path: "/v1/models/{id}", note: "one model's metadata" }, |
| 16 | + { method: "POST", path: "/v1/infer", note: "{model, input} → {output}" }, |
| 17 | + { method: "POST", path: "/graphql", note: "GraphQL endpoint (introspection enabled)" }, |
| 18 | + { method: "GET", path: "/openapi.json", note: "OpenAPI 3.1 document" }, |
| 19 | +] |
| 20 | + |
| 21 | +function esc(s: string): string { |
| 22 | + return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") |
| 23 | +} |
| 24 | + |
| 25 | +export function docsPage(openapiPath: string): string { |
| 26 | + const rows = ENDPOINTS.map( |
| 27 | + (e) => |
| 28 | + `<tr><td><span class="m">${esc(e.method)}</span></td><td><code>${esc(e.path)}</code></td><td>${esc(e.note)}</td></tr>`, |
| 29 | + ).join("\n") |
| 30 | + return `<!doctype html> |
| 31 | +<html lang="en"> |
| 32 | +<head> |
| 33 | +<meta charset="utf-8"> |
| 34 | +<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 35 | +<title>Interscript API</title> |
| 36 | +<style> |
| 37 | + :root { color-scheme: light dark; } |
| 38 | + * { box-sizing: border-box; } |
| 39 | + body { |
| 40 | + margin: 0; padding: 2.5rem 1.25rem 4rem; |
| 41 | + font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; |
| 42 | + background: #f6f3ec; color: #1a1d1f; |
| 43 | + } |
| 44 | + @media (prefers-color-scheme: dark) { body { background: #14171a; color: #eceae4; } } |
| 45 | + main { max-width: 44rem; margin: 0 auto; } |
| 46 | + h1 { font-size: 1.9rem; line-height: 1.15; margin: 0 0 .35rem; } |
| 47 | + .tagline { margin: 0 0 2rem; color: #5c6470; } |
| 48 | + .brand { color: #008075; } |
| 49 | + table { border-collapse: collapse; width: 100%; margin: 1rem 0 2rem; font-size: .95rem; } |
| 50 | + th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid rgba(128,128,128,.25); vertical-align: top; } |
| 51 | + th { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: #5c6470; } |
| 52 | + code { font: .9em ui-monospace, "SF Mono", Menlo, Consolas, monospace; } |
| 53 | + .m { font-weight: 700; font-size: .78rem; letter-spacing: .05em; color: #008075; } |
| 54 | + .links a { margin-right: 1.4rem; } |
| 55 | + a { color: #008075; } |
| 56 | + section { margin-top: 2.5rem; } |
| 57 | + pre { background: rgba(128,128,128,.12); padding: 1rem; border-radius: 6px; overflow-x: auto; } |
| 58 | +</style> |
| 59 | +</head> |
| 60 | +<body> |
| 61 | +<main> |
| 62 | + <h1><span class="brand">Interscript</span> API</h1> |
| 63 | + <p class="tagline">Authority-backed transliteration for every script — REST v1 + GraphQL on the edge.</p> |
| 64 | +
|
| 65 | + <table> |
| 66 | + <thead><tr><th>Method</th><th>Endpoint</th><th>Behavior</th></tr></thead> |
| 67 | + <tbody> |
| 68 | +${rows} |
| 69 | + </tbody> |
| 70 | + </table> |
| 71 | +
|
| 72 | + <section> |
| 73 | + <h2>Quick start</h2> |
| 74 | + <pre><code>curl -X POST https://api.interscript.org/v1/transliterate \\ |
| 75 | + -H 'Content-Type: application/json' \\ |
| 76 | + -d '{"system":"alalc-ara-Arab-Latn-1997","input":"السلام عليكم"}'</code></pre> |
| 77 | + </section> |
| 78 | +
|
| 79 | + <section> |
| 80 | + <h2>Machine-readable</h2> |
| 81 | + <p class="links"> |
| 82 | + <a href="${esc(openapiPath)}">OpenAPI 3.1</a> |
| 83 | + <a href="/v1/models">Model index</a> |
| 84 | + <a href="/v1/maps">System codes</a> |
| 85 | + <a href="https://www.interscript.org">Interscript project</a> |
| 86 | + <a href="https://github.com/interscript/api">Source (BSD-2-Clause)</a> |
| 87 | + </p> |
| 88 | + </section> |
| 89 | +</main> |
| 90 | +</body> |
| 91 | +</html> |
| 92 | +` |
| 93 | +} |
0 commit comments