@heyo-sh/create-heyo-docs 3.1.0 → 3.2.1
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/deployments/cloudflare/astro/src/pages/heyo-docs-internal/ai-chat.ts +9 -4
- package/deployments/cloudflare/next/app/heyo-docs-internal/ai-chat/route.ts +10 -6
- package/deployments/cloudflare/react-router/app/routes/ai-chat.ts +11 -6
- package/package.json +1 -1
- package/templates/astro/src/pages/robots.txt.ts +1 -0
- package/templates/next/app/robots.txt/route.ts +1 -0
- package/templates/react-router/app/routes/docs.tsx +30 -27
- package/templates/react-router/app/routes/page.tsx +1 -1
- package/templates/react-router/app/routes/robots.ts +1 -0
|
@@ -16,10 +16,15 @@ export const POST: APIRoute = async ({ request }) => {
|
|
|
16
16
|
const token = env.HEYO_DOCS_AI_API_KEY;
|
|
17
17
|
const { createAiChatResponse } = await import("@heyo-sh/heyo-docs/ai");
|
|
18
18
|
return createAiChatResponse(request, {
|
|
19
|
-
ai:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
ai: {
|
|
20
|
+
...config.ai,
|
|
21
|
+
chat: {
|
|
22
|
+
...config.ai.chat,
|
|
23
|
+
...(!config.ai.chat.auth && token
|
|
24
|
+
? { auth: { type: "api-key" as const, token } }
|
|
25
|
+
: {}),
|
|
26
|
+
},
|
|
27
|
+
},
|
|
23
28
|
markdownPages,
|
|
24
29
|
pages: markdownPages.map((page) => ({
|
|
25
30
|
description: page.description,
|
|
@@ -12,14 +12,18 @@ export async function POST(request: Request) {
|
|
|
12
12
|
{ status: 404 },
|
|
13
13
|
);
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
const token = env.HEYO_DOCS_AI_API_KEY;
|
|
15
|
+
const token = getCloudflareContext().env.HEYO_DOCS_AI_API_KEY;
|
|
17
16
|
const { createAiChatResponse } = await import("@heyo-sh/heyo-docs/ai");
|
|
18
17
|
return createAiChatResponse(request, {
|
|
19
|
-
ai:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
ai: {
|
|
19
|
+
...config.ai,
|
|
20
|
+
chat: {
|
|
21
|
+
...config.ai.chat,
|
|
22
|
+
...(!config.ai.chat.auth && token
|
|
23
|
+
? { auth: { type: "api-key" as const, token } }
|
|
24
|
+
: {}),
|
|
25
|
+
},
|
|
26
|
+
},
|
|
23
27
|
markdownPages,
|
|
24
28
|
pages: docsPages,
|
|
25
29
|
title: config.title,
|
|
@@ -16,14 +16,19 @@ export async function action({ context, request }: ActionFunctionArgs) {
|
|
|
16
16
|
{ error: "AI chat is not configured." },
|
|
17
17
|
{ status: 404 },
|
|
18
18
|
);
|
|
19
|
-
|
|
20
|
-
const token =
|
|
19
|
+
|
|
20
|
+
const token = context.get(cloudflareContext).HEYO_DOCS_AI_API_KEY;
|
|
21
21
|
const { createAiChatResponse } = await import("@heyo-sh/heyo-docs/ai");
|
|
22
22
|
return createAiChatResponse(request, {
|
|
23
|
-
ai:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
ai: {
|
|
24
|
+
...config.ai,
|
|
25
|
+
chat: {
|
|
26
|
+
...config.ai.chat,
|
|
27
|
+
...(!config.ai.chat.auth && token
|
|
28
|
+
? { auth: { type: "api-key" as const, token } }
|
|
29
|
+
: {}),
|
|
30
|
+
},
|
|
31
|
+
},
|
|
27
32
|
markdownPages,
|
|
28
33
|
pages,
|
|
29
34
|
title: config.title,
|
package/package.json
CHANGED
|
@@ -5,10 +5,7 @@ import {
|
|
|
5
5
|
findOpenApiEndpoint,
|
|
6
6
|
} from "@heyo-sh/heyo-docs/model";
|
|
7
7
|
import { changelogGroupForPage } from "@heyo-sh/heyo-docs/navigation";
|
|
8
|
-
import {
|
|
9
|
-
openApiEndpointDataPath,
|
|
10
|
-
openApiEndpointDetail,
|
|
11
|
-
} from "@heyo-sh/heyo-docs/openapi";
|
|
8
|
+
import { openApiEndpointDetail } from "@heyo-sh/heyo-docs/openapi";
|
|
12
9
|
import { docsSeoMeta } from "@heyo-sh/heyo-docs/seo/react-router";
|
|
13
10
|
import type { OpenApiEndpoint } from "@heyo-sh/heyo-docs/types";
|
|
14
11
|
import { useDocsTheme } from "@heyo-sh/heyo-docs/theme/provider";
|
|
@@ -16,6 +13,7 @@ import {
|
|
|
16
13
|
Link,
|
|
17
14
|
useLoaderData,
|
|
18
15
|
useParams,
|
|
16
|
+
type ClientLoaderFunctionArgs,
|
|
19
17
|
type LoaderFunctionArgs,
|
|
20
18
|
type MetaFunction,
|
|
21
19
|
} from "react-router";
|
|
@@ -48,33 +46,38 @@ export async function loader({ params }: LoaderFunctionArgs) {
|
|
|
48
46
|
|
|
49
47
|
if (!endpoint) return {};
|
|
50
48
|
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
currentOpenApiEndpoint: currentOpenApiEndpoint
|
|
61
|
-
? openApiEndpointDetail(currentOpenApiEndpoint)
|
|
62
|
-
: undefined,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Client transitions wait for the static shard before committing the new
|
|
67
|
-
// route. This prevents rendering the compact index and replacing it later.
|
|
68
|
-
const response = await fetch(openApiEndpointDataPath(endpoint.slug));
|
|
69
|
-
if (!response.ok)
|
|
70
|
-
throw new Response("OpenAPI endpoint data could not be loaded", {
|
|
71
|
-
status: response.status,
|
|
72
|
-
});
|
|
49
|
+
// This loader runs on the server, including during prerendering, so the
|
|
50
|
+
// operation's full data is serialised with the route. First paint and every
|
|
51
|
+
// client transition therefore start from the complete API reference.
|
|
52
|
+
const serverModel = createDocsModel(config, pages, openApiDocuments);
|
|
53
|
+
const currentOpenApiEndpoint = findOpenApiEndpoint(
|
|
54
|
+
serverModel.endpoints,
|
|
55
|
+
pathname,
|
|
56
|
+
);
|
|
73
57
|
return {
|
|
74
|
-
currentOpenApiEndpoint:
|
|
58
|
+
currentOpenApiEndpoint: currentOpenApiEndpoint
|
|
59
|
+
? (openApiEndpointDetail(currentOpenApiEndpoint) as OpenApiEndpoint)
|
|
60
|
+
: undefined,
|
|
75
61
|
};
|
|
76
62
|
}
|
|
77
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Loads the page's MDX chunk before the new route is displayed, so a reader
|
|
66
|
+
* never sees a loading placeholder replace the page they came from.
|
|
67
|
+
*/
|
|
68
|
+
export async function clientLoader({
|
|
69
|
+
params,
|
|
70
|
+
serverLoader,
|
|
71
|
+
}: ClientLoaderFunctionArgs) {
|
|
72
|
+
const model = createDocsModel(config, pages, [], openApiEndpoints);
|
|
73
|
+
const page = findDocsPage(model.pages, pathnameFor(params));
|
|
74
|
+
const [data] = await Promise.all([
|
|
75
|
+
serverLoader<Awaited<ReturnType<typeof loader>>>(),
|
|
76
|
+
page?.preload?.(),
|
|
77
|
+
]);
|
|
78
|
+
return data;
|
|
79
|
+
}
|
|
80
|
+
|
|
78
81
|
export const meta: MetaFunction = ({ params }) => {
|
|
79
82
|
const model = createDocsModel(config, pages, [], openApiEndpoints);
|
|
80
83
|
const pathname = pathnameFor(params);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default, loader, meta, ErrorBoundary } from "./docs";
|
|
1
|
+
export { default, clientLoader, loader, meta, ErrorBoundary } from "./docs";
|