@xyd-js/host 0.1.0-xyd.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/LICENSE +21 -0
- package/app/debug-null.tsx +3 -0
- package/app/docPaths.ts +65 -0
- package/app/entry.client.tsx +58 -0
- package/app/entry.server.tsx +68 -0
- package/app/pathRoutes.ts +61 -0
- package/app/public.ts +42 -0
- package/app/raw.ts +31 -0
- package/app/robots.ts +18 -0
- package/app/root.tsx +82 -0
- package/app/routes.ts +34 -0
- package/app/sitemap.ts +40 -0
- package/auto-imports.d.ts +10 -0
- package/package.json +32 -0
- package/plugins/README.md +1 -0
- package/postcss.config.cjs +5 -0
- package/react-router.config.ts +94 -0
- package/src/auto-imports.d.ts +29 -0
- package/tsconfig.json +28 -0
- package/types.d.ts +8 -0
- package/vite.config.ts +8 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @xyd-js/host
|
|
2
|
+
|
|
3
|
+
## 0.1.0-xyd.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- test
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @xyd-js/atlas@0.1.0-xyd.18
|
|
10
|
+
- @xyd-js/components@0.1.0-xyd.13
|
|
11
|
+
- @xyd-js/composer@0.1.0-xyd.2
|
|
12
|
+
- @xyd-js/core@0.1.0-xyd.15
|
|
13
|
+
- @xyd-js/framework@0.1.0-xyd.34
|
|
14
|
+
- @xyd-js/plugin-algolia@0.1.0-xyd.2
|
|
15
|
+
- @xyd-js/plugin-orama@0.1.0-xyd.2
|
|
16
|
+
- @xyd-js/theme-cosmo@0.1.0-xyd.2
|
|
17
|
+
- @xyd-js/theme-opener@0.1.0-xyd.2
|
|
18
|
+
- @xyd-js/theme-picasso@0.1.0-xyd.2
|
|
19
|
+
- @xyd-js/theme-poetry@0.1.0-xyd.29
|
|
20
|
+
- @xyd-js/themes@0.1.1-xyd.5
|
|
21
|
+
|
|
22
|
+
## 0.1.0-xyd.1
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- update packages
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
- @xyd-js/atlas@0.1.0-xyd.17
|
|
29
|
+
- @xyd-js/components@0.1.0-xyd.12
|
|
30
|
+
- @xyd-js/composer@0.1.0-xyd.1
|
|
31
|
+
- @xyd-js/core@0.1.0-xyd.14
|
|
32
|
+
- @xyd-js/framework@0.1.0-xyd.33
|
|
33
|
+
- @xyd-js/plugin-algolia@0.1.0-xyd.1
|
|
34
|
+
- @xyd-js/plugin-orama@0.1.0-xyd.1
|
|
35
|
+
- @xyd-js/theme-cosmo@0.1.0-xyd.1
|
|
36
|
+
- @xyd-js/theme-opener@0.1.0-xyd.1
|
|
37
|
+
- @xyd-js/theme-picasso@0.1.0-xyd.1
|
|
38
|
+
- @xyd-js/theme-poetry@0.1.0-xyd.28
|
|
39
|
+
- @xyd-js/themes@0.1.1-xyd.4
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 xyd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/app/docPaths.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {PageURL, Settings, Sidebar} from "@xyd-js/core";
|
|
2
|
+
|
|
3
|
+
export function docPaths(navigation: Settings['navigation']) {
|
|
4
|
+
if (!navigation?.sidebar) return [];
|
|
5
|
+
|
|
6
|
+
const paths: string[] = [];
|
|
7
|
+
|
|
8
|
+
// Process each sidebar group
|
|
9
|
+
navigation.sidebar.forEach(sidebarGroup => {
|
|
10
|
+
if (typeof sidebarGroup === "string") {
|
|
11
|
+
paths.push(sidebarGroup.startsWith("/") ? sidebarGroup : `/${sidebarGroup}`)
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Add the route of the sidebar group
|
|
16
|
+
if ('route' in sidebarGroup) {
|
|
17
|
+
const route = sidebarGroup.route;
|
|
18
|
+
if (route) {
|
|
19
|
+
paths.push(`/${route}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Process items in the sidebar group
|
|
24
|
+
if ("pages" in sidebarGroup && sidebarGroup.pages?.length) {
|
|
25
|
+
processSidebarItems(sidebarGroup.pages);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Helper function to process sidebar items recursively
|
|
30
|
+
function processSidebarItems(items: Sidebar[] | PageURL[]) {
|
|
31
|
+
items.forEach(item => {
|
|
32
|
+
if (typeof item === 'string') {
|
|
33
|
+
paths.push(`/${item}`);
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Add the route of the sidebar group
|
|
38
|
+
if ('route' in item) {
|
|
39
|
+
const route = item.route;
|
|
40
|
+
if (route) {
|
|
41
|
+
paths.push(`/${route}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// If item has pages, process them
|
|
46
|
+
if ("pages" in item && item.pages?.length) {
|
|
47
|
+
item.pages.forEach((page) => {
|
|
48
|
+
if (typeof page === 'string') {
|
|
49
|
+
// Add the page path
|
|
50
|
+
paths.push(`/${page}`);
|
|
51
|
+
} else {
|
|
52
|
+
if ("virtual" in page) {
|
|
53
|
+
paths.push(`/${page.page}`);
|
|
54
|
+
} else {
|
|
55
|
+
// Recursively process nested pages
|
|
56
|
+
processSidebarItems([page]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return paths;
|
|
65
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { startTransition, StrictMode } from "react";
|
|
2
|
+
import { hydrateRoot } from "react-dom/client";
|
|
3
|
+
import { HydratedRouter } from "react-router/dom";
|
|
4
|
+
|
|
5
|
+
// TODO: !!! BETTER !!! - needed cuz issues with rerender in react-router hash change
|
|
6
|
+
(() => {
|
|
7
|
+
var _wr = function (type: 'pushState' | 'replaceState') {
|
|
8
|
+
var orig = history[type];
|
|
9
|
+
return function (data: any, unused: string, url?: string | URL | null) {
|
|
10
|
+
var rv = orig.call(history, data, unused, url);
|
|
11
|
+
var e = new Event(type);
|
|
12
|
+
(e as any).arguments = arguments;
|
|
13
|
+
window.dispatchEvent(e);
|
|
14
|
+
return rv;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
history.replaceState = _wr('replaceState')
|
|
18
|
+
})()
|
|
19
|
+
|
|
20
|
+
console.log(`+-----------------------------------------------------------------------------------------------------------------------------+
|
|
21
|
+
| |
|
|
22
|
+
| dddddddd |
|
|
23
|
+
| /////// d::::::d |
|
|
24
|
+
| /:::::/ d::::::d >>>>>>> |
|
|
25
|
+
| /:::::/ d::::::d >:::::> |
|
|
26
|
+
| /:::::/ d::::::d >:::::> |
|
|
27
|
+
| /:::::/ xxxxxxx xxxxxxx yyyyyyy yyyyyyy ddddddddd:::::d >:::::> |
|
|
28
|
+
| /:::::/ x:::::x x:::::x y:::::y y:::::y dd::::::::::::::d >:::::> |
|
|
29
|
+
| /:::::/ x:::::x x:::::x y:::::y y:::::y d::::::::::::::::d >:::::> |
|
|
30
|
+
| /:::::/ x:::::xx:::::x y:::::y y:::::y d:::::::ddddd:::::d >:::::>|
|
|
31
|
+
| /:::::/ x::::::::::x y:::::y y:::::y d::::::d d:::::d >:::::> |
|
|
32
|
+
| /:::::/ x::::::::x y:::::y y:::::y d:::::d d:::::d >:::::> |
|
|
33
|
+
| /:::::/ x::::::::x y:::::y:::::y d:::::d d:::::d >:::::> |
|
|
34
|
+
| /:::::/ x::::::::::x y:::::::::y d:::::d d:::::d >:::::> |
|
|
35
|
+
| /:::::/ x:::::xx:::::x y:::::::y d::::::ddddd::::::dd >:::::> |
|
|
36
|
+
| /:::::/ x:::::x x:::::x y:::::y d:::::::::::::::::d >>>>>>> |
|
|
37
|
+
| /:::::/ x:::::x x:::::x y:::::y d:::::::::ddd::::d |
|
|
38
|
+
|/////// xxxxxxx xxxxxxx y:::::y ddddddddd ddddd |
|
|
39
|
+
| y:::::y |
|
|
40
|
+
| y:::::y |
|
|
41
|
+
| y:::::y |
|
|
42
|
+
| y:::::y |
|
|
43
|
+
| yyyyyyy |
|
|
44
|
+
| |
|
|
45
|
+
| |
|
|
46
|
+
| Check out https://github.com/livesession/xyd |
|
|
47
|
+
+-----------------------------------------------------------------------------------------------------------------------------+
|
|
48
|
+
`)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
startTransition(() => {
|
|
52
|
+
hydrateRoot(
|
|
53
|
+
document,
|
|
54
|
+
<StrictMode>
|
|
55
|
+
<HydratedRouter />
|
|
56
|
+
</StrictMode>
|
|
57
|
+
);
|
|
58
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { PassThrough } from "node:stream";
|
|
2
|
+
|
|
3
|
+
import type { AppLoadContext, EntryContext } from "react-router";
|
|
4
|
+
import { createReadableStreamFromReadable } from "@react-router/node";
|
|
5
|
+
import { ServerRouter } from "react-router";
|
|
6
|
+
import { isbot } from "isbot";
|
|
7
|
+
import type { RenderToPipeableStreamOptions } from "react-dom/server";
|
|
8
|
+
import { renderToPipeableStream } from "react-dom/server";
|
|
9
|
+
|
|
10
|
+
export const streamTimeout = 5_000;
|
|
11
|
+
|
|
12
|
+
export default function handleRequest(
|
|
13
|
+
request: Request,
|
|
14
|
+
responseStatusCode: number,
|
|
15
|
+
responseHeaders: Headers,
|
|
16
|
+
routerContext: EntryContext,
|
|
17
|
+
loadContext: AppLoadContext
|
|
18
|
+
) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
let shellRendered = false;
|
|
21
|
+
let userAgent = request.headers.get("user-agent");
|
|
22
|
+
|
|
23
|
+
// Ensure requests from bots and SPA Mode renders wait for all content to load before responding
|
|
24
|
+
// https://react.dev/reference/react-dom/server/renderToPipeableStream#waiting-for-all-content-to-load-for-crawlers-and-static-generation
|
|
25
|
+
let readyOption: keyof RenderToPipeableStreamOptions =
|
|
26
|
+
(userAgent && isbot(userAgent)) || routerContext.isSpaMode
|
|
27
|
+
? "onAllReady"
|
|
28
|
+
: "onShellReady";
|
|
29
|
+
|
|
30
|
+
const { pipe, abort } = renderToPipeableStream(
|
|
31
|
+
<ServerRouter context={routerContext} url={request.url} />,
|
|
32
|
+
{
|
|
33
|
+
[readyOption]() {
|
|
34
|
+
shellRendered = true;
|
|
35
|
+
const body = new PassThrough();
|
|
36
|
+
const stream = createReadableStreamFromReadable(body);
|
|
37
|
+
|
|
38
|
+
responseHeaders.set("Content-Type", "text/html");
|
|
39
|
+
|
|
40
|
+
resolve(
|
|
41
|
+
new Response(stream, {
|
|
42
|
+
headers: responseHeaders,
|
|
43
|
+
status: responseStatusCode,
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
pipe(body);
|
|
48
|
+
},
|
|
49
|
+
onShellError(error: unknown) {
|
|
50
|
+
reject(error);
|
|
51
|
+
},
|
|
52
|
+
onError(error: unknown) {
|
|
53
|
+
responseStatusCode = 500;
|
|
54
|
+
// Log streaming rendering errors from inside the shell. Don't log
|
|
55
|
+
// errors encountered during initial shell rendering since they'll
|
|
56
|
+
// reject and get logged in handleDocumentRequest.
|
|
57
|
+
if (shellRendered) {
|
|
58
|
+
console.error(error);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// Abort the rendering stream after the `streamTimeout` so it has tine to
|
|
65
|
+
// flush down the rejected boundaries
|
|
66
|
+
setTimeout(abort, streamTimeout + 1000);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import { Settings } from "@xyd-js/core";
|
|
4
|
+
import { layout, route } from "@react-router/dev/routes";
|
|
5
|
+
|
|
6
|
+
type Route = {
|
|
7
|
+
id: string
|
|
8
|
+
path: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Helper function to recursively extract route definitions from nested pages
|
|
12
|
+
export function pathRoutes(basePath: string, navigation: Settings['navigation']) {
|
|
13
|
+
if (!navigation?.sidebar) return [];
|
|
14
|
+
|
|
15
|
+
const routes: Route[] = [];
|
|
16
|
+
|
|
17
|
+
// Process each sidebar group
|
|
18
|
+
extractNestedRoutes(navigation.sidebar || [], routes)
|
|
19
|
+
|
|
20
|
+
if (!routes.length) {
|
|
21
|
+
return [
|
|
22
|
+
layout(path.join(basePath, "src/pages/layout.tsx"), [
|
|
23
|
+
route("/*", path.join(basePath, "src/pages/page.tsx"))
|
|
24
|
+
])
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return routes.map(r => {
|
|
29
|
+
return layout(path.join(basePath, "src/pages/layout.tsx"), { id: `layout:${r.id}` }, [
|
|
30
|
+
route(r.path, path.join(basePath, "src/pages/page.tsx"), { id: r.id })
|
|
31
|
+
])
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function extractNestedRoutes(
|
|
37
|
+
sidebarItems: any[],
|
|
38
|
+
routes: Route[],
|
|
39
|
+
parentRoute?: string,
|
|
40
|
+
) {
|
|
41
|
+
sidebarItems.forEach(item => {
|
|
42
|
+
if (item && typeof item === "object") {
|
|
43
|
+
let route = ""
|
|
44
|
+
|
|
45
|
+
// Only extract routes from items that have a "route" property
|
|
46
|
+
if ('route' in item && item.route) {
|
|
47
|
+
route = item.route
|
|
48
|
+
const routeMatch = item.route.startsWith("/") ? item.route : `/${item.route}`;
|
|
49
|
+
routes.push({ id: routeMatch, path: routeMatch + "/*" });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Recursively process nested pages within this route
|
|
53
|
+
if (item.pages && Array.isArray(item.pages)) {
|
|
54
|
+
extractNestedRoutes(item.pages, routes, route || parentRoute)
|
|
55
|
+
}
|
|
56
|
+
} else if (!parentRoute) {
|
|
57
|
+
const page = item.startsWith("/") ? item : `/${item}`;
|
|
58
|
+
routes.push({ id: page, path: page });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
package/app/public.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
import { redirect } from "react-router";
|
|
5
|
+
|
|
6
|
+
const MIME_TYPES: Record<string, string> = {
|
|
7
|
+
'.html': 'text/html',
|
|
8
|
+
'.css': 'text/css',
|
|
9
|
+
'.js': 'text/javascript',
|
|
10
|
+
'.json': 'application/json',
|
|
11
|
+
'.png': 'image/png',
|
|
12
|
+
'.jpg': 'image/jpeg',
|
|
13
|
+
'.jpeg': 'image/jpeg',
|
|
14
|
+
'.gif': 'image/gif',
|
|
15
|
+
'.svg': 'image/svg+xml',
|
|
16
|
+
'.ico': 'image/x-icon',
|
|
17
|
+
'.txt': 'text/plain',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const BINARY_FILE_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.ico'];
|
|
21
|
+
|
|
22
|
+
export async function loader({ params }: any) {
|
|
23
|
+
const filePath = path.join(process.cwd(), "public", params["*"])
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
await fs.access(filePath)
|
|
27
|
+
} catch (e) {
|
|
28
|
+
return redirect("/404")
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
32
|
+
const isBinaryFile = BINARY_FILE_EXTENSIONS.includes(ext);
|
|
33
|
+
const fileContent = await fs.readFile(filePath, isBinaryFile ? null : 'utf-8');
|
|
34
|
+
const contentType = MIME_TYPES[ext] || 'application/octet-stream';
|
|
35
|
+
|
|
36
|
+
return new Response(fileContent, {
|
|
37
|
+
status: 200,
|
|
38
|
+
headers: {
|
|
39
|
+
'Content-Type': contentType,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
package/app/raw.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
import { redirect } from "react-router";
|
|
5
|
+
|
|
6
|
+
const MIME_TYPES: Record<string, string> = {
|
|
7
|
+
'.md': 'text/markdown',
|
|
8
|
+
'.mdx': 'text/markdown',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// TODO: !!! FINISH !!!
|
|
12
|
+
export async function loader({ params }: any) {
|
|
13
|
+
const filePath = path.join(process.cwd(), "/docs/guides/quickstart.md")
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
await fs.access(filePath)
|
|
17
|
+
} catch (e) {
|
|
18
|
+
return redirect("/404")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
22
|
+
const fileContent = await fs.readFile(filePath, 'utf-8');
|
|
23
|
+
const contentType = MIME_TYPES[ext] || 'application/octet-stream';
|
|
24
|
+
|
|
25
|
+
return new Response(fileContent, {
|
|
26
|
+
status: 200,
|
|
27
|
+
headers: {
|
|
28
|
+
'Content-Type': contentType,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
package/app/robots.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export async function loader({ request }: { request: Request }) {
|
|
2
|
+
const baseUrl = __xydSettings?.seo?.domain || new URL(request.url).origin;
|
|
3
|
+
|
|
4
|
+
// Generate robots.txt content
|
|
5
|
+
const content = `# https://www.robotstxt.org/robotstxt.html
|
|
6
|
+
User-agent: *
|
|
7
|
+
Allow: /
|
|
8
|
+
|
|
9
|
+
# Sitemap
|
|
10
|
+
Sitemap: ${baseUrl}/sitemap.xml`;
|
|
11
|
+
|
|
12
|
+
return new Response(content, {
|
|
13
|
+
headers: {
|
|
14
|
+
'Content-Type': 'text/plain',
|
|
15
|
+
'Cache-Control': 'public, max-age=3600'
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
package/app/root.tsx
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React, { } from "react";
|
|
2
|
+
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "react-router";
|
|
3
|
+
|
|
4
|
+
import { XYDAnalytics } from "@xyd-js/analytics";
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { loadProvider } from 'virtual:xyd-analytics-providers'
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import virtualSettings from "virtual:xyd-settings";
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const { settings } = virtualSettings
|
|
11
|
+
|
|
12
|
+
// const settings = globalThis.__xydSettings
|
|
13
|
+
const DEFAULT_FAVICON_PATH = "/public/favicon.png";
|
|
14
|
+
|
|
15
|
+
const faviconPath = settings?.theme?.favicon || DEFAULT_FAVICON_PATH
|
|
16
|
+
const head = settings?.theme?.head || []
|
|
17
|
+
|
|
18
|
+
type HeadTag = 'meta' | 'link' | 'title' | 'script' | 'style'
|
|
19
|
+
|
|
20
|
+
export function Layout({ children }: { children: React.ReactNode }) {
|
|
21
|
+
const colorScheme = settings?.theme?.defaultColorScheme || "os"
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<html lang="en" data-color-scheme={colorScheme}>
|
|
25
|
+
<head>
|
|
26
|
+
|
|
27
|
+
{/* Inline script to prevent flash of unstyled content */}
|
|
28
|
+
<script
|
|
29
|
+
dangerouslySetInnerHTML={{
|
|
30
|
+
__html: `
|
|
31
|
+
(function() {
|
|
32
|
+
try {
|
|
33
|
+
var theme = localStorage.getItem('xyd-color-scheme') || 'auto';
|
|
34
|
+
var isDark = false;
|
|
35
|
+
|
|
36
|
+
if (theme === 'dark') {
|
|
37
|
+
isDark = true;
|
|
38
|
+
} else if (theme === 'auto') {
|
|
39
|
+
isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (isDark) {
|
|
43
|
+
document.documentElement.setAttribute('data-color-scheme', 'dark');
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
// Fallback to system preference if localStorage fails
|
|
47
|
+
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
48
|
+
document.documentElement.setAttribute('data-color-scheme', 'dark');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
`
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
<meta charSet="utf-8" />
|
|
56
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
57
|
+
|
|
58
|
+
<link rel="icon" type="image/png" sizes="32x32" href={faviconPath}></link>
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
{head.map(([tag, props]: [HeadTag, Record<string, string | boolean>], index: number) => {
|
|
62
|
+
return React.createElement(tag, { key: index, ...props })
|
|
63
|
+
})}
|
|
64
|
+
|
|
65
|
+
<Meta />
|
|
66
|
+
<Links />
|
|
67
|
+
</head>
|
|
68
|
+
<XYDAnalytics settings={settings} loader={loadProvider}>
|
|
69
|
+
<body>
|
|
70
|
+
{children}
|
|
71
|
+
<ScrollRestoration />
|
|
72
|
+
<Scripts />
|
|
73
|
+
</body>
|
|
74
|
+
</XYDAnalytics>
|
|
75
|
+
</html>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default function App() {
|
|
80
|
+
return <Outlet />;
|
|
81
|
+
}
|
|
82
|
+
|
package/app/routes.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
route,
|
|
3
|
+
} from "@react-router/dev/routes";
|
|
4
|
+
import {pathRoutes} from "./pathRoutes";
|
|
5
|
+
|
|
6
|
+
// Declare the global property type
|
|
7
|
+
declare global {
|
|
8
|
+
var __xydBasePath: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const basePath = globalThis.__xydBasePath
|
|
12
|
+
|
|
13
|
+
const navigation = __xydSettings?.navigation || {sidebar: []};
|
|
14
|
+
const docsRoutes = pathRoutes(basePath, navigation)
|
|
15
|
+
|
|
16
|
+
// TODO: !!!! if not routes found then '*' !!!
|
|
17
|
+
export const routes = [
|
|
18
|
+
...docsRoutes,
|
|
19
|
+
|
|
20
|
+
// TODO: in the future better sitemap + robots.txt
|
|
21
|
+
route("/sitemap.xml", "./sitemap.ts"),
|
|
22
|
+
route("/robots.txt", "./robots.ts"),
|
|
23
|
+
route(
|
|
24
|
+
"/.well-known/appspecific/com.chrome.devtools.json",
|
|
25
|
+
"./debug-null.tsx",
|
|
26
|
+
),
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
if (globalThis.__xydStaticFiles?.length) {
|
|
30
|
+
routes.push(route("/public/*", "./public.ts"))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default routes
|
|
34
|
+
|
package/app/sitemap.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {docPaths} from "./docPaths";
|
|
2
|
+
|
|
3
|
+
const navigation = __xydSettings?.navigation || {sidebar: []};
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// TODO: support lastmod and other advanced features
|
|
7
|
+
|
|
8
|
+
export async function loader({request}: { request: Request }) {
|
|
9
|
+
if (!navigation?.sidebar) {
|
|
10
|
+
return new Response('', {
|
|
11
|
+
status: 404,
|
|
12
|
+
headers: {
|
|
13
|
+
'Content-Type': 'text/plain'
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const routes: string[] = docPaths(navigation);
|
|
19
|
+
const baseUrl = __xydSettings?.seo?.domain || new URL(request.url).origin;
|
|
20
|
+
|
|
21
|
+
// Generate XML sitemap
|
|
22
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
23
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
24
|
+
${routes.map(route => {
|
|
25
|
+
const fullUrl = `${baseUrl}${route}`.replace(/([^:]\/)\/+/g, "$1"); // Remove duplicate slashes
|
|
26
|
+
return ` <url>
|
|
27
|
+
<loc>${fullUrl}</loc>
|
|
28
|
+
<changefreq>daily</changefreq>
|
|
29
|
+
<priority>0.7</priority>
|
|
30
|
+
</url>`;
|
|
31
|
+
}).join('\n')}
|
|
32
|
+
</urlset>`;
|
|
33
|
+
|
|
34
|
+
return new Response(xml, {
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/xml',
|
|
37
|
+
'Cache-Control': 'public, max-age=3600'
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyd-js/host",
|
|
3
|
+
"version": "0.1.0-xyd.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@react-router/dev": "^7.5.0",
|
|
7
|
+
"@react-router/node": "^7.5.0",
|
|
8
|
+
"@react-router/serve": "^7.5.0",
|
|
9
|
+
"isbot": "^5",
|
|
10
|
+
"react-router": "^7.5.0",
|
|
11
|
+
"@xyd-js/core": "0.1.0-xyd.15",
|
|
12
|
+
"@xyd-js/components": "0.1.0-xyd.13",
|
|
13
|
+
"@xyd-js/framework": "0.1.0-xyd.34",
|
|
14
|
+
"@xyd-js/composer": "0.1.0-xyd.2",
|
|
15
|
+
"@xyd-js/themes": "0.1.1-xyd.5",
|
|
16
|
+
"@xyd-js/theme-poetry": "0.1.0-xyd.29",
|
|
17
|
+
"@xyd-js/theme-opener": "0.1.0-xyd.2",
|
|
18
|
+
"@xyd-js/theme-cosmo": "0.1.0-xyd.2",
|
|
19
|
+
"@xyd-js/theme-picasso": "0.1.0-xyd.2",
|
|
20
|
+
"@xyd-js/plugin-orama": "0.1.0-xyd.2",
|
|
21
|
+
"@xyd-js/plugin-algolia": "0.1.0-xyd.2",
|
|
22
|
+
"@xyd-js/atlas": "0.1.0-xyd.18"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"autoprefixer": "^10.4.20",
|
|
26
|
+
"postcss": "^8.4.47",
|
|
27
|
+
"semver": "^7.6.3",
|
|
28
|
+
"vite": "^6.1.0",
|
|
29
|
+
"vite-tsconfig-paths": "^5.1.4"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
xyd plugins
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
import type {Config} from "@react-router/dev/config";
|
|
5
|
+
|
|
6
|
+
import {Settings} from "@xyd-js/core";
|
|
7
|
+
import {docPaths} from "./app/docPaths";
|
|
8
|
+
|
|
9
|
+
declare global {
|
|
10
|
+
var __xydSettings: Settings;
|
|
11
|
+
var __xydStaticFiles: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Function to get all static files from the public directory
|
|
15
|
+
async function getStaticFiles() {
|
|
16
|
+
const publicDir = path.join(process.cwd(), "public");
|
|
17
|
+
const paths: string[] = [];
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
await fs.access(publicDir);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return paths;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function scanDirectory(dir: string, basePath: string = "") {
|
|
26
|
+
const entries = await fs.readdir(dir, {withFileTypes: true});
|
|
27
|
+
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
const fullPath = path.join(dir, entry.name);
|
|
30
|
+
const relativePath = path.join(basePath, entry.name);
|
|
31
|
+
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
await scanDirectory(fullPath, relativePath);
|
|
34
|
+
} else {
|
|
35
|
+
paths.push(`/public/${relativePath}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await scanDirectory(publicDir);
|
|
41
|
+
return paths;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Function to find documentation files for navigation paths
|
|
45
|
+
// async function findDocFiles(navigationPaths: string[]) {
|
|
46
|
+
// const docFiles: string[] = [];
|
|
47
|
+
//
|
|
48
|
+
// for (const navPath of navigationPaths) {
|
|
49
|
+
// // Try .mdx first, then .md
|
|
50
|
+
// const mdxPath = path.join(process.cwd(), navPath + '.mdx');
|
|
51
|
+
// const mdPath = path.join(process.cwd(), navPath + '.md');
|
|
52
|
+
//
|
|
53
|
+
// try {
|
|
54
|
+
// await fs.access(mdxPath);
|
|
55
|
+
// docFiles.push(navPath + ".mdx");
|
|
56
|
+
// } catch {
|
|
57
|
+
// try {
|
|
58
|
+
// await fs.access(mdPath);
|
|
59
|
+
// docFiles.push(navPath + ".md");
|
|
60
|
+
// } catch {
|
|
61
|
+
// }
|
|
62
|
+
// }
|
|
63
|
+
// }
|
|
64
|
+
//
|
|
65
|
+
// return docFiles;
|
|
66
|
+
// }
|
|
67
|
+
|
|
68
|
+
// Use settings.navigation if it exists, otherwise use an empty object
|
|
69
|
+
const navigation = __xydSettings?.navigation || {sidebar: []};
|
|
70
|
+
const navigationPaths = docPaths(navigation);
|
|
71
|
+
|
|
72
|
+
// Get static files and documentation files
|
|
73
|
+
const staticFiles = await getStaticFiles();
|
|
74
|
+
// const docFiles = await findDocFiles(navigationPaths);
|
|
75
|
+
|
|
76
|
+
globalThis.__xydStaticFiles = staticFiles
|
|
77
|
+
|
|
78
|
+
// Combine all paths for prerendering
|
|
79
|
+
const prerenderPaths = [
|
|
80
|
+
...navigationPaths,
|
|
81
|
+
...staticFiles,
|
|
82
|
+
|
|
83
|
+
"/sitemap.xml",
|
|
84
|
+
"/robots.txt",
|
|
85
|
+
// ...docFiles,
|
|
86
|
+
];
|
|
87
|
+
const cwd = process.cwd();
|
|
88
|
+
|
|
89
|
+
export default {
|
|
90
|
+
ssr: false,
|
|
91
|
+
prerender: prerenderPaths,
|
|
92
|
+
buildDirectory: path.join(cwd, ".xyd/build"),
|
|
93
|
+
// return a list of URLs to prerender at build time
|
|
94
|
+
} satisfies Config;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* prettier-ignore */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
// noinspection JSUnusedGlobalSymbols
|
|
5
|
+
// Generated by unplugin-auto-import
|
|
6
|
+
// biome-ignore lint: disable
|
|
7
|
+
export {}
|
|
8
|
+
declare global {
|
|
9
|
+
const createRef: typeof import('react')['createRef']
|
|
10
|
+
const forwardRef: typeof import('react')['forwardRef']
|
|
11
|
+
const lazy: typeof import('react')['lazy']
|
|
12
|
+
const memo: typeof import('react')['memo']
|
|
13
|
+
const startTransition: typeof import('react')['startTransition']
|
|
14
|
+
const useCallback: typeof import('react')['useCallback']
|
|
15
|
+
const useContext: typeof import('react')['useContext']
|
|
16
|
+
const useDebugValue: typeof import('react')['useDebugValue']
|
|
17
|
+
const useDeferredValue: typeof import('react')['useDeferredValue']
|
|
18
|
+
const useEffect: typeof import('react')['useEffect']
|
|
19
|
+
const useId: typeof import('react')['useId']
|
|
20
|
+
const useImperativeHandle: typeof import('react')['useImperativeHandle']
|
|
21
|
+
const useInsertionEffect: typeof import('react')['useInsertionEffect']
|
|
22
|
+
const useLayoutEffect: typeof import('react')['useLayoutEffect']
|
|
23
|
+
const useMemo: typeof import('react')['useMemo']
|
|
24
|
+
const useReducer: typeof import('react')['useReducer']
|
|
25
|
+
const useRef: typeof import('react')['useRef']
|
|
26
|
+
const useState: typeof import('react')['useState']
|
|
27
|
+
const useSyncExternalStore: typeof import('react')['useSyncExternalStore']
|
|
28
|
+
const useTransition: typeof import('react')['useTransition']
|
|
29
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": [
|
|
7
|
+
"ES2020",
|
|
8
|
+
"DOM",
|
|
9
|
+
"DOM.Iterable"
|
|
10
|
+
],
|
|
11
|
+
"typeRoots": [
|
|
12
|
+
"./types.d.ts"
|
|
13
|
+
],
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"moduleResolution": "bundler",
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"isolatedModules": true,
|
|
18
|
+
"noEmit": false,
|
|
19
|
+
"strict": true,
|
|
20
|
+
"noUnusedLocals": true,
|
|
21
|
+
"noUnusedParameters": true,
|
|
22
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
|
+
"jsx": "react-jsx",
|
|
24
|
+
"include": [
|
|
25
|
+
"./types.d.ts"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
package/types.d.ts
ADDED