Skip to repository content71 lines · 1.9 KB · javascript
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T03:28:26.556Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
worker.js
1export default {
2 async fetch(request, _env, _ctx) {
3 const url = new URL(request.url);
4 const acceptHeader = request.headers.get("Accept") || "";
5 const wantsMarkdown = acceptHeader
6 .split(",")
7 .map((mediaType) => mediaType.split(";")[0].trim().toLowerCase())
8 .includes("text/markdown");
9
10 if (url.pathname === "/docs/nightly") {
11 url.hostname = "docs-nightly.pages.dev";
12 url.pathname = "/docs/";
13 } else if (url.pathname.startsWith("/docs/nightly/")) {
14 url.hostname = "docs-nightly.pages.dev";
15 url.pathname = url.pathname.replace("/docs/nightly/", "/docs/");
16 } else if (url.pathname === "/docs/preview") {
17 url.hostname = "docs-preview-5xd.pages.dev";
18 url.pathname = "/docs/";
19 } else if (url.pathname.startsWith("/docs/preview/")) {
20 url.hostname = "docs-preview-5xd.pages.dev";
21 url.pathname = url.pathname.replace("/docs/preview/", "/docs/");
22 } else {
23 url.hostname = "docs-anw.pages.dev";
24 }
25
26 if (url.pathname === "/docs.md") {
27 url.pathname = "/docs/getting-started.md";
28 }
29
30 if (wantsMarkdown) {
31 url.pathname = markdownPathFor(url.pathname);
32 }
33
34 let res = await fetch(url, request);
35
36 if (res.status === 404) {
37 res = await fetch("https://zed.dev/404");
38 }
39
40 return res;
41 },
42};
43
44function markdownPathFor(pathname) {
45 if (pathname === "/docs" || pathname === "/docs/") {
46 return "/docs/getting-started.md";
47 }
48
49 if (pathname.endsWith("/index.md")) {
50 return pathname.replace(/\/index\.md$/, "/getting-started.md");
51 }
52
53 if (pathname.endsWith(".md")) {
54 return pathname;
55 }
56
57 if (pathname.endsWith(".html")) {
58 return pathname.replace(/\.html$/, ".md");
59 }
60
61 if (pathname.split("/").pop().includes(".")) {
62 return pathname;
63 }
64
65 if (pathname.endsWith("/")) {
66 return `${pathname}getting-started.md`;
67 }
68
69 return `${pathname}.md`;
70}
71