@docs-sdk-dev/next 0.0.0-stage → 0.4.0-next.0
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/LICENSE +21 -0
- package/README.md +58 -2
- package/dist/build-profile.d.ts +7 -0
- package/dist/build-profile.js +158 -0
- package/dist/build-profile.js.map +1 -0
- package/dist/build.d.ts +39 -0
- package/dist/build.js +177 -0
- package/dist/build.js.map +1 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +69 -0
- package/dist/client.js.map +1 -0
- package/dist/dev-events.d.ts +35 -0
- package/dist/dev-events.js +117 -0
- package/dist/dev-events.js.map +1 -0
- package/dist/dev-refresh.d.ts +9 -0
- package/dist/dev-refresh.js +51 -0
- package/dist/dev-refresh.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/metadata.d.ts +15 -0
- package/dist/metadata.js +48 -0
- package/dist/metadata.js.map +1 -0
- package/dist/native-routes.d.ts +9 -0
- package/dist/native-routes.js +80 -0
- package/dist/native-routes.js.map +1 -0
- package/dist/publication.d.ts +6 -0
- package/dist/publication.js +56 -0
- package/dist/publication.js.map +1 -0
- package/dist/server.d.ts +1253 -0
- package/dist/server.js +364 -0
- package/dist/server.js.map +1 -0
- package/docs/framework/hosts/next-native-preview.md +21 -0
- package/docs/framework/hosts.md +91 -0
- package/docs/index.md +8 -0
- package/docs/zh-CN/framework/hosts/next-native-preview.md +21 -0
- package/docs/zh-CN/framework/hosts.md +93 -0
- package/package.json +60 -4
- package/styles/site.css +5 -0
package/dist/server.js
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { headers } from "next/headers.js";
|
|
3
|
+
import { connection } from "next/server.js";
|
|
4
|
+
import { cache, createElement } from "react";
|
|
5
|
+
import { isSourceAssetPath, localeAlternates } from "@docs-sdk-dev/core";
|
|
6
|
+
import { isPublicationPath, localeDimension } from "@docs-sdk-dev/reader";
|
|
7
|
+
import { createPageContextPresenter } from "@docs-sdk-dev/web/context-bridge";
|
|
8
|
+
import { createDocs as createDocs$1 } from "@docs-sdk-dev/web/application";
|
|
9
|
+
import { publicResourceAssetResponse, resourceAssetHeaders } from "@docs-sdk-dev/node/internal/web-serving";
|
|
10
|
+
import { isAccessPrefetch } from "@docs-sdk-dev/core/access";
|
|
11
|
+
import { selectIslandPreloads } from "@docs-sdk-dev/web/island-plan";
|
|
12
|
+
import { resourcePreviewCandidates } from "@docs-sdk-dev/web/resource-preview";
|
|
13
|
+
import { createDocsRuntime } from "@docs-sdk-dev/web/runtime";
|
|
14
|
+
import { DocsMetadata, toNextMetadata } from "./metadata.js";
|
|
15
|
+
import { openAccessPublication, openPublication, publicPublication } from "./publication.js";
|
|
16
|
+
|
|
17
|
+
// src/server.ts
|
|
18
|
+
/**
|
|
19
|
+
* Under `devNext`, a refresh can read a new publication before Next recompiles the generated route that names its
|
|
20
|
+
* revision. That route already imports the current source module, so only its revision lags, and Next refreshes the
|
|
21
|
+
* page again once it compiles.
|
|
22
|
+
*/
|
|
23
|
+
const followsDevBuilds = () => process.env.NODE_ENV !== "production" && Boolean(process.env.DOCS_SDK_DEV_EVENTS);
|
|
24
|
+
function route(slug) {
|
|
25
|
+
const parts = slug.map((part) => encodeURIComponent(part));
|
|
26
|
+
return parts.length ? "/" + parts.join("/") + "/" : "/";
|
|
27
|
+
}
|
|
28
|
+
function routeParams(path) {
|
|
29
|
+
return { slug: path.split("/").filter(Boolean).map(decodeURIComponent) };
|
|
30
|
+
}
|
|
31
|
+
function index(publication, base, runtime = createDocsRuntime({ reader: publication })) {
|
|
32
|
+
const { manifest } = publication;
|
|
33
|
+
const routes = new Map(manifest.documents.map((page) => [route(routeParams(page.route).slug), page]));
|
|
34
|
+
const presentContext = createPageContextPresenter(manifest, base);
|
|
35
|
+
let languages;
|
|
36
|
+
return {
|
|
37
|
+
routes,
|
|
38
|
+
runtime,
|
|
39
|
+
presentContext,
|
|
40
|
+
languages: () => languages ??= localeAlternates(manifest.documents, localeDimension(manifest.dimensionPolicy), manifest.dimensionPolicy?.defaultLocale)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function metadata(publication, page, base, languages) {
|
|
44
|
+
if (!page) return {};
|
|
45
|
+
const resolved = pageMetadata(publication, page);
|
|
46
|
+
if (resolved) return toNextMetadata(resolved);
|
|
47
|
+
const alternates = languages().get(page.key);
|
|
48
|
+
return {
|
|
49
|
+
title: page.title,
|
|
50
|
+
description: page.description,
|
|
51
|
+
alternates: {
|
|
52
|
+
canonical: base + page.route,
|
|
53
|
+
...alternates && { languages: Object.fromEntries(alternates.map((item) => [item.locale, base + item.route])) }
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function pageMetadata(publication, page) {
|
|
58
|
+
const values = publication.metadata;
|
|
59
|
+
return values && Object.hasOwn(values, page.key) ? values[page.key] : void 0;
|
|
60
|
+
}
|
|
61
|
+
const protectedMetadata = {
|
|
62
|
+
title: null,
|
|
63
|
+
description: null,
|
|
64
|
+
alternates: null,
|
|
65
|
+
openGraph: null,
|
|
66
|
+
twitter: null,
|
|
67
|
+
robots: {
|
|
68
|
+
index: false,
|
|
69
|
+
follow: false,
|
|
70
|
+
noarchive: true
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
function privateResponse(body, init = {}) {
|
|
74
|
+
const result = new Headers(init.headers);
|
|
75
|
+
result.set("cache-control", "private, no-store");
|
|
76
|
+
const vary = new Set(result.get("vary")?.toLowerCase().split(/\s*,\s*/));
|
|
77
|
+
if (!vary.has("*")) {
|
|
78
|
+
vary.add("authorization");
|
|
79
|
+
vary.add("cookie");
|
|
80
|
+
result.set("vary", [...vary].join(", "));
|
|
81
|
+
}
|
|
82
|
+
result.delete("etag");
|
|
83
|
+
result.delete("last-modified");
|
|
84
|
+
return new Response(body, {
|
|
85
|
+
...init,
|
|
86
|
+
headers: result
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function createDocs(settings) {
|
|
90
|
+
const application = createDocs$1({
|
|
91
|
+
publication: settings.publicPublication,
|
|
92
|
+
host: {
|
|
93
|
+
async access(request, publicView) {
|
|
94
|
+
if (isAccessPrefetch(request) || publicView.accessRequired === false || !settings.accessPublication) return { publication: publicView };
|
|
95
|
+
return { publication: await settings.accessPublication(request, publicView.manifest.buildRevision) };
|
|
96
|
+
},
|
|
97
|
+
persistence: settings.persistenceForRequest
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const publicViewForRender = cache(async () => settings.publicPublication());
|
|
101
|
+
const publicIndexes = /* @__PURE__ */ new WeakMap();
|
|
102
|
+
function publicIndex(publication) {
|
|
103
|
+
let lookup = publicIndexes.get(publication);
|
|
104
|
+
if (!lookup) {
|
|
105
|
+
lookup = index(publication, basePath(publication));
|
|
106
|
+
publicIndexes.set(publication, lookup);
|
|
107
|
+
}
|
|
108
|
+
return lookup;
|
|
109
|
+
}
|
|
110
|
+
function basePath(publication) {
|
|
111
|
+
return settings.basePath ?? publication.manifest.basePath ?? "";
|
|
112
|
+
}
|
|
113
|
+
async function publicPage(slug) {
|
|
114
|
+
const publication = await publicViewForRender();
|
|
115
|
+
const lookup = publicIndex(publication);
|
|
116
|
+
return {
|
|
117
|
+
publication,
|
|
118
|
+
lookup,
|
|
119
|
+
entry: lookup.routes.get(route(slug))
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async function present(publication, lookup, entry, { private: restricted, routeView, metadata: resolvedMetadata, request, preferences } = {}) {
|
|
123
|
+
if (!entry) return null;
|
|
124
|
+
const page = pageFor(lookup.runtime, entry);
|
|
125
|
+
if (!page) return null;
|
|
126
|
+
const document = await page.loadCompiledDocument({ signal: request?.signal });
|
|
127
|
+
if (!document) return null;
|
|
128
|
+
const context = page.readContext();
|
|
129
|
+
const { personalized, ...pageContext } = (context && await lookup.presentContext(document.identity, context, {
|
|
130
|
+
request,
|
|
131
|
+
restricted,
|
|
132
|
+
preferences: await preferences?.()
|
|
133
|
+
})) ?? {};
|
|
134
|
+
if (routeView && (routeView.revision !== publication.manifest.buildRevision && !followsDevBuilds() || routeView.module !== document.nativeView?.module)) return null;
|
|
135
|
+
const native = routeView?.view ?? (document.nativeView && await publication.readNativeView?.(document.nativeView.module));
|
|
136
|
+
if (document.nativeView && !native?.default && !restricted) throw new Error(`No native view in this publication for ${entry.route}.`);
|
|
137
|
+
if (restricted && native?.default && Reflect.get(native.default, "$$typeof") === Symbol.for("react.client.reference")) throw new Error(`The protected native view for ${entry.route} must be a Server Component.`);
|
|
138
|
+
if (native && document.nativeView?.layout === "custom" && (!native.Layout || Reflect.get(native.Layout, "$$typeof") === Symbol.for("react.client.reference"))) throw new Error(`The native Layout for ${entry.route} must be a Server Component. Place "use client" components inside the layout instead.`);
|
|
139
|
+
return {
|
|
140
|
+
document,
|
|
141
|
+
navigation: page.navigation,
|
|
142
|
+
outline: page.outline,
|
|
143
|
+
locale: page.locale,
|
|
144
|
+
themeLabels: publication.readLabels?.(page.locale),
|
|
145
|
+
basePath: basePath(publication),
|
|
146
|
+
...native?.default && { native },
|
|
147
|
+
...pageContext,
|
|
148
|
+
...restricted && { private: true },
|
|
149
|
+
...resolvedMetadata && { metadata: resolvedMetadata },
|
|
150
|
+
...page.capabilities.resources && { resourceBase: basePath(publication) }
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function pageFor(runtime, entry) {
|
|
154
|
+
if (!entry) return;
|
|
155
|
+
const page = runtime.resolvePage({
|
|
156
|
+
identity: entry.identity,
|
|
157
|
+
match: "exact"
|
|
158
|
+
});
|
|
159
|
+
return page.status === "exact" ? page : void 0;
|
|
160
|
+
}
|
|
161
|
+
async function contextFor(runtime, entry, section) {
|
|
162
|
+
const page = pageFor(runtime, entry);
|
|
163
|
+
const excerpt = await page?.read(section);
|
|
164
|
+
return page && excerpt ? {
|
|
165
|
+
...excerpt,
|
|
166
|
+
buildRevision: page.revision
|
|
167
|
+
} : null;
|
|
168
|
+
}
|
|
169
|
+
async function markdownFor(runtime, entry) {
|
|
170
|
+
return (await pageFor(runtime, entry)?.read())?.markdown;
|
|
171
|
+
}
|
|
172
|
+
function resourcePath(path) {
|
|
173
|
+
const name = ["resource-assets", ...path].join("/");
|
|
174
|
+
return path.length && path.every((part) => !part.includes("/")) && isSourceAssetPath(name) ? name : void 0;
|
|
175
|
+
}
|
|
176
|
+
async function assetFor(publication, name, request, isPrivate) {
|
|
177
|
+
const missing = () => isPrivate ? privateResponse(null, { status: 404 }) : new Response(null, { status: 404 });
|
|
178
|
+
if (!name || !isPublicationPath(name)) return missing();
|
|
179
|
+
const asset = await publication.readResource?.(name);
|
|
180
|
+
if (!asset) return !isPrivate && await publication.readOgResource?.(name, request) || missing();
|
|
181
|
+
if (!isPrivate) return publicResourceAssetResponse(name, asset, request);
|
|
182
|
+
return privateResponse(request?.method === "HEAD" ? null : Buffer.from(asset.base64, "base64"), { headers: {
|
|
183
|
+
...resourceAssetHeaders(name),
|
|
184
|
+
"content-security-policy": "sandbox; default-src 'none'"
|
|
185
|
+
} });
|
|
186
|
+
}
|
|
187
|
+
async function forRequest(request) {
|
|
188
|
+
await connection();
|
|
189
|
+
const scope = await application.forRequest(request);
|
|
190
|
+
const { publicView, publication, runtime } = scope;
|
|
191
|
+
if (!publication || !runtime) throw new Error("The Next documentation request scope was denied.");
|
|
192
|
+
let lookup;
|
|
193
|
+
function entryFor(slug) {
|
|
194
|
+
scope.signal.throwIfAborted();
|
|
195
|
+
lookup ??= index(publication, basePath(publication), runtime);
|
|
196
|
+
return {
|
|
197
|
+
lookup,
|
|
198
|
+
entry: lookup.routes.get(route(slug))
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function publicEntryFor(slug, entry) {
|
|
202
|
+
if (!entry) return;
|
|
203
|
+
const publicEntry = publicIndex(publicView).routes.get(route(slug));
|
|
204
|
+
return publicEntry?.key === entry.key ? publicEntry : void 0;
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
manifest: publication.manifest,
|
|
208
|
+
/** A runtime over the same filtered Reader and resource indexes as the page. */
|
|
209
|
+
runtime,
|
|
210
|
+
signal: scope.signal,
|
|
211
|
+
dispose: scope.dispose,
|
|
212
|
+
reader: runtime.reader,
|
|
213
|
+
async getPage(slug) {
|
|
214
|
+
const { lookup, entry } = entryFor(slug);
|
|
215
|
+
const publicEntry = publicEntryFor(slug, entry);
|
|
216
|
+
return present(publication, lookup, entry, {
|
|
217
|
+
private: true,
|
|
218
|
+
request,
|
|
219
|
+
preferences: scope.preferences,
|
|
220
|
+
metadata: publicEntry && pageMetadata(publicView, publicEntry)
|
|
221
|
+
});
|
|
222
|
+
},
|
|
223
|
+
getMetadata(slug) {
|
|
224
|
+
const publicEntry = publicEntryFor(slug, entryFor(slug).entry);
|
|
225
|
+
return publicEntry ? metadata(publicView, publicEntry, basePath(publicView), publicIndex(publicView).languages) : protectedMetadata;
|
|
226
|
+
},
|
|
227
|
+
getRedirect(slug) {
|
|
228
|
+
if (!entryFor(slug).entry) return publication.manifest.redirects?.find((item) => item.from === route(slug))?.to;
|
|
229
|
+
},
|
|
230
|
+
getAgentContext(slug, section) {
|
|
231
|
+
return contextFor(runtime, entryFor(slug).entry, section);
|
|
232
|
+
},
|
|
233
|
+
getMarkdown(slug) {
|
|
234
|
+
return markdownFor(runtime, entryFor(slug).entry);
|
|
235
|
+
},
|
|
236
|
+
async resolveFact(...args) {
|
|
237
|
+
return runtime.facts.resolve(...args);
|
|
238
|
+
},
|
|
239
|
+
async search(text, options) {
|
|
240
|
+
return runtime.search(text, options);
|
|
241
|
+
},
|
|
242
|
+
getResourceAsset(path) {
|
|
243
|
+
scope.signal.throwIfAborted();
|
|
244
|
+
return assetFor(publication, resourcePath(path), request, true);
|
|
245
|
+
},
|
|
246
|
+
getAsset(path) {
|
|
247
|
+
scope.signal.throwIfAborted();
|
|
248
|
+
return assetFor(publication, path, request, true);
|
|
249
|
+
},
|
|
250
|
+
async mcp() {
|
|
251
|
+
scope.signal.throwIfAborted();
|
|
252
|
+
const response = await publication.serveMcp?.(request);
|
|
253
|
+
scope.signal.throwIfAborted();
|
|
254
|
+
if (!response || response.status === 304) return privateResponse(null, { status: 404 });
|
|
255
|
+
return privateResponse(response.body, {
|
|
256
|
+
status: response.status,
|
|
257
|
+
statusText: response.statusText,
|
|
258
|
+
headers: response.headers
|
|
259
|
+
});
|
|
260
|
+
},
|
|
261
|
+
response: privateResponse
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
const pageView = cache(async (href) => forRequest(new Request(href, { headers: await headers() })));
|
|
265
|
+
return {
|
|
266
|
+
forRequest,
|
|
267
|
+
/** Use the incoming Next headers with a URL from the application's trusted origin. */
|
|
268
|
+
forPage(url) {
|
|
269
|
+
return pageView(url.href);
|
|
270
|
+
},
|
|
271
|
+
async getPage(slug, routeView) {
|
|
272
|
+
const { publication, lookup, entry } = await publicPage(slug);
|
|
273
|
+
return present(publication, lookup, entry, {
|
|
274
|
+
routeView,
|
|
275
|
+
metadata: entry && pageMetadata(publication, entry)
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
/** Render a cookie-aware public page without placing its HTML in an ISR cache. */
|
|
279
|
+
async getPageForRequest(slug, request, routeView) {
|
|
280
|
+
await connection();
|
|
281
|
+
const { publication, lookup, entry } = await publicPage(slug);
|
|
282
|
+
return present(publication, lookup, entry, {
|
|
283
|
+
routeView,
|
|
284
|
+
request,
|
|
285
|
+
preferences: () => settings.persistenceForRequest?.(request),
|
|
286
|
+
metadata: entry && pageMetadata(publication, entry)
|
|
287
|
+
});
|
|
288
|
+
},
|
|
289
|
+
/** Read a bounded, navigation-only plan from the public publication. Request views cannot produce this plan. */
|
|
290
|
+
async getIslandPreloadPlan(slug) {
|
|
291
|
+
const { publication, entry, lookup } = await publicPage(slug);
|
|
292
|
+
if (!publication.readResource) return null;
|
|
293
|
+
const document = await pageFor(lookup.runtime, entry)?.loadCompiledDocument();
|
|
294
|
+
if (!document) return null;
|
|
295
|
+
const files = selectIslandPreloads(resourcePreviewCandidates(document, basePath(publication), true), {
|
|
296
|
+
bytes: 65536,
|
|
297
|
+
requests: 6
|
|
298
|
+
});
|
|
299
|
+
return files.length ? {
|
|
300
|
+
revision: publication.manifest.buildRevision,
|
|
301
|
+
files
|
|
302
|
+
} : null;
|
|
303
|
+
},
|
|
304
|
+
/** The build revision of the public publication this render reads. */
|
|
305
|
+
async getBuildRevision() {
|
|
306
|
+
return (await publicViewForRender()).manifest.buildRevision;
|
|
307
|
+
},
|
|
308
|
+
async getMetadata(slug) {
|
|
309
|
+
const { publication, entry, lookup } = await publicPage(slug);
|
|
310
|
+
return metadata(publication, entry, basePath(publication), lookup.languages);
|
|
311
|
+
},
|
|
312
|
+
async generateStaticParams({ excludeNative = false } = {}) {
|
|
313
|
+
const publication = await settings.publicPublication();
|
|
314
|
+
const pages = publication.manifest.documents;
|
|
315
|
+
if (!excludeNative) return pages.map((entry) => routeParams(entry.route));
|
|
316
|
+
return (await Promise.all(pages.map(async (entry) => entry.route !== "/" && !(publication.hasNativeView ? await publication.hasNativeView(entry) : (await publication.readDocument(entry)).nativeView) ? routeParams(entry.route) : void 0))).filter((entry) => entry !== void 0);
|
|
317
|
+
},
|
|
318
|
+
async getResourceAsset(path, request) {
|
|
319
|
+
return assetFor(await settings.publicPublication(), resourcePath(path), request, false);
|
|
320
|
+
},
|
|
321
|
+
async getDiscoveryAsset(path, request) {
|
|
322
|
+
const name = /^(?:robots\.txt|sitemap(?:-[1-9][0-9]*)?\.xml)$/.test(path) ? path : void 0;
|
|
323
|
+
return assetFor(await settings.publicPublication(), name, request, false);
|
|
324
|
+
},
|
|
325
|
+
async getRedirect(slug) {
|
|
326
|
+
const { publication, entry } = await publicPage(slug);
|
|
327
|
+
if (!entry) return publication.manifest.redirects?.find((item) => item.from === route(slug))?.to;
|
|
328
|
+
},
|
|
329
|
+
async getAgentContext(slug, section) {
|
|
330
|
+
const { lookup, entry } = await publicPage(slug);
|
|
331
|
+
return contextFor(lookup.runtime, entry, section);
|
|
332
|
+
},
|
|
333
|
+
async resolveFact(...args) {
|
|
334
|
+
return publicIndex(await settings.publicPublication()).runtime.facts.resolve(...args);
|
|
335
|
+
},
|
|
336
|
+
async search(text, options) {
|
|
337
|
+
return publicIndex(await settings.publicPublication()).runtime.search(text, options);
|
|
338
|
+
},
|
|
339
|
+
async getMarkdown(slug) {
|
|
340
|
+
const { lookup, entry } = await publicPage(slug);
|
|
341
|
+
return markdownFor(lookup.runtime, entry);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Refresh open pages in place after `devNext` rebuilds the publication. Render it once in the root layout. It renders
|
|
347
|
+
* nothing in production or outside `devNext`, and production builds leave its client code out.
|
|
348
|
+
*/
|
|
349
|
+
async function DocsDevRefresh({ docs }) {
|
|
350
|
+
if (process.env.NODE_ENV !== "production") {
|
|
351
|
+
const url = process.env.DOCS_SDK_DEV_EVENTS;
|
|
352
|
+
if (url) {
|
|
353
|
+
const { DevRefresh } = await import("./dev-refresh.js");
|
|
354
|
+
return createElement(DevRefresh, {
|
|
355
|
+
url,
|
|
356
|
+
revision: await docs.getBuildRevision()
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export { DocsDevRefresh, DocsMetadata, createDocs, openAccessPublication, openPublication, publicPublication, toNextMetadata };
|
|
364
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","names":["createDocsApplication"],"sources":["../src/server.ts"],"sourcesContent":["import \"server-only\"\nimport type { Labels } from \"@docs-sdk-dev/web/internal/labels-runtime\"\nimport { headers } from \"next/headers.js\"\nimport { connection } from \"next/server.js\"\nimport type { Metadata } from \"next\"\nimport { cache, createElement, type ReactNode } from \"react\"\nimport {\n isSourceAssetPath,\n localeAlternates,\n type Document,\n type ResolvedMetadata,\n} from \"@docs-sdk-dev/core\"\nimport {\n isPublicationPath,\n localeDimension,\n type Manifest,\n type PublishedMarkdownRead,\n} from \"@docs-sdk-dev/reader\"\nimport { type NativePageModule, type PresentedPage } from \"@docs-sdk-dev/react/server\"\nimport {\n createPageContextPresenter,\n type DocsRequestPreferences,\n} from \"@docs-sdk-dev/web/context-bridge\"\nimport { createDocs as createDocsApplication } from \"@docs-sdk-dev/web/application\"\nimport {\n publicResourceAssetResponse,\n resourceAssetHeaders,\n} from \"@docs-sdk-dev/node/internal/web-serving\"\nimport { isAccessPrefetch } from \"@docs-sdk-dev/core/access\"\nimport { selectIslandPreloads } from \"@docs-sdk-dev/web/island-plan\"\nimport { type IslandResource } from \"@docs-sdk-dev/web/islands\"\nimport { resourcePreviewCandidates } from \"@docs-sdk-dev/web/resource-preview\"\nimport { createDocsRuntime, type DocsRuntime, type RuntimeReader } from \"@docs-sdk-dev/web/runtime\"\nimport { toNextMetadata } from \"./metadata.js\"\n\ntype PageEntry = Manifest[\"documents\"][number]\ntype Awaitable<T> = T | Promise<T>\n\nexport { openAccessPublication, openPublication, publicPublication } from \"./publication.js\"\nexport { DocsMetadata, toNextMetadata } from \"./metadata.js\"\n\nexport interface NativeViews {\n revision: string\n modules: Readonly<Record<string, () => Promise<NativePageModule>>>\n}\n\ninterface RouteView {\n revision: string\n module: string\n view: NativePageModule\n}\n\nexport interface DocsPublication extends RuntimeReader {\n accessRequired?: boolean\n readDocument(page: PageEntry): Awaitable<Document>\n readLabels?(locale: string): Labels\n readNativeView?(path: string): Awaitable<NativePageModule | undefined>\n readOgResource?(path: string, request?: Request): Awaitable<Response | undefined>\n serveMcp?(request: Request): Awaitable<Response>\n}\n\n/**\n * Under `devNext`, a refresh can read a new publication before Next recompiles the generated route that names its\n * revision. That route already imports the current source module, so only its revision lags, and Next refreshes the\n * page again once it compiles.\n */\nconst followsDevBuilds = () =>\n process.env.NODE_ENV !== \"production\" && Boolean(process.env.DOCS_SDK_DEV_EVENTS)\n\nfunction route(slug: readonly string[]) {\n const parts = slug.map((part) => encodeURIComponent(part))\n return parts.length ? \"/\" + parts.join(\"/\") + \"/\" : \"/\"\n}\n\nfunction routeParams(path: string) {\n return { slug: path.split(\"/\").filter(Boolean).map(decodeURIComponent) }\n}\n\nfunction index(\n publication: DocsPublication,\n base?: string,\n runtime = createDocsRuntime({ reader: publication }),\n) {\n const { manifest } = publication\n const routes = new Map(\n manifest.documents.map((page) => [route(routeParams(page.route).slug), page]),\n )\n const presentContext = createPageContextPresenter(manifest, base)\n let languages: ReturnType<typeof localeAlternates> | undefined\n return {\n routes,\n runtime,\n presentContext,\n languages: () =>\n (languages ??= localeAlternates(\n manifest.documents,\n localeDimension(manifest.dimensionPolicy),\n manifest.dimensionPolicy?.defaultLocale,\n )),\n }\n}\n\nfunction metadata(\n publication: DocsPublication,\n page: PageEntry | undefined,\n base: string,\n languages: ReturnType<typeof index>[\"languages\"],\n): Metadata {\n if (!page) return {}\n const resolved = pageMetadata(publication, page)\n if (resolved) return toNextMetadata(resolved)\n const alternates = languages().get(page.key)\n return {\n title: page.title,\n description: page.description,\n alternates: {\n canonical: base + page.route,\n ...(alternates && {\n languages: Object.fromEntries(alternates.map((item) => [item.locale, base + item.route])),\n }),\n },\n }\n}\n\nfunction pageMetadata(publication: DocsPublication, page: PageEntry) {\n const values = publication.metadata\n return values && Object.hasOwn(values, page.key) ? values[page.key] : undefined\n}\n\nconst protectedMetadata: Metadata = {\n title: null,\n description: null,\n alternates: null,\n openGraph: null,\n twitter: null,\n robots: { index: false, follow: false, noarchive: true },\n}\n\nfunction privateResponse(body: BodyInit | null, init: ResponseInit = {}) {\n const result = new Headers(init.headers)\n result.set(\"cache-control\", \"private, no-store\")\n const vary = new Set(\n result\n .get(\"vary\")\n ?.toLowerCase()\n .split(/\\s*,\\s*/),\n )\n if (!vary.has(\"*\")) {\n vary.add(\"authorization\")\n vary.add(\"cookie\")\n result.set(\"vary\", [...vary].join(\", \"))\n }\n result.delete(\"etag\")\n result.delete(\"last-modified\")\n return new Response(body, { ...init, headers: result })\n}\n\nexport function createDocs(settings: {\n publicPublication(): Awaitable<DocsPublication>\n /** Open a filtered publication for a verified host request and the current public revision. */\n accessPublication?(request: Request, publicRevision: string): Awaitable<DocsPublication>\n basePath?: string\n /** Resolve an application-owned, verified preference namespace for one request. */\n persistenceForRequest?(request: Request): Awaitable<DocsRequestPreferences | undefined>\n}) {\n const application = createDocsApplication({\n publication: settings.publicPublication,\n host: {\n async access(request, publicView) {\n if (\n isAccessPrefetch(request) ||\n publicView.accessRequired === false ||\n !settings.accessPublication\n )\n return { publication: publicView }\n const publication = await settings.accessPublication(\n request,\n publicView.manifest.buildRevision,\n )\n return { publication }\n },\n persistence: settings.persistenceForRequest,\n },\n })\n const publicViewForRender = cache(async () => settings.publicPublication())\n const publicIndexes = new WeakMap<DocsPublication, ReturnType<typeof index>>()\n function publicIndex(publication: DocsPublication) {\n let lookup = publicIndexes.get(publication)\n if (!lookup) {\n lookup = index(publication, basePath(publication))\n publicIndexes.set(publication, lookup)\n }\n return lookup\n }\n function basePath(publication: DocsPublication) {\n return settings.basePath ?? publication.manifest.basePath ?? \"\"\n }\n async function publicPage(slug: readonly string[]) {\n const publication = await publicViewForRender()\n const lookup = publicIndex(publication)\n return { publication, lookup, entry: lookup.routes.get(route(slug)) }\n }\n async function present(\n publication: DocsPublication,\n lookup: ReturnType<typeof index>,\n entry: PageEntry | undefined,\n {\n private: restricted,\n routeView,\n metadata: resolvedMetadata,\n request,\n preferences,\n }: {\n private?: true\n routeView?: RouteView\n metadata?: ResolvedMetadata\n request?: Request\n preferences?: () => Awaitable<DocsRequestPreferences | undefined>\n } = {},\n ): Promise<PresentedPage | null> {\n if (!entry) return null\n const page = pageFor(lookup.runtime, entry)\n if (!page) return null\n const document = await page.loadCompiledDocument({ signal: request?.signal })\n if (!document) return null\n const context = page.readContext()\n const prepared =\n context &&\n (await lookup.presentContext(document.identity, context, {\n request,\n restricted,\n preferences: await preferences?.(),\n }))\n const { personalized, ...pageContext } = prepared ?? {}\n if (\n routeView &&\n ((routeView.revision !== publication.manifest.buildRevision && !followsDevBuilds()) ||\n routeView.module !== document.nativeView?.module)\n )\n return null\n const native =\n routeView?.view ??\n (document.nativeView && (await publication.readNativeView?.(document.nativeView.module)))\n if (document.nativeView && !native?.default && !restricted)\n throw new Error(`No native view in this publication for ${entry.route}.`)\n if (\n restricted &&\n native?.default &&\n Reflect.get(native.default, \"$$typeof\") === Symbol.for(\"react.client.reference\")\n )\n throw new Error(`The protected native view for ${entry.route} must be a Server Component.`)\n if (\n native &&\n document.nativeView?.layout === \"custom\" &&\n (!native.Layout ||\n Reflect.get(native.Layout, \"$$typeof\") === Symbol.for(\"react.client.reference\"))\n )\n throw new Error(\n `The native Layout for ${entry.route} must be a Server Component. Place \"use client\" components inside the layout instead.`,\n )\n return {\n document,\n navigation: page.navigation,\n outline: page.outline,\n locale: page.locale,\n themeLabels: publication.readLabels?.(page.locale),\n basePath: basePath(publication),\n ...(native?.default && { native }),\n ...pageContext,\n ...(restricted && { private: true }),\n ...(resolvedMetadata && { metadata: resolvedMetadata }),\n ...(page.capabilities.resources && { resourceBase: basePath(publication) }),\n }\n }\n\n function pageFor(runtime: DocsRuntime, entry: PageEntry | undefined) {\n if (!entry) return\n const page = runtime.resolvePage({ identity: entry.identity, match: \"exact\" })\n return page.status === \"exact\" ? page : undefined\n }\n\n async function contextFor(\n runtime: DocsRuntime,\n entry: PageEntry | undefined,\n section?: string,\n ): Promise<(PublishedMarkdownRead & { buildRevision: string }) | null> {\n const page = pageFor(runtime, entry)\n const excerpt = await page?.read(section)\n return page && excerpt ? { ...excerpt, buildRevision: page.revision } : null\n }\n\n async function markdownFor(runtime: DocsRuntime, entry: PageEntry | undefined) {\n return (await pageFor(runtime, entry)?.read())?.markdown\n }\n\n function resourcePath(path: readonly string[]) {\n const name = [\"resource-assets\", ...path].join(\"/\")\n return path.length && path.every((part) => !part.includes(\"/\")) && isSourceAssetPath(name)\n ? name\n : undefined\n }\n\n async function assetFor(\n publication: DocsPublication,\n name: string | undefined,\n request: Request | undefined,\n isPrivate: boolean,\n ) {\n const missing = () =>\n isPrivate ? privateResponse(null, { status: 404 }) : new Response(null, { status: 404 })\n if (!name || !isPublicationPath(name)) return missing()\n const asset = await publication.readResource?.(name)\n if (!asset)\n return (!isPrivate && (await publication.readOgResource?.(name, request))) || missing()\n if (!isPrivate) return publicResourceAssetResponse(name, asset, request)\n return privateResponse(\n request?.method === \"HEAD\" ? null : Buffer.from(asset.base64, \"base64\"),\n {\n headers: {\n ...resourceAssetHeaders(name),\n \"content-security-policy\": \"sandbox; default-src 'none'\",\n },\n },\n )\n }\n\n async function forRequest(request: Request) {\n await connection()\n const scope = await application.forRequest(request)\n const { publicView, publication, runtime } = scope\n // This host always serves a filtered view, even when it contains no eligible pages.\n if (!publication || !runtime)\n throw new Error(\"The Next documentation request scope was denied.\")\n let lookup: ReturnType<typeof index> | undefined\n function entryFor(slug: readonly string[]) {\n scope.signal.throwIfAborted()\n lookup ??= index(publication!, basePath(publication!), runtime)\n return { lookup, entry: lookup.routes.get(route(slug)) }\n }\n function publicEntryFor(slug: readonly string[], entry: PageEntry | undefined) {\n if (!entry) return\n const publicEntry = publicIndex(publicView).routes.get(route(slug))\n return publicEntry?.key === entry.key ? publicEntry : undefined\n }\n return {\n manifest: publication.manifest,\n /** A runtime over the same filtered Reader and resource indexes as the page. */\n runtime,\n signal: scope.signal,\n dispose: scope.dispose,\n reader: runtime.reader,\n async getPage(slug: readonly string[]) {\n const { lookup, entry } = entryFor(slug)\n const publicEntry = publicEntryFor(slug, entry)\n return present(publication, lookup, entry, {\n private: true,\n request,\n preferences: scope.preferences,\n metadata: publicEntry && pageMetadata(publicView, publicEntry),\n })\n },\n getMetadata(slug: readonly string[]) {\n const publicEntry = publicEntryFor(slug, entryFor(slug).entry)\n return publicEntry\n ? metadata(\n publicView,\n publicEntry,\n basePath(publicView),\n publicIndex(publicView).languages,\n )\n : protectedMetadata\n },\n getRedirect(slug: readonly string[]) {\n if (!entryFor(slug).entry)\n return publication.manifest.redirects?.find((item) => item.from === route(slug))?.to\n },\n getAgentContext(slug: readonly string[], section?: string) {\n return contextFor(runtime, entryFor(slug).entry, section)\n },\n getMarkdown(slug: readonly string[]) {\n return markdownFor(runtime, entryFor(slug).entry)\n },\n async resolveFact(...args: Parameters<NonNullable<DocsPublication[\"resolve\"]>>) {\n return runtime.facts.resolve(...args)\n },\n async search(text: string, options?: Parameters<NonNullable<DocsPublication[\"search\"]>>[1]) {\n return runtime.search(text, options)\n },\n getResourceAsset(path: readonly string[]) {\n scope.signal.throwIfAborted()\n return assetFor(publication, resourcePath(path), request, true)\n },\n getAsset(path: string) {\n scope.signal.throwIfAborted()\n return assetFor(publication, path, request, true)\n },\n async mcp() {\n scope.signal.throwIfAborted()\n const response = await publication.serveMcp?.(request)\n scope.signal.throwIfAborted()\n if (!response || response.status === 304) return privateResponse(null, { status: 404 })\n return privateResponse(response.body, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n })\n },\n response: privateResponse,\n }\n }\n\n // React's server cache is request-local, so page metadata and body share an authorization decision.\n const pageView = cache(async (href: string) =>\n forRequest(new Request(href, { headers: await headers() })),\n )\n\n return {\n forRequest,\n /** Use the incoming Next headers with a URL from the application's trusted origin. */\n forPage(url: URL) {\n return pageView(url.href)\n },\n async getPage(slug: readonly string[], routeView?: RouteView) {\n const { publication, lookup, entry } = await publicPage(slug)\n return present(publication, lookup, entry, {\n routeView,\n metadata: entry && pageMetadata(publication, entry),\n })\n },\n /** Render a cookie-aware public page without placing its HTML in an ISR cache. */\n async getPageForRequest(slug: readonly string[], request: Request, routeView?: RouteView) {\n await connection()\n const { publication, lookup, entry } = await publicPage(slug)\n return present(publication, lookup, entry, {\n routeView,\n request,\n preferences: () => settings.persistenceForRequest?.(request),\n metadata: entry && pageMetadata(publication, entry),\n })\n },\n /** Read a bounded, navigation-only plan from the public publication. Request views cannot produce this plan. */\n async getIslandPreloadPlan(slug: readonly string[]): Promise<IslandResource | null> {\n const { publication, entry, lookup } = await publicPage(slug)\n if (!publication.readResource) return null\n const document = await pageFor(lookup.runtime, entry)?.loadCompiledDocument()\n if (!document) return null\n const files = selectIslandPreloads(\n resourcePreviewCandidates(document, basePath(publication), true),\n {\n bytes: 64 * 1024,\n requests: 6,\n },\n )\n return files.length ? { revision: publication.manifest.buildRevision, files } : null\n },\n /** The build revision of the public publication this render reads. */\n async getBuildRevision() {\n return (await publicViewForRender()).manifest.buildRevision\n },\n async getMetadata(slug: readonly string[]) {\n const { publication, entry, lookup } = await publicPage(slug)\n return metadata(publication, entry, basePath(publication), lookup.languages)\n },\n async generateStaticParams({ excludeNative = false }: { excludeNative?: boolean } = {}) {\n const publication = await settings.publicPublication()\n const pages = publication.manifest.documents\n if (!excludeNative) return pages.map((entry) => routeParams(entry.route))\n const eligible = await Promise.all(\n pages.map(async (entry) =>\n entry.route !== \"/\" &&\n !(publication.hasNativeView\n ? await publication.hasNativeView(entry)\n : (await publication.readDocument(entry)).nativeView)\n ? routeParams(entry.route)\n : undefined,\n ),\n )\n return eligible.filter((entry) => entry !== undefined)\n },\n async getResourceAsset(path: readonly string[], request?: Request) {\n return assetFor(await settings.publicPublication(), resourcePath(path), request, false)\n },\n async getDiscoveryAsset(path: string, request?: Request) {\n const name = /^(?:robots\\.txt|sitemap(?:-[1-9][0-9]*)?\\.xml)$/.test(path) ? path : undefined\n return assetFor(await settings.publicPublication(), name, request, false)\n },\n async getRedirect(slug: readonly string[]) {\n const { publication, entry } = await publicPage(slug)\n if (!entry)\n return publication.manifest.redirects?.find((item) => item.from === route(slug))?.to\n },\n async getAgentContext(slug: readonly string[], section?: string) {\n const { lookup, entry } = await publicPage(slug)\n return contextFor(lookup.runtime, entry, section)\n },\n async resolveFact(...args: Parameters<NonNullable<DocsPublication[\"resolve\"]>>) {\n return publicIndex(await settings.publicPublication()).runtime.facts.resolve(...args)\n },\n async search(text: string, options?: Parameters<NonNullable<DocsPublication[\"search\"]>>[1]) {\n return publicIndex(await settings.publicPublication()).runtime.search(text, options)\n },\n async getMarkdown(slug: readonly string[]) {\n const { lookup, entry } = await publicPage(slug)\n return markdownFor(lookup.runtime, entry)\n },\n }\n}\n\n/**\n * Refresh open pages in place after `devNext` rebuilds the publication. Render it once in the root layout. It renders\n * nothing in production or outside `devNext`, and production builds leave its client code out.\n */\nexport async function DocsDevRefresh({\n docs,\n}: {\n docs: Pick<ReturnType<typeof createDocs>, \"getBuildRevision\">\n}): Promise<ReactNode> {\n // Compare with the literal so bundlers drop the dev-only client module from production output.\n if (process.env.NODE_ENV !== \"production\") {\n const url = process.env.DOCS_SDK_DEV_EVENTS\n if (url) {\n const { DevRefresh } = await import(\"./dev-refresh.js\")\n return createElement(DevRefresh, { url, revision: await docs.getBuildRevision() })\n }\n }\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAM,yBACJ,QAAQ,IAAI,aAAa,gBAAgB,QAAQ,QAAQ,IAAI,mBAAmB;AAElF,SAAS,MAAM,MAAyB;CACtC,MAAM,QAAQ,KAAK,KAAK,SAAS,mBAAmB,IAAI,CAAC;CACzD,OAAO,MAAM,SAAS,MAAM,MAAM,KAAK,GAAG,IAAI,MAAM;AACtD;AAEA,SAAS,YAAY,MAAc;CACjC,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,IAAI,kBAAkB,EAAE;AACzE;AAEA,SAAS,MACP,aACA,MACA,UAAU,kBAAkB,EAAE,QAAQ,YAAY,CAAC,GACnD;CACA,MAAM,EAAE,aAAa;CACrB,MAAM,SAAS,IAAI,IACjB,SAAS,UAAU,KAAK,SAAS,CAAC,MAAM,YAAY,KAAK,KAAK,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAC9E;CACA,MAAM,iBAAiB,2BAA2B,UAAU,IAAI;CAChE,IAAI;CACJ,OAAO;EACL;EACA;EACA;EACA,iBACG,cAAc,iBACb,SAAS,WACT,gBAAgB,SA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;GACnF,OAAO,SAAS,MAAM,SAAS,kBAAkB,GAAG,MAAM,SAAS,KAAK;EAC1E;EACA,MAAM,YAAY,MAAyB;GACzC,MAAM,EAAE,aAAa,UAAU,MAAM,WAAW,IAAI;GACpD,IAAI,CAAC,OACH,OAAO,YAAY,SAAS,WAAW,MAAM,SAAS,KAAK,SAAS,MAAM,IAAI,CAAC,CAAC,EAAE;EACtF;EACA,MAAM,gBAAgB,MAAyB,SAAkB;GAC/D,MAAM,EAAE,QAAQ,UAAU,MAAM,WAAW,IAAI;GAC/C,OAAO,WAAW,OAAO,SAAS,OAAO,OAAO;EAClD;EACA,MAAM,YAAY,GAAG,MAA2D;GAC9E,OAAO,YAAY,MAAM,SAAS,kBAAkB,CAAC,CAAC,CAAC,QAAQ,MAAM,QAAQ,GAAG,IAAI;EACtF;EACA,MAAM,OAAO,MAAc,SAAiE;GAC1F,OAAO,YAAY,MAAM,SAAS,kBAAkB,CAAC,CAAC,CAAC,QAAQ,OAAO,MAAM,OAAO;EACrF;EACA,MAAM,YAAY,MAAyB;GACzC,MAAM,EAAE,QAAQ,UAAU,MAAM,WAAW,IAAI;GAC/C,OAAO,YAAY,OAAO,SAAS,KAAK;EAC1C;CACF;AACF;;;;;AAMA,eAAsB,eAAe,EACnC,QAGqB;CAErB,IAAI,QAAQ,IAAI,aAAa,cAAc;EACzC,MAAM,MAAM,QAAQ,IAAI;EACxB,IAAI,KAAK;GACP,MAAM,EAAE,eAAe,MAAM,OAAO;GACpC,OAAO,cAAc,YAAY;IAAE;IAAK,UAAU,MAAM,KAAK,iBAAiB;GAAE,CAAC;EACnF;CACF;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Next.js native preview
|
|
2
|
+
|
|
3
|
+
## Run the preview
|
|
4
|
+
|
|
5
|
+
This example requires a running Next.js App Router host. From the repository root, build the workspace and start the example.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun install --frozen-lockfile
|
|
9
|
+
bun run build:packages
|
|
10
|
+
cd examples/next
|
|
11
|
+
bun run build
|
|
12
|
+
bun run start
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Open [the native authoring example](http://localhost:3000/guide/native-author/). The document heading and portable body are in the initial HTML. Choose a published guide and submit the form. Next.js sends a Server Action request, and the action reads the built Docs SDK publication on the server and returns the selected title. The separate counter updates in the browser.
|
|
16
|
+
|
|
17
|
+
## Source and execution
|
|
18
|
+
|
|
19
|
+
The [Server Component](https://github.com/LioRael/docs-sdk/blob/main/examples/next/content/pages/guide/native-author.tsx) declares the portable document body and renders it through the Framework. The [Client Component](https://github.com/LioRael/docs-sdk/blob/main/examples/next/content/pages/guide/_components/author-counter.tsx) owns the counter and the form state. The [Server Action](https://github.com/LioRael/docs-sdk/blob/main/examples/next/content/pages/guide/_components/author-action.ts) resolves the selected guide through the same public publication the App Router uses. The fixture [README](https://github.com/LioRael/docs-sdk/tree/main/examples/next) covers the rest of the application and deployment.
|
|
20
|
+
|
|
21
|
+
For previews of ordinary client components, the Next.js selection uses the corresponding React module. The App Router preview on this page runs in the separate Next.js application.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Choose a Web host
|
|
2
|
+
|
|
3
|
+
Keep your semantic content, templates, source declarations and dimension policy in one Docs SDK project. [TypeScript content](https://docs-sdk.dev/site/authoring/#build-a-semantic-page-in-typescript) works across hosts. Write native TSX with your host's framework. Choose a host for routing, rendering and interactivity.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
This Next.js adapter is available from the source workspace. Pack one Docs SDK checkout and use its starter and tarballs together.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
bun install --frozen-lockfile
|
|
11
|
+
bundle=$(mktemp -d)
|
|
12
|
+
bun run release:pack "$bundle"
|
|
13
|
+
node packages/create/dist/cli.js handbook --framework next
|
|
14
|
+
cd handbook
|
|
15
|
+
npm install "$bundle"/create-docs-sdk-*.tgz "$bundle"/docs-sdk-dev-cli-*.tgz \
|
|
16
|
+
"$bundle"/docs-sdk-dev-core-*.tgz "$bundle"/docs-sdk-dev-reader-*.tgz \
|
|
17
|
+
"$bundle"/docs-sdk-dev-web-*.tgz "$bundle"/docs-sdk-dev-node-*.tgz \
|
|
18
|
+
"$bundle"/docs-sdk-dev-react-*.tgz "$bundle"/docs-sdk-dev-next-*.tgz
|
|
19
|
+
npm run typecheck
|
|
20
|
+
npm run build
|
|
21
|
+
npm run start
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For an existing application, install the host adapter and its Docs SDK dependencies from the same bundle. If you already have a compiled publication, open it from the host. Adapter-only applications can consume that publication without installing the CLI.
|
|
25
|
+
|
|
26
|
+
Run the [native App Router preview](https://docs-sdk.dev/framework/hosts/next-native-preview/?ctx.framework=next) to see a Server Action resolve a guide from the published runtime.
|
|
27
|
+
|
|
28
|
+
The generated build runs `docs prepare-web` before `next build`. Add an existing publication to an App Router project with `createDocs` and `publicPublication` from `@docs-sdk-dev/next/server`. Call `generateStaticParams` for public guides and `getMetadata` for their titles and canonical routes. Import `@docs-sdk-dev/next/styles.css` in the root layout for the default styles, including on webpack builds.
|
|
29
|
+
|
|
30
|
+
The generated `npm run dev` calls `devNext` from `@docs-sdk-dev/next/build`. It rebuilds the publication when a content file changes and starts `next dev`. Render `<DocsDevRefresh docs={docs} />` from `@docs-sdk-dev/next/server` once in the root layout. After each rebuild, open pages refresh in place and keep their scroll position and client state. A failed rebuild keeps the last good page and shows the error until a fix lands. The component renders nothing in production. When a rebuild reaches no open page and the root layout doesn't name `DocsDevRefresh`, `devNext` prints once how to add it.
|
|
31
|
+
|
|
32
|
+
Pass the page returned by `getPage` to `DocsPage` to carry its Context automatically. Keep native route components and their loaders on the server. Place event handlers in Client Components and pass them public, serializable props. Define cross-framework preview loaders in a Client Component and import each framework only when its island is activated. When deploying to Vercel, trace the compiled publication with the application and verify the preview before using it for live traffic.
|
|
33
|
+
|
|
34
|
+
The Next starter generates App Router entries for public native pages, so a Client Component used by one page stays out of the initial scripts for unrelated guides. An existing App Router can opt in through the `NativeRoutes` argument to `buildPublication` and `buildNext`. Share a host module exporting `docs` and `renderDocsPage`, then use `docs.generateStaticParams({ excludeNative: true })` in the catch-all route. Reserve `app/(docs-sdk-native)` for generated entries.
|
|
35
|
+
|
|
36
|
+
Register resource profiles in `resourceSource({ buildProfiles })`. Use `esbuildBuildProfile()` from `@docs-sdk-dev/next/build-profile` for captured JavaScript, TypeScript and CSS inputs, or supply your own `defineBuildProfile()` adapter. A profile with a portable Markdown fallback can expose a trusted interactive preview through an `Example` reference. The Next starter serves published profile assets and checks prerendered HTML as part of `npm run build`.
|
|
37
|
+
|
|
38
|
+
Use packages from the same Docs SDK release or source checkout. If a host generates a compiled publication for server rendering, keep that file outside public assets. The public loader supplies static generation, search and Markdown.
|
|
39
|
+
|
|
40
|
+
## Compose a document
|
|
41
|
+
|
|
42
|
+
Compose `Document.Root`, `Document.Title`, `Document.Description` and `Document.Content` with your own layout. Use the resolved document for the active route. A custom server layout can render a selected `Document.Section`, inspect `Document.Metadata` and `Document.Source`, show `Document.LastUpdated`, or build a host-owned `Document.EditLink`.
|
|
43
|
+
|
|
44
|
+
```tsx react
|
|
45
|
+
import { Document } from "@docs-sdk-dev/react/document"
|
|
46
|
+
import type { Document as CompiledDocument } from "@docs-sdk-dev/core"
|
|
47
|
+
|
|
48
|
+
export function HelpArticle({ document }: { document: CompiledDocument }) {
|
|
49
|
+
return (
|
|
50
|
+
<Document.Root>
|
|
51
|
+
<Document.Title document={document} />
|
|
52
|
+
<Document.Description document={document} />
|
|
53
|
+
<Document.Content document={document} />
|
|
54
|
+
</Document.Root>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
For an embedded client that owns a Reader, place a `DocsProvider` above `Document.Root identity="guide/install"`. The [Solid parts](https://docs-sdk.dev/reference/api/solid-document/) and [React client parts](https://docs-sdk.dev/reference/api/react-document-client/) resolve the document through that runtime. Use a root fallback for unavailable editions, and a content loading or error fallback for asynchronous reads.
|
|
60
|
+
|
|
61
|
+
See [Outline, reading and feedback](https://docs-sdk.dev/framework/reading/). Arrange a published semantic outline with `Outline.Root`, `Outline.List` and links built from the resolved anchors. For a custom server layout, enable `trackOutline` on `Document.Root` to bind scroll tracking. Mark a nested scroller with `data-docs-scroll-root` when it owns scrolling. `Reading` exposes progress and preferences, and `Feedback` uses a submission callback supplied by the host. Links and the published article remain available before JavaScript loads.
|
|
62
|
+
|
|
63
|
+
## Share a theme across hosts
|
|
64
|
+
|
|
65
|
+
Use the same theme tokens and styles across hosts. Both adapters export `defineTokens`, `resolveTheme` and `themeTokenStyles`. A native theme can inherit tokens and override one scheme for one token. Site applies these tokens when it builds its stylesheet. In React or Next.js, render `themeTokenStyles(resolveTheme({}, theme.tokens))` in the host stylesheet or document head. Call `defineTheme()` from the native adapter when you need to override a region, layout, or content renderer. The layout receives named regions such as `header`, `navigation`, `article`, `outline` and `footer`. A custom layout can compose these with the host's own navigation and controls. Shared Web models resolve navigation, search results and context-dependent choices, while each adapter renders native components. Next.js uses the React adapter.
|
|
66
|
+
|
|
67
|
+
For a custom search surface, use `Search.Root`, `Search.Input`, `Search.Item` and `Search.Footer` with the shared search store or your own async backend. Use a named navigation view for the sidebar or header and leave its link URLs available in the server markup.
|
|
68
|
+
|
|
69
|
+
Import search parts from `@docs-sdk-dev/react/search` and native code parts from `@docs-sdk-dev/react/content/client`.
|
|
70
|
+
|
|
71
|
+
Use the published page and Context contract as the input for edition links, bound tabs and previews. Let the host router handle document links, keeping their `href` available in server-rendered HTML. Test the host's keyboard flow and narrow layout with the same document before adding custom controls. The host sets response headers and cache policy.
|
|
72
|
+
|
|
73
|
+
A [published `products` view](https://docs-sdk.dev/site/navigation/#group-a-site-by-product) drives the default page shell. It scopes the sidebar, adjacent page links and initial search to the active product or section. The starters forward the optional `product` value from the search dialog. A custom search endpoint can pass that value to `publication.search(query, { product })` using the request’s authorized publication.
|
|
74
|
+
|
|
75
|
+
## Reuse a host session
|
|
76
|
+
|
|
77
|
+
Use the same [access definition](https://docs-sdk.dev/site/access/) that a Docs Site uses. Compile the public and server-only inputs before building the application.
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
docs prepare-web --private-output .docs-sdk/private-publication.json
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Pass the server-only file to `openAccessPublication(file, access)` in `@docs-sdk-dev/next/server`, then pass the resulting loader as `accessPublication` to `createDocs`. The public loader continues to power static parameters and public metadata. Call `docs.forRequest(request)` on a dynamic route before reading protected pages, metadata, search, facts, Markdown, Agent context or assets. The request view exposes its filtered `reader` and, for compiled publications, a `runtime` for Server Components. Use `docs.forPage(url)` to share the request-scoped view between an App Router page and its metadata. Return API responses with the request view’s response helper so both allowed and denied results carry private cache headers. Keep the server file in the deployment’s function trace and outside any public asset path. A static export cannot host the protected routes.
|
|
84
|
+
|
|
85
|
+
To combine generated native routes and an access-aware publication, pass `{ nativeRoutes, privateOutput }` to `buildPublication` and `buildNext`. The generated routes and registry contain public views. Supply a trusted server-only loader on the authorized publication for a protected View. The SDK selects it only after resolving the page for the request and checking the revision. When access filtering redacts the View's inputs, render the authorized semantic body instead. Keep protected values in Server Components and pass only public props to client controls.
|
|
86
|
+
|
|
87
|
+
## Activate a component from an installed extension
|
|
88
|
+
|
|
89
|
+
An extension can give a component a portable Markdown projection and a separate browser entry with `source.packageModule()`. Publish the client entry as JavaScript for its declared framework. Let the consumer install the matching framework runtime through the package's peer dependencies. The generated Solid Site, React and Next.js hosts register published package components automatically. Use the same activation file and MDX in each host.
|
|
90
|
+
|
|
91
|
+
The browser entry loads according to the component's activation policy. With `activation: "interaction"`, readers see the portable projection and can open the interactive component on demand. Context access stays scoped to the host's grants. Components used exclusively in protected documents stay out of the public React and Next.js client registry and retain their portable projection in those hosts.
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Docs SDK guides (@docs-sdk-dev/next 0.4.0-next.0)
|
|
2
|
+
|
|
3
|
+
Read the guide for your task and verify API signatures in the installed package declarations.
|
|
4
|
+
|
|
5
|
+
- [Choose a Web host](./framework/hosts.md)
|
|
6
|
+
- [Next.js 原生预览](./zh-CN/framework/hosts/next-native-preview.md)
|
|
7
|
+
- [Next.js native preview](./framework/hosts/next-native-preview.md)
|
|
8
|
+
- [选择 Web 宿主](./zh-CN/framework/hosts.md)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Next.js 原生预览
|
|
2
|
+
|
|
3
|
+
## 运行预览
|
|
4
|
+
|
|
5
|
+
此示例需要运行 Next.js App Router 宿主。从仓库根目录构建工作区,再启动示例。
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun install --frozen-lockfile
|
|
9
|
+
bun run build:packages
|
|
10
|
+
cd examples/next
|
|
11
|
+
bun run build
|
|
12
|
+
bun run start
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
打开[原生文档示例](http://localhost:3000/guide/native-author/)。初始 HTML 已包含文档标题和可移植正文。选择一篇已发布的指南并提交表单。Next.js 发出 Server Action 请求,操作在服务端读取 Docs SDK 发布物,返回所选指南的标题。独立的计数器在浏览器中更新。
|
|
16
|
+
|
|
17
|
+
## 源码与运行环境
|
|
18
|
+
|
|
19
|
+
[Server Component](https://github.com/LioRael/docs-sdk/blob/main/examples/next/content/pages/guide/native-author.tsx)声明可移植正文并通过 Framework 渲染。[Client Component](https://github.com/LioRael/docs-sdk/blob/main/examples/next/content/pages/guide/_components/author-counter.tsx)管理计数器和表单状态。[Server Action](https://github.com/LioRael/docs-sdk/blob/main/examples/next/content/pages/guide/_components/author-action.ts)从 App Router 所使用的同一份公开发布物中解析所选指南。应用其他功能和部署方法见[示例 README](https://github.com/LioRael/docs-sdk/tree/main/examples/next)。
|
|
20
|
+
|
|
21
|
+
选择 Next.js 时,普通客户端组件预览使用相应的 React 模块。本页的 App Router 预览在独立的 Next.js 应用中运行。
|