@tdacorp/hyle-sdk 0.21.0 → 0.22.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/README.md +110 -18
- package/dist/check-routes-bin.js +154 -42
- package/dist/{chunk-X2TLYM7Y.js → chunk-7T5EEJHK.js} +1 -1
- package/dist/chunk-DUPT6XLB.js +57 -0
- package/dist/{chunk-56Y24XBV.js → chunk-IW3TUD4G.js} +4 -3
- package/dist/{chunk-75JFLML4.js → chunk-KU7LWK4E.js} +75 -12
- package/dist/{chunk-K5VDLROQ.js → chunk-SFFBZFEN.js} +34 -1
- package/dist/{chunk-HJX57NLI.js → chunk-ZIW6FDU2.js} +246 -225
- package/dist/{client-LwzHwqpM.d.ts → client-BGjmEWhN.d.cts} +7 -1
- package/dist/{client-41fU6OY2.d.cts → client-D0LTpr3Y.d.ts} +7 -1
- package/dist/code-copy.cjs +4 -2
- package/dist/code-copy.d.cts +5 -2
- package/dist/code-copy.d.ts +5 -2
- package/dist/code-copy.js +5 -3
- package/dist/comments.cjs +11 -6
- package/dist/comments.js +11 -6
- package/dist/docs-enhance.cjs +7 -4
- package/dist/docs-enhance.d.cts +5 -3
- package/dist/docs-enhance.d.ts +5 -3
- package/dist/docs-enhance.js +8 -5
- package/dist/{embed-BUFRQboD.d.ts → embed-CbtsbZs3.d.cts} +4 -2
- package/dist/{embed-CYt-q13P.d.cts → embed-Cf_2ZR5x.d.ts} +4 -2
- package/dist/html.cjs +11 -6
- package/dist/html.d.cts +1 -1
- package/dist/html.d.ts +1 -1
- package/dist/html.js +2 -2
- package/dist/index.cjs +65 -12
- package/dist/index.d.cts +13 -11
- package/dist/index.d.ts +13 -11
- package/dist/index.js +2 -2
- package/dist/mermaid-diagram.cjs +46 -6
- package/dist/mermaid-diagram.js +15 -6
- package/dist/mermaid-image.cjs +4 -1
- package/dist/mermaid-image.js +1 -1
- package/dist/next.cjs +410 -241
- package/dist/next.d.cts +39 -17
- package/dist/next.d.ts +39 -17
- package/dist/next.js +116 -32
- package/dist/print-coordinator.js +1 -1
- package/dist/react.cjs +230 -197
- package/dist/react.d.cts +17 -6
- package/dist/react.d.ts +17 -6
- package/dist/react.js +5 -3
- package/dist/{resolve-eI1muCKL.d.cts → resolve-BnIv7aB7.d.cts} +1 -1
- package/dist/{resolve-BjAK0k_Y.d.ts → resolve-BysHtZ_i.d.ts} +1 -1
- package/dist/{sanitize-ijiWjEm9.d.cts → sanitize-BpY_AdZh.d.cts} +1 -1
- package/dist/{sanitize-ijiWjEm9.d.ts → sanitize-BpY_AdZh.d.ts} +1 -1
- package/dist/styles.css +4 -4
- package/dist/toc-spy.cjs +2 -1
- package/dist/toc-spy.js +2 -1
- package/dist/{types-3F0wqD-o.d.cts → types-D09Z072G.d.cts} +32 -1
- package/dist/{types-3F0wqD-o.d.ts → types-D09Z072G.d.ts} +32 -1
- package/dist/use-cache.cjs +53 -3
- package/dist/use-cache.d.cts +3 -3
- package/dist/use-cache.d.ts +3 -3
- package/dist/use-cache.js +3 -3
- package/package.json +3 -3
- package/dist/chunk-67IOIAVW.js +0 -35
package/dist/next.d.cts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { A as ArticleRef, O as OgImage, J as JsonLdConfig, H as HyleComponents, a as HyleSlots, E as EngagementConfig, b as EmbedHeading } from './embed-
|
|
3
|
-
export { c as HyleCommentsFallback } from './embed-
|
|
4
|
-
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-
|
|
5
|
-
export { f as fetchResolver, w as workspaceTags } from './resolve-
|
|
2
|
+
import { A as ArticleRef, O as OgImage, J as JsonLdConfig, H as HyleComponents, a as HyleSlots, E as EngagementConfig, b as EmbedHeading } from './embed-CbtsbZs3.cjs';
|
|
3
|
+
export { c as HyleCommentsFallback } from './embed-CbtsbZs3.cjs';
|
|
4
|
+
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-BnIv7aB7.cjs';
|
|
5
|
+
export { f as fetchResolver, w as workspaceTags } from './resolve-BnIv7aB7.cjs';
|
|
6
6
|
import { MetadataRoute, ResolvingMetadata, Metadata } from 'next';
|
|
7
7
|
import { R as RevalidationCallbackOptions, b as RevalidationCallbackRoute } from './revalidation-callback-BQl77tQR.cjs';
|
|
8
|
-
import './
|
|
8
|
+
import { c as HyleCredential } from './client-BGjmEWhN.cjs';
|
|
9
|
+
import './types-D09Z072G.cjs';
|
|
9
10
|
|
|
10
11
|
type RouteParams = Record<string, string | string[] | undefined>;
|
|
11
12
|
interface CommonOptions {
|
|
@@ -108,16 +109,16 @@ interface CommonOptions {
|
|
|
108
109
|
* `"searchParams"` makes list pages paginate: `?cursor=` is read, sent to hyle, and an "Older posts" link is built from
|
|
109
110
|
* `next_cursor`. Default off, and the trade-off is real: reading `searchParams` makes the route dynamic, so it can no longer
|
|
110
111
|
* be statically generated or served from ISR (hyle's fetch cache still applies). Leave it off when one page of `listLimit`
|
|
111
|
-
* items is enough. A malformed `cursor` is ignored (the first page is shown); one that is well-formed but
|
|
112
|
+
* items is enough. A malformed `cursor` is ignored (the first page is shown); one that is well-formed but rejected by hyle is a 404.
|
|
112
113
|
*/
|
|
113
114
|
readonly paginate?: "searchParams";
|
|
114
115
|
/**
|
|
115
|
-
* Opt-in custom UI for
|
|
116
|
+
* Opt-in custom UI for hyle failures (network error, timeout, 5xx, any 4xx that is not hyle's NOT_FOUND, a malformed
|
|
116
117
|
* response, a refused redirect target). Without it `hylePage` rethrows them, so Next keeps serving the last good ISR page
|
|
117
118
|
* when a revalidation fails (and a failure on a first render is an uncached 500). With it, the returned element is a NORMAL
|
|
118
119
|
* render: it is cached for the revalidate window and replaces the last good page for that long, so prefer a boundary
|
|
119
120
|
* (`error.tsx`) unless you want that. The `error` can carry `Cp1ClientError.message` and `requestId`: never render it.
|
|
120
|
-
* Only its name is logged. A
|
|
121
|
+
* Only its name is logged. A not-found answer from hyle (or a `cursor` it refuses) is always `notFound()` and never reaches this, and
|
|
121
122
|
* `notFound()` and redirects are Next control flow that always propagate.
|
|
122
123
|
*/
|
|
123
124
|
readonly onError?: (error: unknown) => ReactElement;
|
|
@@ -145,8 +146,8 @@ interface PageProps {
|
|
|
145
146
|
* in front, and 301 maps to permanentRedirect (308) while 307 maps to redirect (temporary). A target equal to the current
|
|
146
147
|
* URL would loop, so it is treated as not found.
|
|
147
148
|
*
|
|
148
|
-
* Failure:
|
|
149
|
-
*
|
|
149
|
+
* Failure: only hyle's own not-found answer (or its refusal of the visitor's `cursor`) is `notFound()`. Every other failure (network error, timeout, 5xx, any other
|
|
150
|
+
* 4xx, a malformed response, a refused redirect target) is RETHROWN, so under ISR Next keeps serving the last good
|
|
150
151
|
* page when a revalidation fails, and a first-render failure is an uncached 500 rather than a cached soft 200. `onError`
|
|
151
152
|
* opts in to a custom element instead (see its docs). `notFound()` and redirects always propagate (`unstable_rethrow`).
|
|
152
153
|
*
|
|
@@ -193,8 +194,8 @@ declare function hyleFeedLink(options: HyleNextOptions, locale?: string): {
|
|
|
193
194
|
* when there is one). A list page canonicals to itself; with `paginate` a cursor page canonicals to its own `?cursor=` URL (never to the
|
|
194
195
|
* first page) and its title gets an "Older posts" suffix. Open Graph titles are always the bare title.
|
|
195
196
|
* Canonical and hreflang URLs are ABSOLUTE when `siteOrigin` is a bare https origin, else relative paths (set `metadataBase` in the host's root layout).
|
|
196
|
-
* Redirects, 404s and a switched-off read surface produce no metadata; `hylePage` handles those.
|
|
197
|
-
* gives no metadata; any other failure (network, timeout, 5xx,
|
|
197
|
+
* Redirects, 404s and a switched-off read surface produce no metadata; `hylePage` handles those. hyle's own not-found
|
|
198
|
+
* gives no metadata; any other failure (network, timeout, 5xx, any other 4xx) is rethrown, so an outage is not
|
|
198
199
|
* cached as a page; Next control flow is rethrown.
|
|
199
200
|
*/
|
|
200
201
|
declare function hyleMetadata(options: HyleNextOptions): (props: PageProps, parent?: ResolvingMetadata) => Promise<Metadata>;
|
|
@@ -258,8 +259,8 @@ declare const MOUNTS_MAX_STALE_MS: number;
|
|
|
258
259
|
* entries: `notFound()` with ZERO resolve calls, so junk URLs and bot probes never reach hyle;
|
|
259
260
|
* - otherwise the request is served by `hylePage` with `basePath` = the matched prefix (same locale, redirect and error rules).
|
|
260
261
|
*
|
|
261
|
-
* Failure of the mounts fetch:
|
|
262
|
-
* 5xx,
|
|
262
|
+
* Failure of the mounts fetch: the kill switch means nothing is served (404); 401 and 403 are rethrown at once. Any other
|
|
263
|
+
* failure (network, timeout, 5xx, any other 4xx, malformed body) uses the last mounts read successfully for up to 15 minutes, so a hyle outage keeps
|
|
263
264
|
* unmatched URLs a plain 404 and mounted pages on their last good render; with no such copy (a cold server) it is RETHROWN,
|
|
264
265
|
* because the URL might be a mounted page: Next keeps the last good ISR page, or a first render is an uncached 500. A host
|
|
265
266
|
* route never depends on this at all: Next matches it first. With a ROOT mount and no copy, every unmatched URL errors
|
|
@@ -301,7 +302,7 @@ interface MarkdownRoute {
|
|
|
301
302
|
* `hyleRootPage`. It serves the markdown source of a page the mounts serve (same mount matching, reserved paths, `locale`,
|
|
302
303
|
* `localePrefix`, fetch cache and tags as the page itself): `text/markdown; charset=utf-8` with `X-Robots-Tag: noindex`, asset links
|
|
303
304
|
* rewritten to the host's asset route. A redirect (301 becomes 308, 307 stays) goes to the target's `.md` twin; a list, an unknown
|
|
304
|
-
* path or
|
|
305
|
+
* path or hyle's not-found is 404; any other failure is 502 with no body. Reached by `markdownRewritePath` in the host's middleware.
|
|
305
306
|
* For a locale-prefixed site put the route under `[locale]` (`app/api/hyle/md/[locale]/[...path]/route.ts`) so `locale(params)` sees it.
|
|
306
307
|
*/
|
|
307
308
|
declare function createMarkdownRoute(options: Configs): MarkdownRoute;
|
|
@@ -374,11 +375,17 @@ interface AssetRoute {
|
|
|
374
375
|
* `img-src 'self'` (and `media-src 'self'`) CSP needs no change. hyle serves only assets that a currently published page of this
|
|
375
376
|
* workspace references, so an unpublished or other workspace's asset is a 404 here too.
|
|
376
377
|
*
|
|
377
|
-
*
|
|
378
|
+
* The same route serves the workspace's theme stylesheet as `theme-<scope>-<sha256>.css` (see `serveTheme`), which `<HyleTheme>` links.
|
|
379
|
+
*
|
|
380
|
+
* Safety: the only input is the `file` segment, matched against `<uuid>[.<ext>]` or the theme name before anything is sent, so this is not an open
|
|
378
381
|
* proxy. The browser's cookies and authorization header are never forwarded; only `Range`, `If-Range` and `If-None-Match` are.
|
|
379
382
|
* The response headers are built here (no upstream header is copied blindly), the content type must be on the asset allowlist,
|
|
380
383
|
* the body is size-capped and time-bounded, and every failure is an empty 404 or 502 that says nothing about hyle.
|
|
381
384
|
* The site switch `HYLE_CONTENT_ENABLED=0`/`false`, or missing configuration, answers 404.
|
|
385
|
+
*
|
|
386
|
+
* Draft preview (hyle ADR 0037): `?hyle_preview=<token>`, which the preview page puts on its own images, is sent to hyle as a
|
|
387
|
+
* header so that draft's assets load; every such answer is `no-store`. The token is never sent for the theme stylesheet,
|
|
388
|
+
* which is the credential's own with or without it. No other query parameter is read.
|
|
382
389
|
*/
|
|
383
390
|
declare function createAssetRoute(options: AssetRouteOptions): AssetRoute;
|
|
384
391
|
|
|
@@ -512,4 +519,19 @@ declare const ENGAGE_CSRF_HEADER = "x-hyle-engage";
|
|
|
512
519
|
*/
|
|
513
520
|
declare function createEngagementRoute(options: EngagementRouteOptions): EngagementRoute;
|
|
514
521
|
|
|
515
|
-
|
|
522
|
+
/** The credential and base URL of `createHyleClient`, plus how your article pages are drawn. */
|
|
523
|
+
type HylePreviewPageOptions = HyleCredential & {
|
|
524
|
+
readonly baseUrl: string;
|
|
525
|
+
} & Pick<CommonOptions, "components" | "slots" | "layout" | "localePrefix">;
|
|
526
|
+
/** `export const metadata = hylePreviewMetadata`, next to `hylePreviewPage`. The page also renders both tags itself. */
|
|
527
|
+
declare const hylePreviewMetadata: Metadata;
|
|
528
|
+
/**
|
|
529
|
+
* The page behind hyle's "Open on site" (ADR 0037): `export default hylePreviewPage({ baseUrl, token })` in
|
|
530
|
+
* `app/hyle-preview/page.tsx`. It draws the draft behind `?token=` with your article components; a missing, wrong or
|
|
531
|
+
* expired token is `notFound()`. The page opens with an "Unpublished draft preview" banner. Nothing is cached (it reads
|
|
532
|
+
* `searchParams` and fetches `no-store`), the page is noindex with no referrer, and the token is never logged. Keep
|
|
533
|
+
* analytics off this route: its URL carries the token.
|
|
534
|
+
*/
|
|
535
|
+
declare function hylePreviewPage(options: HylePreviewPageOptions): (props: PageProps) => Promise<ReactElement>;
|
|
536
|
+
|
|
537
|
+
export { type AssetRoute, type AssetRouteOptions, ENGAGE_CSRF_HEADER, type EngageReader, type EngagementRoute, type EngagementRouteOptions, FetchResolverOptions, HyleArticle, type HyleArticleProps, HyleComments, type HyleCommentsProps, type HyleFeedOptions, HyleList, type HyleListProps, type HyleNextOptions, type HylePreviewPageOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, type LlmsTxtOptions, MOUNTS_MAX_STALE_MS, type MarkdownRoute, type OgImageRoute, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createEngagementRoute, createLlmsTxtRoute, createMarkdownRoute, createOgImageRoute, createRevalidateRoute, hyleFeed, hyleFeedLink, hyleMetadata, hylePage, hylePreviewMetadata, hylePreviewPage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap, markdownRewritePath };
|
package/dist/next.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { A as ArticleRef, O as OgImage, J as JsonLdConfig, H as HyleComponents, a as HyleSlots, E as EngagementConfig, b as EmbedHeading } from './embed-
|
|
3
|
-
export { c as HyleCommentsFallback } from './embed-
|
|
4
|
-
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-
|
|
5
|
-
export { f as fetchResolver, w as workspaceTags } from './resolve-
|
|
2
|
+
import { A as ArticleRef, O as OgImage, J as JsonLdConfig, H as HyleComponents, a as HyleSlots, E as EngagementConfig, b as EmbedHeading } from './embed-Cf_2ZR5x.js';
|
|
3
|
+
export { c as HyleCommentsFallback } from './embed-Cf_2ZR5x.js';
|
|
4
|
+
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-BysHtZ_i.js';
|
|
5
|
+
export { f as fetchResolver, w as workspaceTags } from './resolve-BysHtZ_i.js';
|
|
6
6
|
import { MetadataRoute, ResolvingMetadata, Metadata } from 'next';
|
|
7
7
|
import { R as RevalidationCallbackOptions, b as RevalidationCallbackRoute } from './revalidation-callback-BQl77tQR.js';
|
|
8
|
-
import './
|
|
8
|
+
import { c as HyleCredential } from './client-D0LTpr3Y.js';
|
|
9
|
+
import './types-D09Z072G.js';
|
|
9
10
|
|
|
10
11
|
type RouteParams = Record<string, string | string[] | undefined>;
|
|
11
12
|
interface CommonOptions {
|
|
@@ -108,16 +109,16 @@ interface CommonOptions {
|
|
|
108
109
|
* `"searchParams"` makes list pages paginate: `?cursor=` is read, sent to hyle, and an "Older posts" link is built from
|
|
109
110
|
* `next_cursor`. Default off, and the trade-off is real: reading `searchParams` makes the route dynamic, so it can no longer
|
|
110
111
|
* be statically generated or served from ISR (hyle's fetch cache still applies). Leave it off when one page of `listLimit`
|
|
111
|
-
* items is enough. A malformed `cursor` is ignored (the first page is shown); one that is well-formed but
|
|
112
|
+
* items is enough. A malformed `cursor` is ignored (the first page is shown); one that is well-formed but rejected by hyle is a 404.
|
|
112
113
|
*/
|
|
113
114
|
readonly paginate?: "searchParams";
|
|
114
115
|
/**
|
|
115
|
-
* Opt-in custom UI for
|
|
116
|
+
* Opt-in custom UI for hyle failures (network error, timeout, 5xx, any 4xx that is not hyle's NOT_FOUND, a malformed
|
|
116
117
|
* response, a refused redirect target). Without it `hylePage` rethrows them, so Next keeps serving the last good ISR page
|
|
117
118
|
* when a revalidation fails (and a failure on a first render is an uncached 500). With it, the returned element is a NORMAL
|
|
118
119
|
* render: it is cached for the revalidate window and replaces the last good page for that long, so prefer a boundary
|
|
119
120
|
* (`error.tsx`) unless you want that. The `error` can carry `Cp1ClientError.message` and `requestId`: never render it.
|
|
120
|
-
* Only its name is logged. A
|
|
121
|
+
* Only its name is logged. A not-found answer from hyle (or a `cursor` it refuses) is always `notFound()` and never reaches this, and
|
|
121
122
|
* `notFound()` and redirects are Next control flow that always propagate.
|
|
122
123
|
*/
|
|
123
124
|
readonly onError?: (error: unknown) => ReactElement;
|
|
@@ -145,8 +146,8 @@ interface PageProps {
|
|
|
145
146
|
* in front, and 301 maps to permanentRedirect (308) while 307 maps to redirect (temporary). A target equal to the current
|
|
146
147
|
* URL would loop, so it is treated as not found.
|
|
147
148
|
*
|
|
148
|
-
* Failure:
|
|
149
|
-
*
|
|
149
|
+
* Failure: only hyle's own not-found answer (or its refusal of the visitor's `cursor`) is `notFound()`. Every other failure (network error, timeout, 5xx, any other
|
|
150
|
+
* 4xx, a malformed response, a refused redirect target) is RETHROWN, so under ISR Next keeps serving the last good
|
|
150
151
|
* page when a revalidation fails, and a first-render failure is an uncached 500 rather than a cached soft 200. `onError`
|
|
151
152
|
* opts in to a custom element instead (see its docs). `notFound()` and redirects always propagate (`unstable_rethrow`).
|
|
152
153
|
*
|
|
@@ -193,8 +194,8 @@ declare function hyleFeedLink(options: HyleNextOptions, locale?: string): {
|
|
|
193
194
|
* when there is one). A list page canonicals to itself; with `paginate` a cursor page canonicals to its own `?cursor=` URL (never to the
|
|
194
195
|
* first page) and its title gets an "Older posts" suffix. Open Graph titles are always the bare title.
|
|
195
196
|
* Canonical and hreflang URLs are ABSOLUTE when `siteOrigin` is a bare https origin, else relative paths (set `metadataBase` in the host's root layout).
|
|
196
|
-
* Redirects, 404s and a switched-off read surface produce no metadata; `hylePage` handles those.
|
|
197
|
-
* gives no metadata; any other failure (network, timeout, 5xx,
|
|
197
|
+
* Redirects, 404s and a switched-off read surface produce no metadata; `hylePage` handles those. hyle's own not-found
|
|
198
|
+
* gives no metadata; any other failure (network, timeout, 5xx, any other 4xx) is rethrown, so an outage is not
|
|
198
199
|
* cached as a page; Next control flow is rethrown.
|
|
199
200
|
*/
|
|
200
201
|
declare function hyleMetadata(options: HyleNextOptions): (props: PageProps, parent?: ResolvingMetadata) => Promise<Metadata>;
|
|
@@ -258,8 +259,8 @@ declare const MOUNTS_MAX_STALE_MS: number;
|
|
|
258
259
|
* entries: `notFound()` with ZERO resolve calls, so junk URLs and bot probes never reach hyle;
|
|
259
260
|
* - otherwise the request is served by `hylePage` with `basePath` = the matched prefix (same locale, redirect and error rules).
|
|
260
261
|
*
|
|
261
|
-
* Failure of the mounts fetch:
|
|
262
|
-
* 5xx,
|
|
262
|
+
* Failure of the mounts fetch: the kill switch means nothing is served (404); 401 and 403 are rethrown at once. Any other
|
|
263
|
+
* failure (network, timeout, 5xx, any other 4xx, malformed body) uses the last mounts read successfully for up to 15 minutes, so a hyle outage keeps
|
|
263
264
|
* unmatched URLs a plain 404 and mounted pages on their last good render; with no such copy (a cold server) it is RETHROWN,
|
|
264
265
|
* because the URL might be a mounted page: Next keeps the last good ISR page, or a first render is an uncached 500. A host
|
|
265
266
|
* route never depends on this at all: Next matches it first. With a ROOT mount and no copy, every unmatched URL errors
|
|
@@ -301,7 +302,7 @@ interface MarkdownRoute {
|
|
|
301
302
|
* `hyleRootPage`. It serves the markdown source of a page the mounts serve (same mount matching, reserved paths, `locale`,
|
|
302
303
|
* `localePrefix`, fetch cache and tags as the page itself): `text/markdown; charset=utf-8` with `X-Robots-Tag: noindex`, asset links
|
|
303
304
|
* rewritten to the host's asset route. A redirect (301 becomes 308, 307 stays) goes to the target's `.md` twin; a list, an unknown
|
|
304
|
-
* path or
|
|
305
|
+
* path or hyle's not-found is 404; any other failure is 502 with no body. Reached by `markdownRewritePath` in the host's middleware.
|
|
305
306
|
* For a locale-prefixed site put the route under `[locale]` (`app/api/hyle/md/[locale]/[...path]/route.ts`) so `locale(params)` sees it.
|
|
306
307
|
*/
|
|
307
308
|
declare function createMarkdownRoute(options: Configs): MarkdownRoute;
|
|
@@ -374,11 +375,17 @@ interface AssetRoute {
|
|
|
374
375
|
* `img-src 'self'` (and `media-src 'self'`) CSP needs no change. hyle serves only assets that a currently published page of this
|
|
375
376
|
* workspace references, so an unpublished or other workspace's asset is a 404 here too.
|
|
376
377
|
*
|
|
377
|
-
*
|
|
378
|
+
* The same route serves the workspace's theme stylesheet as `theme-<scope>-<sha256>.css` (see `serveTheme`), which `<HyleTheme>` links.
|
|
379
|
+
*
|
|
380
|
+
* Safety: the only input is the `file` segment, matched against `<uuid>[.<ext>]` or the theme name before anything is sent, so this is not an open
|
|
378
381
|
* proxy. The browser's cookies and authorization header are never forwarded; only `Range`, `If-Range` and `If-None-Match` are.
|
|
379
382
|
* The response headers are built here (no upstream header is copied blindly), the content type must be on the asset allowlist,
|
|
380
383
|
* the body is size-capped and time-bounded, and every failure is an empty 404 or 502 that says nothing about hyle.
|
|
381
384
|
* The site switch `HYLE_CONTENT_ENABLED=0`/`false`, or missing configuration, answers 404.
|
|
385
|
+
*
|
|
386
|
+
* Draft preview (hyle ADR 0037): `?hyle_preview=<token>`, which the preview page puts on its own images, is sent to hyle as a
|
|
387
|
+
* header so that draft's assets load; every such answer is `no-store`. The token is never sent for the theme stylesheet,
|
|
388
|
+
* which is the credential's own with or without it. No other query parameter is read.
|
|
382
389
|
*/
|
|
383
390
|
declare function createAssetRoute(options: AssetRouteOptions): AssetRoute;
|
|
384
391
|
|
|
@@ -512,4 +519,19 @@ declare const ENGAGE_CSRF_HEADER = "x-hyle-engage";
|
|
|
512
519
|
*/
|
|
513
520
|
declare function createEngagementRoute(options: EngagementRouteOptions): EngagementRoute;
|
|
514
521
|
|
|
515
|
-
|
|
522
|
+
/** The credential and base URL of `createHyleClient`, plus how your article pages are drawn. */
|
|
523
|
+
type HylePreviewPageOptions = HyleCredential & {
|
|
524
|
+
readonly baseUrl: string;
|
|
525
|
+
} & Pick<CommonOptions, "components" | "slots" | "layout" | "localePrefix">;
|
|
526
|
+
/** `export const metadata = hylePreviewMetadata`, next to `hylePreviewPage`. The page also renders both tags itself. */
|
|
527
|
+
declare const hylePreviewMetadata: Metadata;
|
|
528
|
+
/**
|
|
529
|
+
* The page behind hyle's "Open on site" (ADR 0037): `export default hylePreviewPage({ baseUrl, token })` in
|
|
530
|
+
* `app/hyle-preview/page.tsx`. It draws the draft behind `?token=` with your article components; a missing, wrong or
|
|
531
|
+
* expired token is `notFound()`. The page opens with an "Unpublished draft preview" banner. Nothing is cached (it reads
|
|
532
|
+
* `searchParams` and fetches `no-store`), the page is noindex with no referrer, and the token is never logged. Keep
|
|
533
|
+
* analytics off this route: its URL carries the token.
|
|
534
|
+
*/
|
|
535
|
+
declare function hylePreviewPage(options: HylePreviewPageOptions): (props: PageProps) => Promise<ReactElement>;
|
|
536
|
+
|
|
537
|
+
export { type AssetRoute, type AssetRouteOptions, ENGAGE_CSRF_HEADER, type EngageReader, type EngagementRoute, type EngagementRouteOptions, FetchResolverOptions, HyleArticle, type HyleArticleProps, HyleComments, type HyleCommentsProps, type HyleFeedOptions, HyleList, type HyleListProps, type HyleNextOptions, type HylePreviewPageOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, type LlmsTxtOptions, MOUNTS_MAX_STALE_MS, type MarkdownRoute, type OgImageRoute, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createEngagementRoute, createLlmsTxtRoute, createMarkdownRoute, createOgImageRoute, createRevalidateRoute, hyleFeed, hyleFeedLink, hyleMetadata, hylePage, hylePreviewMetadata, hylePreviewPage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap, markdownRewritePath };
|
package/dist/next.js
CHANGED
|
@@ -19,15 +19,15 @@ import {
|
|
|
19
19
|
readingMinutes,
|
|
20
20
|
validOgImage,
|
|
21
21
|
wordCountOf
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-ZIW6FDU2.js";
|
|
23
23
|
import {
|
|
24
24
|
stringsFor
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-IW3TUD4G.js";
|
|
26
26
|
import {
|
|
27
27
|
DEFAULT_REVALIDATE,
|
|
28
28
|
fetchResolver,
|
|
29
29
|
workspaceTags
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-7T5EEJHK.js";
|
|
31
31
|
import {
|
|
32
32
|
Cp1ClientError,
|
|
33
33
|
checkBaseUrl,
|
|
@@ -35,15 +35,20 @@ import {
|
|
|
35
35
|
createHyleClient,
|
|
36
36
|
createRevalidationCallbackRoute,
|
|
37
37
|
engagementSigningKey,
|
|
38
|
+
isNotFoundBody,
|
|
39
|
+
isNotFoundResponse,
|
|
38
40
|
listPublicationPaths,
|
|
39
41
|
readCapped,
|
|
40
42
|
signReaderAssertion
|
|
41
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-KU7LWK4E.js";
|
|
42
44
|
import {
|
|
43
45
|
ASSET_CONTENT_TYPES,
|
|
44
46
|
ASSET_FILE,
|
|
45
|
-
ASSET_ROUTE_PREFIX
|
|
46
|
-
|
|
47
|
+
ASSET_ROUTE_PREFIX,
|
|
48
|
+
PREVIEW_PARAM,
|
|
49
|
+
PREVIEW_TOKEN,
|
|
50
|
+
THEME_FILE
|
|
51
|
+
} from "./chunk-DUPT6XLB.js";
|
|
47
52
|
|
|
48
53
|
// src/next/page.tsx
|
|
49
54
|
import { notFound, permanentRedirect, redirect } from "next/navigation";
|
|
@@ -70,7 +75,7 @@ function sitePathFrom(basePath, segments) {
|
|
|
70
75
|
return void 0;
|
|
71
76
|
}
|
|
72
77
|
if (segment !== segment.normalize("NFC")) return void 0;
|
|
73
|
-
if (segment === "" || segment === "." || segment
|
|
78
|
+
if (segment === "" || segment === "." || segment.includes("..") || /[/\\\u0000-\u001f\u007f]|%[0-9a-f]{2}/i.test(segment)) return void 0;
|
|
74
79
|
decoded.push(segment);
|
|
75
80
|
}
|
|
76
81
|
const path = decoded.length === 0 ? basePath || "/" : `${basePath}/${decoded.join("/")}`;
|
|
@@ -105,9 +110,10 @@ function routeContext(options, params) {
|
|
|
105
110
|
const toHref = (sitePath, linkLocale = locale) => (linkLocale ? prefix(linkLocale) : "") + sitePath;
|
|
106
111
|
return { basePath, path, locale, toHref };
|
|
107
112
|
}
|
|
108
|
-
function
|
|
113
|
+
function isNotFoundError(error, cursor) {
|
|
109
114
|
unstable_rethrow(error);
|
|
110
|
-
|
|
115
|
+
if (!(error instanceof Cp1ClientError)) return false;
|
|
116
|
+
return error.status === 404 && error.code === "NOT_FOUND" || cursor !== void 0 && error.status === 400 && error.code === "VALIDATION_ERROR";
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
// src/next/embed.tsx
|
|
@@ -408,7 +414,9 @@ function createEngagementRoute(options) {
|
|
|
408
414
|
redirect: "error",
|
|
409
415
|
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
|
|
410
416
|
});
|
|
411
|
-
|
|
417
|
+
const text = await readCapped(res, MAX_RESPONSE_BYTES);
|
|
418
|
+
const status = res.status === 404 && !isNotFoundBody(res.status, text) ? 502 : res.status;
|
|
419
|
+
return { status, ok: res.ok, text, retryAfter: res.headers.get("retry-after"), throttle: res.headers.get("hyle-throttle") };
|
|
412
420
|
};
|
|
413
421
|
try {
|
|
414
422
|
const out = route.action(req.method) === "comments.list" ? await shared(`${viewer?.reader.sub ?? ""}
|
|
@@ -426,11 +434,11 @@ ${built.query.toString()}`, () => listing(viewer, call)) : await call();
|
|
|
426
434
|
|
|
427
435
|
// src/next/embed.tsx
|
|
428
436
|
import { jsx } from "react/jsx-runtime";
|
|
429
|
-
async function resolveEmbed(options, run) {
|
|
437
|
+
async function resolveEmbed(options, run, cursor) {
|
|
430
438
|
try {
|
|
431
439
|
return { result: await run() };
|
|
432
440
|
} catch (error) {
|
|
433
|
-
if (
|
|
441
|
+
if (isNotFoundError(error, cursor)) return {};
|
|
434
442
|
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
435
443
|
return { failure: options.onError ? options.onError(error) : null };
|
|
436
444
|
}
|
|
@@ -440,10 +448,11 @@ async function HyleList({ options, limit = 5, locale, layout, title, headingLeve
|
|
|
440
448
|
const route = routeContext(locale ? { ...options, locale } : options, {});
|
|
441
449
|
const path = sitePathFrom(route.basePath, void 0);
|
|
442
450
|
if (path === void 0) return null;
|
|
443
|
-
const
|
|
451
|
+
const after = validCursor(cursor);
|
|
452
|
+
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale, limit, after), after);
|
|
444
453
|
if (failure !== void 0) return failure;
|
|
445
454
|
const next = olderHref && result?.kind === "list" ? validCursor(result.next_cursor) : void 0;
|
|
446
|
-
return /* @__PURE__ */ jsx(HyleListView, { items: result?.kind === "list" ? result.items : [], layout, title, headingLevel, moreHref, olderHref: next ? olderHref?.(next) : void 0, components: options.components, slots: options.slots, locale: route.locale, toHref: route.toHref });
|
|
455
|
+
return /* @__PURE__ */ jsx(HyleListView, { items: result?.kind === "list" ? result.items : [], theme: result?.kind === "list" ? result.theme : void 0, layout, title, headingLevel, moreHref, olderHref: next ? olderHref?.(next) : void 0, components: options.components, slots: options.slots, locale: route.locale, toHref: route.toHref });
|
|
447
456
|
}
|
|
448
457
|
async function HyleArticle({ options, path, locale, headingLevel }) {
|
|
449
458
|
if (!isSitePath(path)) return null;
|
|
@@ -472,7 +481,7 @@ async function HyleComments({ options, path, revalidate = 60, interactive }) {
|
|
|
472
481
|
};
|
|
473
482
|
const res = await fetch(`${options.baseUrl.replace(/\/+$/, "")}/cp1/engage/comments?${new URLSearchParams({ path })}`, init);
|
|
474
483
|
if (!res.ok) {
|
|
475
|
-
if (res
|
|
484
|
+
if (!await isNotFoundResponse(res)) console.error(`hyle: comments answered HTTP ${res.status}`);
|
|
476
485
|
return null;
|
|
477
486
|
}
|
|
478
487
|
listing = parseListing(JSON.parse(await readCapped(res, MAX_LISTING_BYTES)).data);
|
|
@@ -503,8 +512,9 @@ function hylePage(options) {
|
|
|
503
512
|
return async function HylePage({ params, searchParams }) {
|
|
504
513
|
const { path, locale, toHref } = routeContext(options, await params ?? {});
|
|
505
514
|
if (path === void 0) notFound();
|
|
515
|
+
let cursor;
|
|
506
516
|
try {
|
|
507
|
-
|
|
517
|
+
cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
508
518
|
const result = await resolve(path, locale, options.listLimit, cursor, options.layout === "docs" ? "tree" : void 0);
|
|
509
519
|
switch (result.kind) {
|
|
510
520
|
case "article": {
|
|
@@ -532,7 +542,7 @@ function hylePage(options) {
|
|
|
532
542
|
notFound();
|
|
533
543
|
}
|
|
534
544
|
} catch (error) {
|
|
535
|
-
if (
|
|
545
|
+
if (isNotFoundError(error, cursor)) notFound();
|
|
536
546
|
if (!options.onError) throw error;
|
|
537
547
|
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
538
548
|
return options.onError(error);
|
|
@@ -633,8 +643,9 @@ function hyleMetadata(options) {
|
|
|
633
643
|
};
|
|
634
644
|
return Object.keys(types).length ? { ...alternates, types } : alternates;
|
|
635
645
|
};
|
|
646
|
+
let cursor;
|
|
636
647
|
try {
|
|
637
|
-
|
|
648
|
+
cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
638
649
|
const result = await resolve(path, locale, options.listLimit, cursor, options.layout === "docs" ? "tree" : void 0);
|
|
639
650
|
const parentMeta = parent ? await parent : void 0;
|
|
640
651
|
const parentImages = parentMeta?.openGraph?.images;
|
|
@@ -710,7 +721,7 @@ function hyleMetadata(options) {
|
|
|
710
721
|
} : {}
|
|
711
722
|
};
|
|
712
723
|
} catch (error) {
|
|
713
|
-
if (
|
|
724
|
+
if (isNotFoundError(error, cursor)) return {};
|
|
714
725
|
throw error;
|
|
715
726
|
}
|
|
716
727
|
};
|
|
@@ -780,7 +791,7 @@ function createRevalidateRoute(options) {
|
|
|
780
791
|
}
|
|
781
792
|
|
|
782
793
|
// src/next/root.ts
|
|
783
|
-
import { notFound as notFound2 } from "next/navigation";
|
|
794
|
+
import { notFound as notFound2, unstable_rethrow as unstable_rethrow4 } from "next/navigation";
|
|
784
795
|
|
|
785
796
|
// src/next/mount-match.ts
|
|
786
797
|
function activeMounts(mounts) {
|
|
@@ -827,10 +838,7 @@ function mountsLoader(config) {
|
|
|
827
838
|
lastKnownGood.set(key, { loaded, at: Date.now() });
|
|
828
839
|
return loaded;
|
|
829
840
|
} catch (error) {
|
|
830
|
-
|
|
831
|
-
lastKnownGood.delete(key);
|
|
832
|
-
return NONE;
|
|
833
|
-
}
|
|
841
|
+
unstable_rethrow4(error);
|
|
834
842
|
if (error instanceof Cp1ClientError && (error.status === 401 || error.status === 403)) {
|
|
835
843
|
lastKnownGood.delete(key);
|
|
836
844
|
throw error;
|
|
@@ -962,7 +970,7 @@ function createMarkdownRoute(options) {
|
|
|
962
970
|
}
|
|
963
971
|
return reply(null, 404);
|
|
964
972
|
} catch (error) {
|
|
965
|
-
if (
|
|
973
|
+
if (isNotFoundError(error)) return reply(null, 404);
|
|
966
974
|
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
967
975
|
return reply(null, 502);
|
|
968
976
|
}
|
|
@@ -971,7 +979,7 @@ function createMarkdownRoute(options) {
|
|
|
971
979
|
}
|
|
972
980
|
|
|
973
981
|
// src/next/llms.ts
|
|
974
|
-
import { unstable_rethrow as
|
|
982
|
+
import { unstable_rethrow as unstable_rethrow5 } from "next/navigation";
|
|
975
983
|
var oneLine = (text) => text.replace(/\s+/g, " ").trim();
|
|
976
984
|
var linkTarget = (url) => url.replace(/[()]/g, (c) => c === "(" ? "%28" : "%29");
|
|
977
985
|
function createLlmsTxtRoute(options, llms) {
|
|
@@ -996,7 +1004,7 @@ function createLlmsTxtRoute(options, llms) {
|
|
|
996
1004
|
return new Response(`${lines.join("\n")}
|
|
997
1005
|
`, { headers: { "Content-Type": "text/plain; charset=utf-8" } });
|
|
998
1006
|
} catch (error) {
|
|
999
|
-
|
|
1007
|
+
unstable_rethrow5(error);
|
|
1000
1008
|
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
1001
1009
|
return new Response(null, { status: 503 });
|
|
1002
1010
|
}
|
|
@@ -1013,8 +1021,34 @@ var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
|
1013
1021
|
var CACHE_CONTROL = "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400";
|
|
1014
1022
|
var PARTIAL_CACHE_CONTROL = "no-store";
|
|
1015
1023
|
var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
|
|
1024
|
+
var PREVIEW_HEADERS = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
|
|
1016
1025
|
var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
|
|
1017
1026
|
var isSwitchedOff3 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
1027
|
+
var THEME_CACHE_CONTROL = "public, max-age=31536000, immutable";
|
|
1028
|
+
var OUTDATED_THEME_CACHE_CONTROL = "public, max-age=60";
|
|
1029
|
+
var THEME_SCOPE_HEADER = "cp-theme-scope";
|
|
1030
|
+
var MAX_THEME_BYTES = 256 * 1024;
|
|
1031
|
+
var sha256Hex = async (text) => Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text))), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1032
|
+
async function serveTheme(client, scope, hash, timeoutMs, head) {
|
|
1033
|
+
try {
|
|
1034
|
+
const upstream = await client.theme({ timeoutMs });
|
|
1035
|
+
const type = upstream.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase();
|
|
1036
|
+
if (upstream.status === 404) return empty(await isNotFoundResponse(upstream) ? 404 : 502);
|
|
1037
|
+
if (upstream.status !== 200 || type !== "text/css") {
|
|
1038
|
+
void upstream.body?.cancel().catch(() => {
|
|
1039
|
+
});
|
|
1040
|
+
return empty(502);
|
|
1041
|
+
}
|
|
1042
|
+
const css = await readCapped(upstream, MAX_THEME_BYTES);
|
|
1043
|
+
const current = await sha256Hex(css);
|
|
1044
|
+
if (current !== hash && upstream.headers.get(THEME_SCOPE_HEADER) !== scope) return empty(404);
|
|
1045
|
+
const cache = current === hash ? THEME_CACHE_CONTROL : OUTDATED_THEME_CACHE_CONTROL;
|
|
1046
|
+
const headers = { "Content-Type": "text/css; charset=utf-8", "Cache-Control": cache, ETag: `"${current}"`, ...SAFE_HEADERS };
|
|
1047
|
+
return new Response(head ? null : css, { status: 200, headers });
|
|
1048
|
+
} catch {
|
|
1049
|
+
return empty(502);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1018
1052
|
function capped(body, max) {
|
|
1019
1053
|
let seen = 0;
|
|
1020
1054
|
return body.pipeThrough(
|
|
@@ -1031,18 +1065,28 @@ function createAssetRoute(options) {
|
|
|
1031
1065
|
let client;
|
|
1032
1066
|
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
1033
1067
|
async function serve(req, ctx, head) {
|
|
1068
|
+
const previewToken = new URL(req.url).searchParams.get(PREVIEW_PARAM);
|
|
1069
|
+
const res = await relay(req, ctx, head, previewToken);
|
|
1070
|
+
if (previewToken !== null) for (const [name, value] of Object.entries(PREVIEW_HEADERS)) res.headers.set(name, value);
|
|
1071
|
+
return res;
|
|
1072
|
+
}
|
|
1073
|
+
async function relay(req, ctx, head, previewToken) {
|
|
1034
1074
|
if (isSwitchedOff3((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
|
|
1035
1075
|
const file = (await ctx.params).file;
|
|
1036
|
-
|
|
1076
|
+
const [, themeScope, themeHash] = typeof file === "string" ? THEME_FILE.exec(file) ?? [] : [];
|
|
1077
|
+
if (typeof file !== "string" || !themeHash && !ASSET_FILE.test(file)) return empty(404);
|
|
1078
|
+
if (previewToken !== null && !PREVIEW_TOKEN.test(previewToken)) return empty(404);
|
|
1037
1079
|
try {
|
|
1038
1080
|
client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
|
|
1039
1081
|
} catch {
|
|
1040
1082
|
return empty(404);
|
|
1041
1083
|
}
|
|
1084
|
+
if (themeScope && themeHash) return serveTheme(client, themeScope, themeHash, options.timeoutMs ?? DEFAULT_TIMEOUT_MS2, head);
|
|
1042
1085
|
let upstream;
|
|
1043
1086
|
try {
|
|
1044
1087
|
upstream = await client.asset(file, {
|
|
1045
1088
|
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS2,
|
|
1089
|
+
...previewToken === null ? {} : { previewToken },
|
|
1046
1090
|
headers: { range: req.headers.get("range"), "if-range": req.headers.get("if-range"), "if-none-match": req.headers.get("if-none-match") }
|
|
1047
1091
|
});
|
|
1048
1092
|
} catch {
|
|
@@ -1055,10 +1099,16 @@ function createAssetRoute(options) {
|
|
|
1055
1099
|
drop();
|
|
1056
1100
|
return new Response(null, { status: 304, headers: { "Cache-Control": CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS, ...etag ? { ETag: etag } : {} } });
|
|
1057
1101
|
}
|
|
1058
|
-
if (upstream.status === 404
|
|
1102
|
+
if (upstream.status === 404) return empty(await isNotFoundResponse(upstream) ? 404 : 502);
|
|
1103
|
+
if (upstream.status === 416) {
|
|
1104
|
+
drop();
|
|
1105
|
+
const range = upstream.headers.get("content-range");
|
|
1106
|
+
return empty(416, range ? { "Content-Range": range } : {});
|
|
1107
|
+
}
|
|
1108
|
+
if (upstream.status === 429 && previewToken !== null) {
|
|
1059
1109
|
drop();
|
|
1060
|
-
const
|
|
1061
|
-
return empty(
|
|
1110
|
+
const wait = upstream.headers.get("retry-after");
|
|
1111
|
+
return empty(429, wait ? { "Retry-After": wait } : {});
|
|
1062
1112
|
}
|
|
1063
1113
|
const type = upstream.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase();
|
|
1064
1114
|
const length = Number(upstream.headers.get("content-length"));
|
|
@@ -1107,7 +1157,7 @@ function createOgImageRoute(options) {
|
|
|
1107
1157
|
if (result.kind !== "article") return new Response(null, { status: 404 });
|
|
1108
1158
|
title = result.publication.title;
|
|
1109
1159
|
} catch (error) {
|
|
1110
|
-
return new Response(null, { status:
|
|
1160
|
+
return new Response(null, { status: isNotFoundError(error) ? 404 : 502 });
|
|
1111
1161
|
}
|
|
1112
1162
|
const chars = [...title];
|
|
1113
1163
|
const shown = chars.length > MAX_TITLE ? `${chars.slice(0, MAX_TITLE - 1).join("")}\u2026` : title;
|
|
@@ -1122,6 +1172,38 @@ function createOgImageRoute(options) {
|
|
|
1122
1172
|
}
|
|
1123
1173
|
};
|
|
1124
1174
|
}
|
|
1175
|
+
|
|
1176
|
+
// src/next/preview.tsx
|
|
1177
|
+
import { notFound as notFound3 } from "next/navigation";
|
|
1178
|
+
import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1179
|
+
var hylePreviewMetadata = { robots: { index: false, follow: false }, referrer: "no-referrer" };
|
|
1180
|
+
var BANNER = {
|
|
1181
|
+
position: "sticky",
|
|
1182
|
+
top: 0,
|
|
1183
|
+
zIndex: 2147483647,
|
|
1184
|
+
padding: "8px 16px",
|
|
1185
|
+
background: "#fde047",
|
|
1186
|
+
color: "#1a1a1a",
|
|
1187
|
+
font: "600 14px/1.4 system-ui, sans-serif",
|
|
1188
|
+
textAlign: "center"
|
|
1189
|
+
};
|
|
1190
|
+
function hylePreviewPage(options) {
|
|
1191
|
+
return async function HylePreviewPage({ searchParams }) {
|
|
1192
|
+
const { token } = await searchParams ?? {};
|
|
1193
|
+
const result = await createHyleClient(options).preview(typeof token === "string" ? token : void 0);
|
|
1194
|
+
if (result.kind !== "preview") notFound3();
|
|
1195
|
+
const { article } = result;
|
|
1196
|
+
const { locale } = article.publication;
|
|
1197
|
+
const toHref = (sitePath, linkLocale = locale) => (options.localePrefix?.(linkLocale) ?? "") + sitePath;
|
|
1198
|
+
const props = { article, components: options.components, slots: options.slots, locale, toHref };
|
|
1199
|
+
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1200
|
+
/* @__PURE__ */ jsx4("meta", { name: "robots", content: "noindex, nofollow" }),
|
|
1201
|
+
/* @__PURE__ */ jsx4("meta", { name: "referrer", content: "no-referrer" }),
|
|
1202
|
+
/* @__PURE__ */ jsx4("div", { role: "status", style: BANNER, children: "Unpublished draft preview" }),
|
|
1203
|
+
options.layout === "docs" ? /* @__PURE__ */ jsx4(DocsPage, { ...props }) : /* @__PURE__ */ jsx4(ArticlePage, { ...props })
|
|
1204
|
+
] });
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1125
1207
|
export {
|
|
1126
1208
|
ENGAGE_CSRF_HEADER,
|
|
1127
1209
|
HyleArticle,
|
|
@@ -1140,6 +1222,8 @@ export {
|
|
|
1140
1222
|
hyleFeedLink,
|
|
1141
1223
|
hyleMetadata,
|
|
1142
1224
|
hylePage,
|
|
1225
|
+
hylePreviewMetadata,
|
|
1226
|
+
hylePreviewPage,
|
|
1143
1227
|
hyleRootMetadata,
|
|
1144
1228
|
hyleRootPage,
|
|
1145
1229
|
hyleRootSitemap,
|