@tdacorp/hyle-sdk 0.14.1 → 0.21.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/README.md +171 -32
- package/dist/check-routes-bin.js +48 -21
- package/dist/chunk-56Y24XBV.js +840 -0
- package/dist/{chunk-MGSUQBDW.js → chunk-75JFLML4.js} +176 -14
- package/dist/chunk-HJX57NLI.js +1105 -0
- package/dist/chunk-K5VDLROQ.js +145 -0
- package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
- package/dist/chunk-U74B7AUG.js +398 -0
- package/dist/{chunk-6VOHFFA5.js → chunk-X2TLYM7Y.js} +2 -2
- package/dist/client-41fU6OY2.d.cts +201 -0
- package/dist/client-LwzHwqpM.d.ts +201 -0
- package/dist/code-copy.cjs +72 -0
- package/dist/code-copy.d.cts +15 -0
- package/dist/code-copy.d.ts +15 -0
- package/dist/code-copy.js +48 -0
- package/dist/comments.cjs +733 -278
- package/dist/comments.d.cts +66 -3
- package/dist/comments.d.ts +66 -3
- package/dist/comments.js +414 -330
- package/dist/{diagram-viewer-DYX6R63Y.js → diagram-viewer-XY3CG75U.js} +107 -46
- package/dist/{embed-B76zRRPa.d.cts → embed-BUFRQboD.d.ts} +10 -5
- package/dist/{embed-SqOBGI-E.d.ts → embed-CYt-q13P.d.cts} +10 -5
- package/dist/fragment-alias.cjs +51 -0
- package/dist/fragment-alias.d.cts +7 -0
- package/dist/fragment-alias.d.ts +7 -0
- package/dist/fragment-alias.js +27 -0
- package/dist/html.cjs +881 -0
- package/dist/html.d.cts +20 -0
- package/dist/html.d.ts +20 -0
- package/dist/html.js +45 -0
- package/dist/index.cjs +181 -14
- package/dist/index.d.cts +14 -62
- package/dist/index.d.ts +14 -62
- package/dist/index.js +11 -1
- package/dist/labels-CrA-iqTN.d.cts +46 -0
- package/dist/labels-CrA-iqTN.d.ts +46 -0
- package/dist/mermaid-diagram.cjs +453 -148
- package/dist/mermaid-diagram.d.cts +25 -42
- package/dist/mermaid-diagram.d.ts +25 -42
- package/dist/mermaid-diagram.js +205 -50
- package/dist/mermaid-image.cjs +1456 -0
- package/dist/mermaid-image.d.cts +30 -0
- package/dist/mermaid-image.d.ts +30 -0
- package/dist/mermaid-image.js +93 -0
- package/dist/next.cjs +1709 -1134
- package/dist/next.d.cts +67 -14
- package/dist/next.d.ts +67 -14
- package/dist/next.js +950 -794
- package/dist/print-coordinator.cjs +157 -0
- package/dist/print-coordinator.d.cts +27 -0
- package/dist/print-coordinator.d.ts +27 -0
- package/dist/print-coordinator.js +83 -0
- package/dist/react.cjs +677 -264
- package/dist/react.d.cts +161 -31
- package/dist/react.d.ts +161 -31
- package/dist/react.js +23 -3
- package/dist/reactions.cjs +653 -0
- package/dist/reactions.d.cts +27 -0
- package/dist/reactions.d.ts +27 -0
- package/dist/reactions.js +364 -0
- package/dist/{resolve-DC2ccfwA.d.ts → resolve-BjAK0k_Y.d.ts} +2 -2
- package/dist/{resolve-DKLVftk_.d.cts → resolve-eI1muCKL.d.cts} +2 -2
- package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
- package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
- package/dist/sanitize-ijiWjEm9.d.cts +23 -0
- package/dist/sanitize-ijiWjEm9.d.ts +23 -0
- package/dist/styles.css +107 -47
- package/dist/toc-spy.cjs +59 -0
- package/dist/toc-spy.d.cts +15 -0
- package/dist/toc-spy.d.ts +15 -0
- package/dist/toc-spy.js +35 -0
- package/dist/{types-ByodIyEv.d.cts → types-3F0wqD-o.d.cts} +44 -4
- package/dist/{types-ByodIyEv.d.ts → types-3F0wqD-o.d.ts} +44 -4
- package/dist/use-cache.cjs +37 -11
- package/dist/use-cache.d.cts +12 -5
- package/dist/use-cache.d.ts +12 -5
- package/dist/use-cache.js +7 -7
- package/dist/youtube-facade.cjs +50 -0
- package/dist/youtube-facade.d.cts +17 -0
- package/dist/youtube-facade.d.ts +17 -0
- package/dist/youtube-facade.js +26 -0
- package/package.json +16 -3
- package/dist/chunk-4V4VKB3O.js +0 -1471
- package/dist/chunk-R5EMI4HQ.js +0 -61
- package/dist/revalidation-callback-D7Ms_Puz.d.cts +0 -42
- package/dist/revalidation-callback-D7Ms_Puz.d.ts +0 -42
package/dist/next.cjs
CHANGED
|
@@ -30,9 +30,11 @@ __export(next_exports, {
|
|
|
30
30
|
createEngagementRoute: () => createEngagementRoute,
|
|
31
31
|
createLlmsTxtRoute: () => createLlmsTxtRoute,
|
|
32
32
|
createMarkdownRoute: () => createMarkdownRoute,
|
|
33
|
+
createOgImageRoute: () => createOgImageRoute,
|
|
33
34
|
createRevalidateRoute: () => createRevalidateRoute,
|
|
34
35
|
fetchResolver: () => fetchResolver,
|
|
35
36
|
hyleFeed: () => hyleFeed,
|
|
37
|
+
hyleFeedLink: () => hyleFeedLink,
|
|
36
38
|
hyleMetadata: () => hyleMetadata,
|
|
37
39
|
hylePage: () => hylePage,
|
|
38
40
|
hyleRootMetadata: () => hyleRootMetadata,
|
|
@@ -45,7 +47,7 @@ __export(next_exports, {
|
|
|
45
47
|
module.exports = __toCommonJS(next_exports);
|
|
46
48
|
|
|
47
49
|
// src/next/page.tsx
|
|
48
|
-
var
|
|
50
|
+
var import_navigation3 = require("next/navigation");
|
|
49
51
|
|
|
50
52
|
// src/asset-path.ts
|
|
51
53
|
var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
|
|
@@ -90,6 +92,18 @@ var Cp1ClientError = class extends Error {
|
|
|
90
92
|
};
|
|
91
93
|
|
|
92
94
|
// src/client.ts
|
|
95
|
+
var RENDERER_VERSION = "4";
|
|
96
|
+
function applyCredential(headers, credential, method, url) {
|
|
97
|
+
if (!credential.auth) {
|
|
98
|
+
headers.set("authorization", `Bearer ${credential.token}`);
|
|
99
|
+
return void 0;
|
|
100
|
+
}
|
|
101
|
+
const { workspaceId } = credential;
|
|
102
|
+
return credential.auth({ method, url }).then((extra) => {
|
|
103
|
+
for (const [name, value] of Object.entries(extra)) headers.set(name, value);
|
|
104
|
+
headers.set("cp-workspace", workspaceId);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
93
107
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
94
108
|
var DEFAULT_MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
|
|
95
109
|
var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
@@ -131,14 +145,16 @@ function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
|
131
145
|
}
|
|
132
146
|
function createHyleClient(options) {
|
|
133
147
|
checkBaseUrl(options.baseUrl, options.allowInsecureHttp);
|
|
134
|
-
if (!options.token) throw new TypeError("token is required");
|
|
148
|
+
if (!options.auth && !options.token) throw new TypeError("token is required");
|
|
135
149
|
const base = options.baseUrl.replace(/\/+$/, "");
|
|
136
150
|
const fetchImpl = options.fetch ?? fetch;
|
|
137
151
|
async function get(pathname, query, init) {
|
|
138
152
|
const url = new URL(`${base}${pathname}`);
|
|
139
153
|
url.search = query.toString();
|
|
140
154
|
const headers = new Headers(init?.headers);
|
|
141
|
-
headers.set("
|
|
155
|
+
headers.set("cp-renderer-version", RENDERER_VERSION);
|
|
156
|
+
const applied = applyCredential(headers, options, "GET", url.toString());
|
|
157
|
+
if (applied) await applied;
|
|
142
158
|
const timeout = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
143
159
|
const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
|
|
144
160
|
const res = await fetchImpl(url.toString(), { ...init, method: "GET", headers, redirect: "error", signal });
|
|
@@ -178,16 +194,28 @@ function createHyleClient(options) {
|
|
|
178
194
|
if (data?.cp === 1 && data.kind === "mounts" && isMounts(data)) return data;
|
|
179
195
|
throw failure(reply2);
|
|
180
196
|
}
|
|
197
|
+
async function pushPosts(opts) {
|
|
198
|
+
if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(opts.section)) throw new TypeError("section must be a section slug");
|
|
199
|
+
const query = new URLSearchParams();
|
|
200
|
+
if (opts.cursor !== void 0) query.set("cursor", opts.cursor);
|
|
201
|
+
const reply2 = await get(`/cp1/read/sections/${opts.section}/posts`, query, opts.init);
|
|
202
|
+
const data = reply2.parsed?.data;
|
|
203
|
+
if (data?.cp === 1 && data.kind === "push_posts" && Array.isArray(data.posts) && typeof data.complete === "boolean") return data;
|
|
204
|
+
throw failure(reply2);
|
|
205
|
+
}
|
|
181
206
|
async function asset(file, opts = {}) {
|
|
182
207
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
183
|
-
const
|
|
208
|
+
const url = `${base}/cp1/read/assets/${file}`;
|
|
209
|
+
const headers = new Headers();
|
|
210
|
+
const applied = applyCredential(headers, options, "GET", url);
|
|
211
|
+
if (applied) await applied;
|
|
184
212
|
for (const name of ["range", "if-range", "if-none-match"]) {
|
|
185
213
|
const value = opts.headers?.[name];
|
|
186
214
|
if (value) headers.set(name, value);
|
|
187
215
|
}
|
|
188
|
-
return fetchImpl(
|
|
216
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
189
217
|
}
|
|
190
|
-
return { resolve, mounts, asset };
|
|
218
|
+
return { resolve, mounts, pushPosts, asset };
|
|
191
219
|
}
|
|
192
220
|
|
|
193
221
|
// src/delivery-dedupe.ts
|
|
@@ -264,6 +292,35 @@ function isValidCacheTag(tag2) {
|
|
|
264
292
|
// src/revalidation-callback.ts
|
|
265
293
|
var MAX_BODY_BYTES = 65536;
|
|
266
294
|
var MAX_TAGS = 1e3;
|
|
295
|
+
var HOOK_WAIT_MS = 3e3;
|
|
296
|
+
var COMMENT_EVENT_TYPES = ["comment.held", "comment.reply", "comment.approved", "comment.hidden"];
|
|
297
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
298
|
+
var isText = (v) => typeof v === "string" && v.length > 0;
|
|
299
|
+
var isTextOrNull = (v) => v === null || isText(v);
|
|
300
|
+
var isEventPath = (v) => typeof v === "string" && v.startsWith("/") && !v.startsWith("//") && v.length <= 2048 && !/[\\\u0000-\u001f\u007f]/.test(v);
|
|
301
|
+
function parseCommentEvent(payload) {
|
|
302
|
+
if (!isRecord(payload) || payload.cp !== 1 || !isRecord(payload.data)) return void 0;
|
|
303
|
+
const type = COMMENT_EVENT_TYPES.find((t) => t === payload.type);
|
|
304
|
+
const { id, created_at, workspace_id, event_id, data } = payload;
|
|
305
|
+
if (!type || !isText(id) || !isText(created_at) || !isText(workspace_id) || !isText(event_id)) return void 0;
|
|
306
|
+
const { comment_id, parent_comment_id, publication_path, reader_sub, parent_reader_sub, status } = data;
|
|
307
|
+
if (!isText(comment_id) || !isTextOrNull(parent_comment_id) || !isEventPath(publication_path) || !isTextOrNull(reader_sub) || !isTextOrNull(parent_reader_sub)) return void 0;
|
|
308
|
+
if (status !== "held" && status !== "visible" && status !== "hidden") return void 0;
|
|
309
|
+
return { cp: 1, id, type, created_at, workspace_id, event_id, data: { comment_id, parent_comment_id, publication_path, reader_sub, parent_reader_sub, status } };
|
|
310
|
+
}
|
|
311
|
+
async function runHook(hook, event) {
|
|
312
|
+
let timer;
|
|
313
|
+
try {
|
|
314
|
+
await Promise.race([
|
|
315
|
+
Promise.resolve().then(() => hook(event)),
|
|
316
|
+
new Promise((_, reject) => timer = setTimeout(() => reject(new Error("timeout")), HOOK_WAIT_MS))
|
|
317
|
+
]);
|
|
318
|
+
} catch {
|
|
319
|
+
console.error(`hyle: onCommentEvent failed or timed out for ${event.type} ${event.id}`);
|
|
320
|
+
} finally {
|
|
321
|
+
clearTimeout(timer);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
267
324
|
function createRevalidationCallbackRoute(options) {
|
|
268
325
|
const dedupe = new DeliveryDedupe(options.dedupeCapacity);
|
|
269
326
|
return {
|
|
@@ -298,7 +355,7 @@ function createRevalidationCallbackRoute(options) {
|
|
|
298
355
|
if (body.workspace_id !== options.workspaceId) {
|
|
299
356
|
return okResponse(0);
|
|
300
357
|
}
|
|
301
|
-
const deliveryId =
|
|
358
|
+
const deliveryId = typeof body.id === "string" ? body.id : void 0;
|
|
302
359
|
if (deliveryId && dedupe.has(deliveryId)) {
|
|
303
360
|
return okResponse(0);
|
|
304
361
|
}
|
|
@@ -313,6 +370,9 @@ function createRevalidationCallbackRoute(options) {
|
|
|
313
370
|
return new Response(null, { status: 500 });
|
|
314
371
|
}
|
|
315
372
|
if (deliveryId) dedupe.add(deliveryId);
|
|
373
|
+
const hook = options.onCommentEvent;
|
|
374
|
+
const event = hook && parseCommentEvent(body);
|
|
375
|
+
if (hook && event) await runHook(hook, event);
|
|
316
376
|
return okResponse(purged);
|
|
317
377
|
}
|
|
318
378
|
};
|
|
@@ -454,9 +514,16 @@ var SHAPES = {
|
|
|
454
514
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9 1.8v3h3" })
|
|
455
515
|
] }),
|
|
456
516
|
chev: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m6 3.5 4.5 4.5L6 12.5" }),
|
|
517
|
+
"chev-up": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3.5 10 4.5-4.5L12.5 10" }),
|
|
457
518
|
"chev-down": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3.5 6 4.5 4.5L12.5 6" }),
|
|
458
519
|
"chev-left": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 3.5 5.5 8 10 12.5" }),
|
|
459
520
|
x: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m4 4 8 8M12 4l-8 8" }),
|
|
521
|
+
important: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 2.5h10a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H8l-3.5 2.8v-2.8H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1zM8 5v2.8M8 9.5v.1" }),
|
|
522
|
+
copy: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
523
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "5.5", y: "5.5", width: "8", height: "8", rx: "1.3" }),
|
|
524
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10.5 5.5v-2a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2" })
|
|
525
|
+
] }),
|
|
526
|
+
check: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3 8.5 3.2 3L13 4.5" }),
|
|
460
527
|
heart: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 13.5S2.2 10 2.2 6.1A3 3 0 0 1 8 5a3 3 0 0 1 5.8 1.1C13.8 10 8 13.5 8 13.5z" }),
|
|
461
528
|
reply: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6.5 3.5 2.5 7.5l4 4M2.5 7.5h6a5 5 0 0 1 5 5" }),
|
|
462
529
|
clock: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
@@ -475,9 +542,7 @@ function Icon({ name, className }) {
|
|
|
475
542
|
|
|
476
543
|
// src/react/content.tsx
|
|
477
544
|
var import_mermaid_diagram = require("./mermaid-diagram.cjs");
|
|
478
|
-
|
|
479
|
-
// src/react/mermaid-config.ts
|
|
480
|
-
var MAX_MERMAID_SOURCE = 2e4;
|
|
545
|
+
var import_mermaid_image = require("./mermaid-image.cjs");
|
|
481
546
|
|
|
482
547
|
// src/react/sanitize.ts
|
|
483
548
|
var HastLimitError = class extends Error {
|
|
@@ -489,7 +554,7 @@ var HastLimitError = class extends Error {
|
|
|
489
554
|
var MAX_NODES = 2e4;
|
|
490
555
|
var MAX_TEXT = 512 * 1024;
|
|
491
556
|
var MAX_DEPTH = 128;
|
|
492
|
-
var MAX_SRCDOC =
|
|
557
|
+
var MAX_SRCDOC = 1024 * 1024;
|
|
493
558
|
var DROP = /* @__PURE__ */ new Set(["script", "style", "template", "noscript"]);
|
|
494
559
|
var VOID = /* @__PURE__ */ new Set(["br", "hr", "img", "input", "path"]);
|
|
495
560
|
var isString = (v) => typeof v === "string";
|
|
@@ -497,8 +562,15 @@ var isScalar = (v) => typeof v === "string" || typeof v === "number" || typeof v
|
|
|
497
562
|
var matches = (re) => (v) => typeof v === "string" && re.test(v);
|
|
498
563
|
var ID_PREFIX = "user-content-";
|
|
499
564
|
var scopeId = (id) => id.startsWith(ID_PREFIX) ? id : ID_PREFIX + id;
|
|
500
|
-
var ID_BODY = /^[\p{L}\p{N}
|
|
501
|
-
|
|
565
|
+
var ID_BODY = /^[\p{L}\p{M}\p{N}\p{Pc}:.-]{1,180}$/u;
|
|
566
|
+
function isIdValue(v) {
|
|
567
|
+
if (typeof v !== "string") return false;
|
|
568
|
+
try {
|
|
569
|
+
return ID_BODY.test(decodeURIComponent(v.startsWith(ID_PREFIX) ? v.slice(ID_PREFIX.length) : v));
|
|
570
|
+
} catch {
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
502
574
|
var CLASS_TOKEN = /^[A-Za-z_][\w:-]*$/;
|
|
503
575
|
var classTokens = (v) => {
|
|
504
576
|
const tokens = Array.isArray(v) ? v : typeof v === "string" ? v.split(/\s+/) : [];
|
|
@@ -506,10 +578,12 @@ var classTokens = (v) => {
|
|
|
506
578
|
};
|
|
507
579
|
var isClass = (v) => classTokens(v) !== void 0;
|
|
508
580
|
var isAlign = matches(/^(left|right|center)$/);
|
|
581
|
+
var isPixels = (v) => typeof v === "number" ? Number.isInteger(v) && v > 0 : typeof v === "string" && /^[1-9]\d*$/.test(v);
|
|
509
582
|
var isLength = matches(/^[\d.]+(em|px|%)?$/);
|
|
510
583
|
var STYLE_PROPS = /* @__PURE__ */ new Set(["height", "vertical-align", "margin-left", "margin-right", "margin-top", "margin-bottom", "top", "width", "min-width", "border-bottom-width", "padding-left"]);
|
|
511
584
|
var STYLE_LENGTH = /^(-?\d+(?:\.\d+)?)(em|px|%)?$/;
|
|
512
585
|
var MAX_STYLE_MAGNITUDE = 100;
|
|
586
|
+
var MAX_MARGIN_MAGNITUDE = 20;
|
|
513
587
|
function isKatexStyle(v, ctx2) {
|
|
514
588
|
if (typeof v !== "string" || !ctx2.katex) return false;
|
|
515
589
|
return v.split(";").filter((d) => d !== "").every((decl) => {
|
|
@@ -517,7 +591,8 @@ function isKatexStyle(v, ctx2) {
|
|
|
517
591
|
if (extra.length > 0 || prop === void 0 || value === void 0) return false;
|
|
518
592
|
if (prop === "position") return value === "relative";
|
|
519
593
|
const m = STYLE_LENGTH.exec(value);
|
|
520
|
-
|
|
594
|
+
const max = prop.startsWith("margin-") ? MAX_MARGIN_MAGNITUDE : MAX_STYLE_MAGNITUDE;
|
|
595
|
+
return STYLE_PROPS.has(prop) && m !== null && Math.abs(Number(m[1])) <= max;
|
|
521
596
|
});
|
|
522
597
|
}
|
|
523
598
|
function isSafeUrl(value, kind) {
|
|
@@ -542,10 +617,16 @@ var MERMAID_SRCDOC = new RegExp(
|
|
|
542
617
|
var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
|
|
543
618
|
var ENTITIES = { "<": "<", "&": "&", "<": "<", ">": ">", "&": "&", """: '"', "'": "'" };
|
|
544
619
|
function mermaidSource(srcDoc) {
|
|
545
|
-
|
|
546
|
-
return text === void 0 || text.length > MAX_MERMAID_SOURCE ? void 0 : text;
|
|
620
|
+
return MERMAID_SRCDOC.exec(srcDoc)?.[1]?.replace(/&(?:#x3c|#x26|#x27|lt|gt|amp|quot);/gi, (e) => ENTITIES[e.toLowerCase()]);
|
|
547
621
|
}
|
|
548
|
-
var
|
|
622
|
+
var RENDER_REF = /^(\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.svg) ([1-9]\d{0,5}) ([1-9]\d{0,5})$/;
|
|
623
|
+
var isRenderRef = matches(RENDER_REF);
|
|
624
|
+
function diagramRender(value) {
|
|
625
|
+
const m = typeof value === "string" ? RENDER_REF.exec(value) : null;
|
|
626
|
+
return m ? { src: hostAssetSrc(m[1]), width: Number(m[2]), height: Number(m[3]) } : void 0;
|
|
627
|
+
}
|
|
628
|
+
var YOUTUBE_WATCH = /^https:\/\/www\.youtube\.com\/watch\?v=([A-Za-z0-9_-]{11})$/;
|
|
629
|
+
var youtubeId = (href) => typeof href === "string" ? YOUTUBE_WATCH.exec(href)?.[1] : void 0;
|
|
549
630
|
var heading = { id: isIdValue, className: isClass };
|
|
550
631
|
var ATTRS = new Map(
|
|
551
632
|
Object.entries({
|
|
@@ -561,6 +642,7 @@ var ATTRS = new Map(
|
|
|
561
642
|
tbody: {},
|
|
562
643
|
tr: {},
|
|
563
644
|
ol: {},
|
|
645
|
+
kbd: {},
|
|
564
646
|
ul: { className: isClass },
|
|
565
647
|
li: { id: isIdValue, className: isClass },
|
|
566
648
|
h1: heading,
|
|
@@ -569,8 +651,8 @@ var ATTRS = new Map(
|
|
|
569
651
|
h4: heading,
|
|
570
652
|
h5: heading,
|
|
571
653
|
h6: heading,
|
|
572
|
-
a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, className: isClass },
|
|
573
|
-
img: { src: isSrc, alt: isString },
|
|
654
|
+
a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, dataEmbed: matches(/^youtube$/), className: isClass },
|
|
655
|
+
img: { src: isSrc, alt: isString, title: isString, width: isPixels, height: isPixels },
|
|
574
656
|
table: {},
|
|
575
657
|
th: { scope: matches(/^(row|col|rowgroup|colgroup)$/), align: isAlign },
|
|
576
658
|
td: { align: isAlign },
|
|
@@ -584,7 +666,7 @@ var ATTRS = new Map(
|
|
|
584
666
|
video: { src: isSrc, controls: isScalar },
|
|
585
667
|
audio: { src: isSrc, controls: isScalar },
|
|
586
668
|
// hyle's sandboxed Mermaid frame (ADR 0001). The renderer emits `sandbox` as ["allow-scripts"]; it is normalized below.
|
|
587
|
-
iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc }
|
|
669
|
+
iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc, dataLight: isRenderRef, dataDark: isRenderRef }
|
|
588
670
|
})
|
|
589
671
|
);
|
|
590
672
|
var isObject = (v) => typeof v === "object" && v !== null;
|
|
@@ -593,8 +675,10 @@ function textOf(node, depth = 0) {
|
|
|
593
675
|
if (node.type === "text") return typeof node.value === "string" ? node.value : "";
|
|
594
676
|
return Array.isArray(node.children) ? node.children.map((c) => textOf(c, depth + 1)).join("") : "";
|
|
595
677
|
}
|
|
678
|
+
var holdsEmbed = (node, depth = 0) => isObject(node) && depth <= MAX_DEPTH && (isObject(node.properties) && "dataEmbed" in node.properties || Array.isArray(node.children) && node.children.some((c) => holdsEmbed(c, depth + 1)));
|
|
679
|
+
var collapse = (text) => text.replace(/\s+/g, " ").trim();
|
|
596
680
|
var CALLOUT_MARKER = /^\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*/i;
|
|
597
|
-
var CALLOUT_KIND = { note: "note", tip: "tip", important: "
|
|
681
|
+
var CALLOUT_KIND = { note: "note", tip: "tip", important: "important", warning: "warning", caution: "caution" };
|
|
598
682
|
function toCallout(children) {
|
|
599
683
|
const first = children.find((c) => c.type === "element");
|
|
600
684
|
const lead = first?.tagName === "p" ? first.children[0] : void 0;
|
|
@@ -606,6 +690,21 @@ function toCallout(children) {
|
|
|
606
690
|
const kind = CALLOUT_KIND[(marker[1] ?? "note").toLowerCase()] ?? "note";
|
|
607
691
|
return { type: "element", tagName: "callout", properties: { kind }, children: [...body, ...children.slice(children.indexOf(first) + 1)] };
|
|
608
692
|
}
|
|
693
|
+
var isBlank = (node) => node.type === "text" && node.value.trim() === "";
|
|
694
|
+
function soleElement(children) {
|
|
695
|
+
const [only, ...more] = children.filter((c) => !isBlank(c));
|
|
696
|
+
return more.length === 0 && only?.type === "element" ? only : void 0;
|
|
697
|
+
}
|
|
698
|
+
function toFigure(children) {
|
|
699
|
+
const only = soleElement(children);
|
|
700
|
+
const img = only?.tagName === "a" ? soleElement(only.children) : only;
|
|
701
|
+
if (!only || img?.tagName !== "img" || typeof img.properties.src !== "string") return void 0;
|
|
702
|
+
const { title, ...properties } = img.properties;
|
|
703
|
+
const bare = { ...img, properties };
|
|
704
|
+
const media = only === img ? bare : { ...only, children: [bare] };
|
|
705
|
+
const caption = typeof title === "string" && title.trim() ? [{ type: "element", tagName: "figcaption", properties: {}, children: [{ type: "text", value: title }] }] : [];
|
|
706
|
+
return { type: "element", tagName: "figure", properties: { dataSlotComponent: "Image" }, children: [media, ...caption] };
|
|
707
|
+
}
|
|
609
708
|
function clean(node, depth, ctx2, budget) {
|
|
610
709
|
if (!isObject(node) || depth > MAX_DEPTH) return [];
|
|
611
710
|
if (++budget.nodes > MAX_NODES) throw new HastLimitError("content has too many nodes");
|
|
@@ -639,6 +738,11 @@ function clean(node, depth, ctx2, budget) {
|
|
|
639
738
|
}
|
|
640
739
|
for (const key of ["id", "ariaDescribedBy"]) if (typeof properties[key] === "string") properties[key] = scopeId(properties[key]);
|
|
641
740
|
if (tag2 === "a" && typeof properties.href === "string" && properties.href.trim().startsWith("#")) properties.href = `#${scopeId(properties.href.trim().slice(1))}`;
|
|
741
|
+
if (tag2 === "a" && properties.dataEmbed !== void 0 && youtubeId(properties.href) === void 0) delete properties.dataEmbed;
|
|
742
|
+
if (tag2 === "p") {
|
|
743
|
+
const figure = toFigure(children);
|
|
744
|
+
if (figure) return [figure];
|
|
745
|
+
}
|
|
642
746
|
if (tag2 === "blockquote") {
|
|
643
747
|
const callout = toCallout(children);
|
|
644
748
|
if (callout) return [callout];
|
|
@@ -650,9 +754,9 @@ function sanitizeHast(tree, title, description) {
|
|
|
650
754
|
const raw = isObject(tree) && tree.type === "root" && Array.isArray(tree.children) ? tree.children : [];
|
|
651
755
|
const elements = raw.filter((n) => isObject(n) && n.type === "element");
|
|
652
756
|
const [first] = elements;
|
|
653
|
-
const skip = title !== void 0 && isObject(first) && first.tagName === "h1" && textOf(first)
|
|
757
|
+
const skip = title !== void 0 && isObject(first) && first.tagName === "h1" && collapse(textOf(first)) === collapse(title) ? first : void 0;
|
|
654
758
|
const lead = elements[skip ? 1 : 0];
|
|
655
|
-
const repeat = description && isObject(lead) && lead.tagName === "p" && textOf(lead)
|
|
759
|
+
const repeat = description && isObject(lead) && lead.tagName === "p" && collapse(textOf(lead)).startsWith(collapse(description)) && !holdsEmbed(lead) ? lead : void 0;
|
|
656
760
|
const budget = { nodes: 0, text: 0 };
|
|
657
761
|
return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
|
|
658
762
|
}
|
|
@@ -691,6 +795,7 @@ var COMMENT_LABELS_EN = {
|
|
|
691
795
|
removed: "This comment was removed.",
|
|
692
796
|
removedByModerator: "This comment was removed by a moderator.",
|
|
693
797
|
removedByAuthor: "This comment was deleted by its author.",
|
|
798
|
+
unrenderable: "This comment cannot be displayed.",
|
|
694
799
|
depthEnd: "Replies end at this depth",
|
|
695
800
|
held: "Awaiting approval.",
|
|
696
801
|
heldBanner: "Thanks, your comment is awaiting approval",
|
|
@@ -717,8 +822,39 @@ var COMMENT_LABELS_EN = {
|
|
|
717
822
|
bannedBody: "Commenting is not available for your account on this site. You can still read every comment. If you think this is a mistake, contact the site team.",
|
|
718
823
|
expired: "Your session ended. Sign in again to post. Your text is kept.",
|
|
719
824
|
more: "Load more comments",
|
|
720
|
-
truncated: "
|
|
721
|
-
justNow: "just now"
|
|
825
|
+
truncated: "Only the first part of this discussion is shown.",
|
|
826
|
+
justNow: "just now",
|
|
827
|
+
react: "React",
|
|
828
|
+
reactions: "Reactions",
|
|
829
|
+
reactionLike: "Like",
|
|
830
|
+
reactionLove: "Love",
|
|
831
|
+
reactionInsightful: "Insightful",
|
|
832
|
+
reactionCelebrate: "Celebrate",
|
|
833
|
+
reactionSignIn: "Sign in to react, ",
|
|
834
|
+
reactionAddedLive: "{kind} reaction added",
|
|
835
|
+
reactionRemovedLive: "{kind} reaction removed",
|
|
836
|
+
reactionsLoading: "Loading reactions",
|
|
837
|
+
reactionsError: "Reactions could not be loaded",
|
|
838
|
+
votesOn: "Votes on the comment by {name}",
|
|
839
|
+
score: "Score {n}",
|
|
840
|
+
upvote: "Upvote",
|
|
841
|
+
downvote: "Downvote",
|
|
842
|
+
upvoteSignIn: "Sign in to upvote",
|
|
843
|
+
downvoteSignIn: "Sign in to downvote",
|
|
844
|
+
upvotedLive: "Upvoted. Score {n}",
|
|
845
|
+
downvotedLive: "Downvoted. Score {n}",
|
|
846
|
+
voteRemovedLive: "Vote removed. Score {n}",
|
|
847
|
+
voteRefused: "That vote was not accepted. You cannot vote on your own comment.",
|
|
848
|
+
slowDown: "Too many actions in a short time. Wait a moment and try again.",
|
|
849
|
+
sort: "Sort comments",
|
|
850
|
+
sortNewest: "Newest",
|
|
851
|
+
sortTop: "Top",
|
|
852
|
+
sortedNewestLive: "Showing newest comments first",
|
|
853
|
+
sortedTopLive: "Showing top comments first",
|
|
854
|
+
sortError: "The comments could not be sorted. Please try again.",
|
|
855
|
+
newerLater: "Newer comments appear after you load more.",
|
|
856
|
+
moreError: "More comments could not be loaded. Please try again.",
|
|
857
|
+
loadedLive: "{n} comments loaded"
|
|
722
858
|
};
|
|
723
859
|
var COMMENT_LABELS_FR = {
|
|
724
860
|
heading: "Commentaires",
|
|
@@ -753,6 +889,7 @@ var COMMENT_LABELS_FR = {
|
|
|
753
889
|
removed: "Ce commentaire a \xE9t\xE9 retir\xE9.",
|
|
754
890
|
removedByModerator: "Ce commentaire a \xE9t\xE9 retir\xE9 par un mod\xE9rateur.",
|
|
755
891
|
removedByAuthor: "Ce commentaire a \xE9t\xE9 supprim\xE9 par son auteur.",
|
|
892
|
+
unrenderable: "Ce commentaire ne peut pas \xEAtre affich\xE9.",
|
|
756
893
|
depthEnd: "Les r\xE9ponses s'arr\xEAtent \xE0 ce niveau",
|
|
757
894
|
held: "En attente d'approbation.",
|
|
758
895
|
heldBanner: "Merci, votre commentaire est en attente d'approbation",
|
|
@@ -779,8 +916,39 @@ var COMMENT_LABELS_FR = {
|
|
|
779
916
|
bannedBody: "Les commentaires ne sont pas disponibles pour votre compte sur ce site. Vous pouvez toujours tout lire. Si vous pensez \xE0 une erreur, contactez l'\xE9quipe du site.",
|
|
780
917
|
expired: "Votre session a expir\xE9. Reconnectez-vous pour publier. Votre texte est conserv\xE9.",
|
|
781
918
|
more: "Charger plus de commentaires",
|
|
782
|
-
truncated: "
|
|
783
|
-
justNow: "\xE0 l'instant"
|
|
919
|
+
truncated: "Seul le d\xE9but de cette discussion est affich\xE9.",
|
|
920
|
+
justNow: "\xE0 l'instant",
|
|
921
|
+
react: "R\xE9agir",
|
|
922
|
+
reactions: "R\xE9actions",
|
|
923
|
+
reactionLike: "J'aime",
|
|
924
|
+
reactionLove: "J'adore",
|
|
925
|
+
reactionInsightful: "Instructif",
|
|
926
|
+
reactionCelebrate: "Bravo",
|
|
927
|
+
reactionSignIn: "Connectez-vous pour r\xE9agir, ",
|
|
928
|
+
reactionAddedLive: "R\xE9action {kind} ajout\xE9e",
|
|
929
|
+
reactionRemovedLive: "R\xE9action {kind} retir\xE9e",
|
|
930
|
+
reactionsLoading: "Chargement des r\xE9actions",
|
|
931
|
+
reactionsError: "Les r\xE9actions n'ont pas pu \xEAtre charg\xE9es",
|
|
932
|
+
votesOn: "Votes sur le commentaire de {name}",
|
|
933
|
+
score: "Score {n}",
|
|
934
|
+
upvote: "Voter pour",
|
|
935
|
+
downvote: "Voter contre",
|
|
936
|
+
upvoteSignIn: "Connectez-vous pour voter pour",
|
|
937
|
+
downvoteSignIn: "Connectez-vous pour voter contre",
|
|
938
|
+
upvotedLive: "Vote pour enregistr\xE9. Score {n}",
|
|
939
|
+
downvotedLive: "Vote contre enregistr\xE9. Score {n}",
|
|
940
|
+
voteRemovedLive: "Vote retir\xE9. Score {n}",
|
|
941
|
+
voteRefused: "Ce vote a \xE9t\xE9 refus\xE9. Vous ne pouvez pas voter pour votre propre commentaire.",
|
|
942
|
+
slowDown: "Trop d'actions en peu de temps. Patientez un instant et r\xE9essayez.",
|
|
943
|
+
sort: "Trier les commentaires",
|
|
944
|
+
sortNewest: "R\xE9cents",
|
|
945
|
+
sortTop: "Meilleurs",
|
|
946
|
+
sortedNewestLive: "Commentaires les plus r\xE9cents en premier",
|
|
947
|
+
sortedTopLive: "Meilleurs commentaires en premier",
|
|
948
|
+
sortError: "Les commentaires n'ont pas pu \xEAtre tri\xE9s. R\xE9essayez.",
|
|
949
|
+
newerLater: "Les commentaires plus r\xE9cents apparaissent apr\xE8s le chargement de la suite.",
|
|
950
|
+
moreError: "La suite des commentaires n'a pas pu \xEAtre charg\xE9e. R\xE9essayez.",
|
|
951
|
+
loadedLive: "{n} commentaires charg\xE9s"
|
|
784
952
|
};
|
|
785
953
|
var COMMENT_LABELS_ES = {
|
|
786
954
|
heading: "Comentarios",
|
|
@@ -815,6 +983,7 @@ var COMMENT_LABELS_ES = {
|
|
|
815
983
|
removed: "Este comentario fue eliminado.",
|
|
816
984
|
removedByModerator: "Un moderador elimin\xF3 este comentario.",
|
|
817
985
|
removedByAuthor: "Su autor elimin\xF3 este comentario.",
|
|
986
|
+
unrenderable: "Este comentario no se puede mostrar.",
|
|
818
987
|
depthEnd: "Las respuestas terminan en este nivel",
|
|
819
988
|
held: "Pendiente de aprobaci\xF3n.",
|
|
820
989
|
heldBanner: "Gracias, tu comentario est\xE1 pendiente de aprobaci\xF3n",
|
|
@@ -841,8 +1010,39 @@ var COMMENT_LABELS_ES = {
|
|
|
841
1010
|
bannedBody: "Los comentarios no est\xE1n disponibles para tu cuenta en este sitio. A\xFAn puedes leerlos todos. Si crees que es un error, contacta con el equipo del sitio.",
|
|
842
1011
|
expired: "Tu sesi\xF3n termin\xF3. Inicia sesi\xF3n de nuevo para publicar. Tu texto se conserva.",
|
|
843
1012
|
more: "Cargar m\xE1s comentarios",
|
|
844
|
-
truncated: "
|
|
845
|
-
justNow: "ahora mismo"
|
|
1013
|
+
truncated: "Solo se muestra la primera parte de esta conversaci\xF3n.",
|
|
1014
|
+
justNow: "ahora mismo",
|
|
1015
|
+
react: "Reaccionar",
|
|
1016
|
+
reactions: "Reacciones",
|
|
1017
|
+
reactionLike: "Me gusta",
|
|
1018
|
+
reactionLove: "Me encanta",
|
|
1019
|
+
reactionInsightful: "Interesante",
|
|
1020
|
+
reactionCelebrate: "Celebrar",
|
|
1021
|
+
reactionSignIn: "Inicia sesi\xF3n para reaccionar, ",
|
|
1022
|
+
reactionAddedLive: "Reacci\xF3n {kind} a\xF1adida",
|
|
1023
|
+
reactionRemovedLive: "Reacci\xF3n {kind} eliminada",
|
|
1024
|
+
reactionsLoading: "Cargando reacciones",
|
|
1025
|
+
reactionsError: "No se pudieron cargar las reacciones",
|
|
1026
|
+
votesOn: "Votos del comentario de {name}",
|
|
1027
|
+
score: "Puntuaci\xF3n {n}",
|
|
1028
|
+
upvote: "Votar a favor",
|
|
1029
|
+
downvote: "Votar en contra",
|
|
1030
|
+
upvoteSignIn: "Inicia sesi\xF3n para votar a favor",
|
|
1031
|
+
downvoteSignIn: "Inicia sesi\xF3n para votar en contra",
|
|
1032
|
+
upvotedLive: "Voto a favor registrado. Puntuaci\xF3n {n}",
|
|
1033
|
+
downvotedLive: "Voto en contra registrado. Puntuaci\xF3n {n}",
|
|
1034
|
+
voteRemovedLive: "Voto retirado. Puntuaci\xF3n {n}",
|
|
1035
|
+
voteRefused: "No se acept\xF3 el voto. No puedes votar tu propio comentario.",
|
|
1036
|
+
slowDown: "Demasiadas acciones en poco tiempo. Espera un momento e int\xE9ntalo de nuevo.",
|
|
1037
|
+
sort: "Ordenar comentarios",
|
|
1038
|
+
sortNewest: "Recientes",
|
|
1039
|
+
sortTop: "Destacados",
|
|
1040
|
+
sortedNewestLive: "Comentarios m\xE1s recientes primero",
|
|
1041
|
+
sortedTopLive: "Comentarios destacados primero",
|
|
1042
|
+
sortError: "No se pudieron ordenar los comentarios. Int\xE9ntalo de nuevo.",
|
|
1043
|
+
newerLater: "Los comentarios m\xE1s recientes aparecen al cargar m\xE1s.",
|
|
1044
|
+
moreError: "No se pudieron cargar m\xE1s comentarios. Int\xE9ntalo de nuevo.",
|
|
1045
|
+
loadedLive: "{n} comentarios cargados"
|
|
846
1046
|
};
|
|
847
1047
|
|
|
848
1048
|
// src/react/viewer/labels.ts
|
|
@@ -854,15 +1054,15 @@ var VIEWER_LABELS_EN = {
|
|
|
854
1054
|
zoomIn: "Zoom in",
|
|
855
1055
|
zoomOut: "Zoom out",
|
|
856
1056
|
fit: "Fit to window",
|
|
857
|
-
actual: "
|
|
1057
|
+
actual: "100%: actual size",
|
|
858
1058
|
search: "Find in diagram",
|
|
859
1059
|
searchPlaceholder: "Find",
|
|
860
1060
|
noMatch: "No match",
|
|
861
1061
|
matchOf: "{n} of {total}",
|
|
862
|
-
copySource: "
|
|
863
|
-
downloadSvg: "
|
|
864
|
-
downloadPng: "
|
|
865
|
-
copyImage: "
|
|
1062
|
+
copySource: "MMD: copy diagram source",
|
|
1063
|
+
downloadSvg: "SVG: download",
|
|
1064
|
+
downloadPng: "PNG: download",
|
|
1065
|
+
copyImage: "IMG: copy as image",
|
|
866
1066
|
pngScale: "PNG scale",
|
|
867
1067
|
fullscreen: "Fullscreen",
|
|
868
1068
|
exitFullscreen: "Exit fullscreen",
|
|
@@ -875,7 +1075,16 @@ var VIEWER_LABELS_EN = {
|
|
|
875
1075
|
legendDownstream: "Downstream",
|
|
876
1076
|
outgoing: "outgoing",
|
|
877
1077
|
tracing: "{label}: {up} upstream, {down} downstream",
|
|
878
|
-
map: "Overview map"
|
|
1078
|
+
map: "Overview map",
|
|
1079
|
+
largeTitle: "Large diagram, not drawn automatically",
|
|
1080
|
+
largeBody: "Drawing a diagram this size can freeze this page for a few seconds, so it waits until you ask. Press Draw diagram: it takes a couple of seconds (a few more on a phone) and the page may pause while it works.",
|
|
1081
|
+
drawLarge: "Draw diagram",
|
|
1082
|
+
drawing: "Drawing\u2026",
|
|
1083
|
+
drawingBody: "Drawing the diagram\u2026 this takes a couple of seconds.",
|
|
1084
|
+
drawAgain: "Draw again",
|
|
1085
|
+
showSource: "Show full source",
|
|
1086
|
+
hideSource: "Show less",
|
|
1087
|
+
printPreparing: "Preparing diagrams for print\u2026 Esc cancels between steps."
|
|
879
1088
|
};
|
|
880
1089
|
var VIEWER_LABELS_FR = {
|
|
881
1090
|
expand: "Agrandir le sch\xE9ma",
|
|
@@ -885,15 +1094,15 @@ var VIEWER_LABELS_FR = {
|
|
|
885
1094
|
zoomIn: "Zoom avant",
|
|
886
1095
|
zoomOut: "Zoom arri\xE8re",
|
|
887
1096
|
fit: "Ajuster \xE0 la fen\xEAtre",
|
|
888
|
-
actual: "
|
|
1097
|
+
actual: "100% : taille r\xE9elle",
|
|
889
1098
|
search: "Rechercher dans le sch\xE9ma",
|
|
890
1099
|
searchPlaceholder: "Rechercher",
|
|
891
1100
|
noMatch: "Aucun r\xE9sultat",
|
|
892
1101
|
matchOf: "{n} sur {total}",
|
|
893
|
-
copySource: "
|
|
894
|
-
downloadSvg: "
|
|
895
|
-
downloadPng: "
|
|
896
|
-
copyImage: "
|
|
1102
|
+
copySource: "MMD : copier la source du sch\xE9ma",
|
|
1103
|
+
downloadSvg: "SVG : t\xE9l\xE9charger",
|
|
1104
|
+
downloadPng: "PNG : t\xE9l\xE9charger",
|
|
1105
|
+
copyImage: "IMG : copier comme image",
|
|
897
1106
|
pngScale: "\xC9chelle du PNG",
|
|
898
1107
|
fullscreen: "Plein \xE9cran",
|
|
899
1108
|
exitFullscreen: "Quitter le plein \xE9cran",
|
|
@@ -906,7 +1115,16 @@ var VIEWER_LABELS_FR = {
|
|
|
906
1115
|
legendDownstream: "En aval",
|
|
907
1116
|
outgoing: "sortants",
|
|
908
1117
|
tracing: "{label} : {up} en amont, {down} en aval",
|
|
909
|
-
map: "Carte d'ensemble"
|
|
1118
|
+
map: "Carte d'ensemble",
|
|
1119
|
+
largeTitle: "Grand sch\xE9ma, non dessin\xE9 automatiquement",
|
|
1120
|
+
largeBody: "Dessiner un sch\xE9ma de cette taille peut figer la page quelques secondes, il attend donc votre demande. Appuyez sur Dessiner le sch\xE9ma : cela prend quelques secondes (un peu plus sur un t\xE9l\xE9phone) et la page peut se figer pendant ce temps.",
|
|
1121
|
+
drawLarge: "Dessiner le sch\xE9ma",
|
|
1122
|
+
drawing: "Dessin en cours\u2026",
|
|
1123
|
+
drawingBody: "Dessin du sch\xE9ma\u2026 cela prend quelques secondes.",
|
|
1124
|
+
drawAgain: "Redessiner",
|
|
1125
|
+
showSource: "Afficher toute la source",
|
|
1126
|
+
hideSource: "R\xE9duire",
|
|
1127
|
+
printPreparing: "Pr\xE9paration des sch\xE9mas pour l'impression\u2026 \xC9chap annule entre deux \xE9tapes."
|
|
910
1128
|
};
|
|
911
1129
|
var VIEWER_LABELS_ES = {
|
|
912
1130
|
expand: "Ampliar el diagrama",
|
|
@@ -916,15 +1134,15 @@ var VIEWER_LABELS_ES = {
|
|
|
916
1134
|
zoomIn: "Acercar",
|
|
917
1135
|
zoomOut: "Alejar",
|
|
918
1136
|
fit: "Ajustar a la ventana",
|
|
919
|
-
actual: "
|
|
1137
|
+
actual: "100%: tama\xF1o real",
|
|
920
1138
|
search: "Buscar en el diagrama",
|
|
921
1139
|
searchPlaceholder: "Buscar",
|
|
922
1140
|
noMatch: "Sin resultados",
|
|
923
1141
|
matchOf: "{n} de {total}",
|
|
924
|
-
copySource: "
|
|
925
|
-
downloadSvg: "
|
|
926
|
-
downloadPng: "
|
|
927
|
-
copyImage: "
|
|
1142
|
+
copySource: "MMD: copiar el c\xF3digo del diagrama",
|
|
1143
|
+
downloadSvg: "SVG: descargar",
|
|
1144
|
+
downloadPng: "PNG: descargar",
|
|
1145
|
+
copyImage: "IMG: copiar como imagen",
|
|
928
1146
|
pngScale: "Escala del PNG",
|
|
929
1147
|
fullscreen: "Pantalla completa",
|
|
930
1148
|
exitFullscreen: "Salir de pantalla completa",
|
|
@@ -937,7 +1155,16 @@ var VIEWER_LABELS_ES = {
|
|
|
937
1155
|
legendDownstream: "Aguas abajo",
|
|
938
1156
|
outgoing: "salientes",
|
|
939
1157
|
tracing: "{label}: {up} aguas arriba, {down} aguas abajo",
|
|
940
|
-
map: "Mapa general"
|
|
1158
|
+
map: "Mapa general",
|
|
1159
|
+
largeTitle: "Diagrama grande, no se dibuja autom\xE1ticamente",
|
|
1160
|
+
largeBody: "Dibujar un diagrama de este tama\xF1o puede bloquear la p\xE1gina unos segundos, as\xED que espera a que lo pidas. Pulsa Dibujar el diagrama: tarda un par de segundos (algo m\xE1s en un tel\xE9fono) y la p\xE1gina puede detenerse mientras tanto.",
|
|
1161
|
+
drawLarge: "Dibujar el diagrama",
|
|
1162
|
+
drawing: "Dibujando\u2026",
|
|
1163
|
+
drawingBody: "Dibujando el diagrama\u2026 tarda un par de segundos.",
|
|
1164
|
+
drawAgain: "Dibujar de nuevo",
|
|
1165
|
+
showSource: "Mostrar todo el c\xF3digo",
|
|
1166
|
+
hideSource: "Mostrar menos",
|
|
1167
|
+
printPreparing: "Preparando los diagramas para imprimir\u2026 Esc cancela entre pasos."
|
|
941
1168
|
};
|
|
942
1169
|
|
|
943
1170
|
// src/react/strings.ts
|
|
@@ -956,13 +1183,27 @@ var en = {
|
|
|
956
1183
|
warning: "Heads up",
|
|
957
1184
|
tip: "Tip",
|
|
958
1185
|
caution: "Caution",
|
|
1186
|
+
important: "Important",
|
|
1187
|
+
copyCode: "Copy code",
|
|
1188
|
+
copied: "Copied",
|
|
1189
|
+
copyBlocked: "Copy blocked",
|
|
1190
|
+
done: "Done",
|
|
1191
|
+
notDone: "Not done",
|
|
1192
|
+
playVideo: "Play video",
|
|
1193
|
+
videoFrame: "YouTube video",
|
|
959
1194
|
diagram: "Diagram",
|
|
960
1195
|
diagramError: "This diagram could not be rendered.",
|
|
1196
|
+
diagramLoading: "Loading the diagram",
|
|
1197
|
+
diagramSource: "Diagram source",
|
|
961
1198
|
contentError: "This content cannot be displayed.",
|
|
962
1199
|
fallbackTitle: "Not translated into {language} yet.",
|
|
963
1200
|
fallbackBody: "You are reading the original.",
|
|
1201
|
+
readingTime: "{n} min read",
|
|
1202
|
+
readingTimeLabel: "Reading time",
|
|
964
1203
|
older: "Older posts",
|
|
965
1204
|
viewAll: "View all",
|
|
1205
|
+
moreInSection: "More in this section",
|
|
1206
|
+
subPages: "In this section",
|
|
966
1207
|
readAtSource: "Read at source",
|
|
967
1208
|
emptyTitle: "Nothing published here yet",
|
|
968
1209
|
emptyBody: "Documents published to this section will appear here, newest first.",
|
|
@@ -1002,13 +1243,27 @@ var fr = {
|
|
|
1002
1243
|
warning: "Attention",
|
|
1003
1244
|
tip: "Astuce",
|
|
1004
1245
|
caution: "Danger",
|
|
1246
|
+
important: "Important",
|
|
1247
|
+
copyCode: "Copier le code",
|
|
1248
|
+
copied: "Copi\xE9",
|
|
1249
|
+
copyBlocked: "Copie bloqu\xE9e",
|
|
1250
|
+
done: "Termin\xE9",
|
|
1251
|
+
notDone: "\xC0 faire",
|
|
1252
|
+
playVideo: "Lire la vid\xE9o",
|
|
1253
|
+
videoFrame: "Vid\xE9o YouTube",
|
|
1005
1254
|
diagram: "Sch\xE9ma",
|
|
1006
1255
|
diagramError: "Ce sch\xE9ma n'a pas pu \xEAtre affich\xE9.",
|
|
1256
|
+
diagramLoading: "Chargement du sch\xE9ma",
|
|
1257
|
+
diagramSource: "Source du sch\xE9ma",
|
|
1007
1258
|
contentError: "Ce contenu ne peut pas \xEAtre affich\xE9.",
|
|
1008
1259
|
fallbackTitle: "Pas encore traduit en {language}.",
|
|
1009
1260
|
fallbackBody: "Vous lisez l'original.",
|
|
1261
|
+
readingTime: "{n} min de lecture",
|
|
1262
|
+
readingTimeLabel: "Temps de lecture",
|
|
1010
1263
|
older: "Articles plus anciens",
|
|
1011
1264
|
viewAll: "Tout voir",
|
|
1265
|
+
moreInSection: "Plus dans cette section",
|
|
1266
|
+
subPages: "Dans cette section",
|
|
1012
1267
|
readAtSource: "Lire \xE0 la source",
|
|
1013
1268
|
emptyTitle: "Rien n'est encore publi\xE9 ici",
|
|
1014
1269
|
emptyBody: "Les documents publi\xE9s dans cette section appara\xEEtront ici, du plus r\xE9cent au plus ancien.",
|
|
@@ -1048,13 +1303,27 @@ var es = {
|
|
|
1048
1303
|
warning: "Atenci\xF3n",
|
|
1049
1304
|
tip: "Consejo",
|
|
1050
1305
|
caution: "Peligro",
|
|
1306
|
+
important: "Importante",
|
|
1307
|
+
copyCode: "Copiar el c\xF3digo",
|
|
1308
|
+
copied: "Copiado",
|
|
1309
|
+
copyBlocked: "Copia bloqueada",
|
|
1310
|
+
done: "Hecho",
|
|
1311
|
+
notDone: "Pendiente",
|
|
1312
|
+
playVideo: "Reproducir el v\xEDdeo",
|
|
1313
|
+
videoFrame: "V\xEDdeo de YouTube",
|
|
1051
1314
|
diagram: "Diagrama",
|
|
1052
1315
|
diagramError: "No se pudo mostrar este diagrama.",
|
|
1316
|
+
diagramLoading: "Cargando el diagrama",
|
|
1317
|
+
diagramSource: "C\xF3digo del diagrama",
|
|
1053
1318
|
contentError: "No se puede mostrar este contenido.",
|
|
1054
1319
|
fallbackTitle: "A\xFAn no est\xE1 traducida al {language}.",
|
|
1055
1320
|
fallbackBody: "Est\xE1s leyendo el original.",
|
|
1321
|
+
readingTime: "{n} min de lectura",
|
|
1322
|
+
readingTimeLabel: "Tiempo de lectura",
|
|
1056
1323
|
older: "Entradas anteriores",
|
|
1057
1324
|
viewAll: "Ver todo",
|
|
1325
|
+
moreInSection: "M\xE1s en esta secci\xF3n",
|
|
1326
|
+
subPages: "En esta secci\xF3n",
|
|
1058
1327
|
readAtSource: "Leer en la fuente",
|
|
1059
1328
|
emptyTitle: "A\xFAn no hay nada publicado aqu\xED",
|
|
1060
1329
|
emptyBody: "Los documentos publicados en esta secci\xF3n aparecer\xE1n aqu\xED, del m\xE1s reciente al m\xE1s antiguo.",
|
|
@@ -1099,14 +1368,15 @@ function formatDate(iso, locale, options = { dateStyle: "medium" }) {
|
|
|
1099
1368
|
}
|
|
1100
1369
|
|
|
1101
1370
|
// src/react/content.tsx
|
|
1371
|
+
var import_youtube_facade = require("./youtube-facade.cjs");
|
|
1102
1372
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1103
1373
|
function plainText(node) {
|
|
1104
1374
|
if (typeof node === "string" || typeof node === "number") return String(node);
|
|
1105
1375
|
if (Array.isArray(node)) return node.map(plainText).join("");
|
|
1106
1376
|
return (0, import_react.isValidElement)(node) ? plainText(node.props.children) : "";
|
|
1107
1377
|
}
|
|
1108
|
-
var CALLOUT_ICON = { note: "info", tip: "check-circle", warning: "alert", caution: "x-circle" };
|
|
1109
|
-
function buildComponents(c, s) {
|
|
1378
|
+
var CALLOUT_ICON = { note: "info", tip: "check-circle", important: "important", warning: "alert", caution: "x-circle" };
|
|
1379
|
+
function buildComponents(c, s, { opensWithImage, interactive }) {
|
|
1110
1380
|
const Link = c.Link ?? "a";
|
|
1111
1381
|
const Img = c.Image ?? "img";
|
|
1112
1382
|
const A = ({ href, children, ...rest }) => {
|
|
@@ -1117,20 +1387,35 @@ function buildComponents(c, s) {
|
|
|
1117
1387
|
}
|
|
1118
1388
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { href: url, rel: "noopener noreferrer", ...rest, children });
|
|
1119
1389
|
};
|
|
1120
|
-
|
|
1390
|
+
let eager = opensWithImage;
|
|
1391
|
+
const Image = (props) => {
|
|
1392
|
+
if (typeof props.src !== "string") return null;
|
|
1393
|
+
const first = eager;
|
|
1394
|
+
eager = false;
|
|
1395
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Img, { loading: first ? "eager" : "lazy", ...first ? { fetchPriority: "high" } : {}, decoding: "async", ...props });
|
|
1396
|
+
};
|
|
1121
1397
|
const Pre = ({ children, ...rest }) => {
|
|
1122
1398
|
const code = import_react.Children.toArray(children).find(import_react.isValidElement);
|
|
1123
1399
|
const language = /(?:^|\s)language-([\w-]+)/.exec(code?.props.className ?? "")?.[1];
|
|
1124
1400
|
const pre = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { tabIndex: 0, ...rest, children });
|
|
1125
1401
|
if (c.CodeBlock) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(c.CodeBlock, { code: plainText(children), language, children: pre });
|
|
1126
1402
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("figure", { className: "hyle-codeblock", "data-slot-component": "CodeBlock", children: [
|
|
1127
|
-
language ? /* @__PURE__ */ (0, import_jsx_runtime3.
|
|
1403
|
+
language || interactive ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("header", { children: [
|
|
1404
|
+
language ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "lang", children: language }) : null,
|
|
1405
|
+
interactive ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
1406
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("button", { type: "button", "aria-label": s.copyCode, children: [
|
|
1407
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { name: "copy" }),
|
|
1408
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { name: "check" })
|
|
1409
|
+
] }),
|
|
1410
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "hyle-sr", role: "status" })
|
|
1411
|
+
] }) : null
|
|
1412
|
+
] }) : null,
|
|
1128
1413
|
pre
|
|
1129
1414
|
] });
|
|
1130
1415
|
};
|
|
1131
1416
|
const Table = ({ children, ...rest }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "hyle-table", tabIndex: 0, role: "region", "aria-label": s.table, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("table", { ...rest, children }) });
|
|
1132
1417
|
const Callout = ({ kind, children }) => {
|
|
1133
|
-
const k =
|
|
1418
|
+
const k = Object.hasOwn(CALLOUT_ICON, String(kind)) ? kind : "note";
|
|
1134
1419
|
const title = s[k];
|
|
1135
1420
|
if (c.Callout) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(c.Callout, { kind: k, title, children });
|
|
1136
1421
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("aside", { className: "hyle-callout", "data-kind": k, "data-slot-component": "Callout", role: "note", children: [
|
|
@@ -1141,26 +1426,42 @@ function buildComponents(c, s) {
|
|
|
1141
1426
|
] })
|
|
1142
1427
|
] });
|
|
1143
1428
|
};
|
|
1144
|
-
const Frame = (
|
|
1429
|
+
const Frame = (props) => {
|
|
1430
|
+
const { srcDoc } = props;
|
|
1145
1431
|
if (typeof srcDoc !== "string") return null;
|
|
1146
1432
|
const source = mermaidSource(srcDoc);
|
|
1147
1433
|
if (c.Mermaid) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(c.Mermaid, { srcDoc, source, title: s.diagram });
|
|
1148
|
-
if (source
|
|
1149
|
-
|
|
1434
|
+
if (source === void 0) return null;
|
|
1435
|
+
const light = diagramRender(props["data-light"]);
|
|
1436
|
+
const dark = diagramRender(props["data-dark"]);
|
|
1437
|
+
if (light && dark) {
|
|
1438
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mermaid_image.MermaidImage, { source, title: s.diagram, errorText: s.diagramError, loadingText: s.diagramLoading, sourceLabel: s.diagramSource, light, dark, labels: s.viewer });
|
|
1439
|
+
}
|
|
1440
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mermaid_diagram.MermaidDiagram, { source, title: s.diagram, errorText: s.diagramError, loadingText: s.diagramLoading, labels: s.viewer });
|
|
1150
1441
|
};
|
|
1151
1442
|
const Heading = (level) => function HyleHeading({ id, children, ...rest }) {
|
|
1152
1443
|
const Tag = `h${level}`;
|
|
1444
|
+
const anchored = typeof id === "string" && !String(rest.className ?? "").split(" ").includes("sr-only");
|
|
1153
1445
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Tag, { id, ...rest, children: [
|
|
1154
|
-
|
|
1446
|
+
anchored ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { className: "hyle-anchor", href: `#${id}`, "aria-label": s.anchor }) : null,
|
|
1155
1447
|
children
|
|
1156
1448
|
] });
|
|
1157
1449
|
};
|
|
1158
|
-
const
|
|
1450
|
+
const Checkbox = (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { ...props, "aria-label": props.checked ? s.done : s.notDone });
|
|
1451
|
+
const Paragraph = ({ children, ...rest }) => {
|
|
1452
|
+
const [only, ...more] = import_react.Children.toArray(children).filter((n) => typeof n !== "string" || n.trim() !== "");
|
|
1453
|
+
if (more.length === 0 && (0, import_react.isValidElement)(only) && only.props["data-embed"] === "youtube") {
|
|
1454
|
+
const id = youtubeId(only.props.href);
|
|
1455
|
+
if (id) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_youtube_facade.YouTubeFacade, { videoId: id, playLabel: s.playVideo, frameTitle: s.videoFrame, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: only }) });
|
|
1456
|
+
}
|
|
1457
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { ...rest, children });
|
|
1458
|
+
};
|
|
1459
|
+
const defaults = { a: A, img: Image, pre: Pre, table: Table, input: Checkbox, callout: Callout, iframe: Frame, h2: Heading(2), h3: Heading(3), h4: Heading(4), ...interactive ? { p: Paragraph } : {} };
|
|
1159
1460
|
const overrides = ["a", "img", "code", "pre", "table", "blockquote", "h1", "h2", "h3", "h4", "h5", "h6"];
|
|
1160
1461
|
for (const key of overrides) if (c[key]) defaults[key] = c[key];
|
|
1161
1462
|
return defaults;
|
|
1162
1463
|
}
|
|
1163
|
-
function
|
|
1464
|
+
function renderHast({ tree, title, description, components = {}, locale }, interactive) {
|
|
1164
1465
|
let root;
|
|
1165
1466
|
try {
|
|
1166
1467
|
root = sanitizeHast(tree, title, description);
|
|
@@ -1172,11 +1473,13 @@ function HastContent({ tree, title, description, components = {}, locale }) {
|
|
|
1172
1473
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: s.contentError })
|
|
1173
1474
|
] });
|
|
1174
1475
|
}
|
|
1476
|
+
const lead = root.children.find((n) => n.type !== "text" || n.value.trim() !== "");
|
|
1477
|
+
const opensWithImage = lead?.type === "element" && lead.tagName === "figure";
|
|
1175
1478
|
return (0, import_hast_util_to_jsx_runtime.toJsxRuntime)(root, {
|
|
1176
1479
|
Fragment: import_react.Fragment,
|
|
1177
1480
|
jsx: import_jsx_runtime2.jsx,
|
|
1178
1481
|
jsxs: import_jsx_runtime2.jsxs,
|
|
1179
|
-
components: buildComponents(components, stringsFor(locale)),
|
|
1482
|
+
components: buildComponents(components, stringsFor(locale), { opensWithImage, interactive }),
|
|
1180
1483
|
elementAttributeNameCase: "react",
|
|
1181
1484
|
stylePropertyNameCase: "dom"
|
|
1182
1485
|
});
|
|
@@ -1185,301 +1488,41 @@ function TrustedServerHtml({ html }) {
|
|
|
1185
1488
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { dangerouslySetInnerHTML: { __html: hostAssetHtml(html) } });
|
|
1186
1489
|
}
|
|
1187
1490
|
|
|
1188
|
-
// src/react/
|
|
1189
|
-
var
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
var import_comments = require("./comments.cjs");
|
|
1193
|
-
|
|
1194
|
-
// src/react/seo.ts
|
|
1195
|
-
var BARE_HTTPS_ORIGIN = /^https:\/\/[^/]+$/;
|
|
1196
|
-
var bareOrigin = (origin) => origin && BARE_HTTPS_ORIGIN.test(origin) ? origin : void 0;
|
|
1197
|
-
var absoluteUrl = (origin, href) => origin + encodeURI(href);
|
|
1198
|
-
var modifiedAt = (pub) => pub.updated_at && Date.parse(pub.updated_at) > Date.parse(pub.published_at) ? pub.updated_at : void 0;
|
|
1199
|
-
function articleAuthor(article, jsonLd) {
|
|
1200
|
-
const given = jsonLd?.author?.(article);
|
|
1201
|
-
if (given && typeof given.name === "string" && given.name) return given;
|
|
1202
|
-
const fromFrontmatter = article.frontmatter.author;
|
|
1203
|
-
return typeof fromFrontmatter === "string" && fromFrontmatter ? { name: fromFrontmatter } : void 0;
|
|
1204
|
-
}
|
|
1205
|
-
var UNSAFE_URL = /[\u0000- \u007f\\]/;
|
|
1206
|
-
var positive = (n) => typeof n === "number" && Number.isInteger(n) && n > 0 ? n : void 0;
|
|
1207
|
-
function validOgImage(image, origin) {
|
|
1208
|
-
if (!image || typeof image.url !== "string" || UNSAFE_URL.test(image.url)) return void 0;
|
|
1209
|
-
const relative = image.url.startsWith("/") && !image.url.startsWith("//");
|
|
1210
|
-
const url = relative ? origin ? origin + image.url : void 0 : image.url;
|
|
1211
|
-
if (!url) return void 0;
|
|
1212
|
-
try {
|
|
1213
|
-
const parsed = new URL(url);
|
|
1214
|
-
if (parsed.protocol !== "https:" || relative && parsed.origin !== origin) return void 0;
|
|
1215
|
-
} catch {
|
|
1216
|
-
return void 0;
|
|
1217
|
-
}
|
|
1218
|
-
const width = positive(image.width);
|
|
1219
|
-
const height = positive(image.height);
|
|
1220
|
-
const type = typeof image.type === "string" && image.type ? image.type : "image/png";
|
|
1221
|
-
return { url, type, ...width ? { width } : {}, ...height ? { height } : {}, ...typeof image.alt === "string" && image.alt ? { alt: image.alt } : {} };
|
|
1222
|
-
}
|
|
1223
|
-
function hreflangLanguages(members, defaultLocale, selfUrl, url) {
|
|
1224
|
-
const defaultMember = members.find((m) => m.locale === defaultLocale);
|
|
1225
|
-
return { ...Object.fromEntries(members.map((m) => [m.locale, url(m)])), "x-default": defaultMember ? url(defaultMember) : selfUrl };
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
// src/react/jsonld.ts
|
|
1229
|
-
var script = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
|
|
1230
|
-
function articleJsonLd({ article, origin, href, jsonLd, imageUrl }) {
|
|
1231
|
-
const { publication: pub } = article;
|
|
1232
|
-
const url = (path) => absoluteUrl(origin, href(path, pub.locale));
|
|
1233
|
-
const canonical = url(pub.canonical_path);
|
|
1234
|
-
const id = (fragment) => ({ "@id": `${canonical}#${fragment}` });
|
|
1235
|
-
const full = jsonLd !== void 0;
|
|
1236
|
-
const author = articleAuthor(article, jsonLd);
|
|
1237
|
-
const publisher = jsonLd?.publisher;
|
|
1238
|
-
const website = jsonLd?.website?.(pub.locale);
|
|
1239
|
-
const modified = modifiedAt(pub);
|
|
1240
|
-
const root = jsonLd?.breadcrumbRoot;
|
|
1241
|
-
const graph = [
|
|
1242
|
-
...full ? [{
|
|
1243
|
-
"@type": "WebPage",
|
|
1244
|
-
...id("webpage"),
|
|
1245
|
-
url: canonical,
|
|
1246
|
-
name: pub.title,
|
|
1247
|
-
...pub.description ? { description: pub.description } : {},
|
|
1248
|
-
inLanguage: pub.locale,
|
|
1249
|
-
...website ? { isPartOf: { "@id": website.id } } : {},
|
|
1250
|
-
...publisher ? { publisher: { "@id": publisher.id } } : {},
|
|
1251
|
-
breadcrumb: id("breadcrumb"),
|
|
1252
|
-
mainEntity: id("article")
|
|
1253
|
-
}] : [],
|
|
1254
|
-
{
|
|
1255
|
-
"@type": "BlogPosting",
|
|
1256
|
-
...id("article"),
|
|
1257
|
-
headline: pub.title,
|
|
1258
|
-
...pub.description ? { description: pub.description } : {},
|
|
1259
|
-
datePublished: pub.published_at.slice(0, 10),
|
|
1260
|
-
...modified ? { dateModified: modified } : {},
|
|
1261
|
-
url: canonical,
|
|
1262
|
-
mainEntityOfPage: full ? id("webpage") : canonical,
|
|
1263
|
-
...author ? { author: author.id ? { "@id": author.id } : { "@type": "Person", name: author.name, ...author.url ? { url: author.url } : {} } } : {},
|
|
1264
|
-
...publisher ? { publisher: { "@id": publisher.id } } : {},
|
|
1265
|
-
inLanguage: pub.locale,
|
|
1266
|
-
...imageUrl ? { image: [imageUrl] } : {}
|
|
1267
|
-
},
|
|
1268
|
-
{
|
|
1269
|
-
"@type": "BreadcrumbList",
|
|
1270
|
-
...id("breadcrumb"),
|
|
1271
|
-
itemListElement: [...root ? [{ name: root.name, item: absoluteUrl(origin, href("/", pub.locale).replace(/(.)\/$/, "$1").replace(/^\/$/, "")) }] : [], ...article.breadcrumbs.map((b) => ({ name: b.title, item: url(b.canonical_path) }))].map((b, i) => ({ "@type": "ListItem", position: i + 1, ...b }))
|
|
1272
|
-
}
|
|
1273
|
-
];
|
|
1274
|
-
return script({ "@context": "https://schema.org", "@graph": graph });
|
|
1275
|
-
}
|
|
1276
|
-
function listJsonLd({ list, origin, href, path, locale, description }) {
|
|
1277
|
-
return script({
|
|
1278
|
-
"@context": "https://schema.org",
|
|
1279
|
-
"@type": "CollectionPage",
|
|
1280
|
-
url: absoluteUrl(origin, href(path)),
|
|
1281
|
-
name: list.section.title,
|
|
1282
|
-
...description ? { description } : {},
|
|
1283
|
-
inLanguage: locale,
|
|
1284
|
-
mainEntity: {
|
|
1285
|
-
"@type": "ItemList",
|
|
1286
|
-
itemListElement: list.items.map((item, i) => ({ "@type": "ListItem", position: i + 1, url: absoluteUrl(origin, href(item.canonical_path)), name: item.title }))
|
|
1287
|
-
}
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
// src/react/pages.tsx
|
|
1491
|
+
// src/react/body.tsx
|
|
1492
|
+
var import_react2 = require("react");
|
|
1493
|
+
var import_code_copy = require("./code-copy.cjs");
|
|
1494
|
+
var import_fragment_alias = require("./fragment-alias.cjs");
|
|
1292
1495
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1293
|
-
function
|
|
1294
|
-
const
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
const locale = p.locale ?? fallbackLocale;
|
|
1302
|
-
return { s: stringsFor(locale), locale, href: (path, linkLocale) => p.toHref ? p.toHref(path, linkLocale ?? locale) : path, Link: p.components?.Link ?? "a" };
|
|
1303
|
-
}
|
|
1304
|
-
function Pager({ prev, next, c }) {
|
|
1305
|
-
if (!prev && !next) return null;
|
|
1306
|
-
const { Link, s } = c;
|
|
1307
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("nav", { className: "hyle-pager", "aria-label": s.pager, children: [
|
|
1308
|
-
prev ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { href: c.href(prev.canonical_path), rel: "prev", children: [
|
|
1309
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dir", children: [
|
|
1310
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev-left" }),
|
|
1311
|
-
s.prev
|
|
1312
|
-
] }),
|
|
1313
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "ttl", children: prev.title })
|
|
1314
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "none", "aria-hidden": "true" }),
|
|
1315
|
-
next ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { href: c.href(next.canonical_path), rel: "next", className: "next", children: [
|
|
1316
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dir", children: [
|
|
1317
|
-
s.next,
|
|
1318
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev" })
|
|
1319
|
-
] }),
|
|
1320
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "ttl", children: next.title })
|
|
1321
|
-
] }) : null
|
|
1322
|
-
] });
|
|
1323
|
-
}
|
|
1324
|
-
function TocList({ toc }) {
|
|
1325
|
-
const groups = [];
|
|
1326
|
-
for (const entry of toc) {
|
|
1327
|
-
const last = groups.at(-1);
|
|
1328
|
-
if (entry.depth === 3 && last) last.subs.push(entry);
|
|
1329
|
-
else groups.push({ entry, subs: [] });
|
|
1330
|
-
}
|
|
1331
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { children: groups.map(({ entry, subs }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { children: [
|
|
1332
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: `#${scopeId(entry.id)}`, children: entry.text }),
|
|
1333
|
-
subs.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { children: subs.map((sub) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: `#${scopeId(sub.id)}`, children: sub.text }) }, sub.id)) }) : null
|
|
1334
|
-
] }, entry.id)) });
|
|
1335
|
-
}
|
|
1336
|
-
function Toc({ toc, c, aside }) {
|
|
1337
|
-
const entries = toc.filter((t) => t.depth === 2 || t.depth === 3);
|
|
1338
|
-
if (entries.length === 0 && !aside) return { narrow: null, wide: null };
|
|
1339
|
-
const { s } = c;
|
|
1340
|
-
return {
|
|
1341
|
-
narrow: entries.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("details", { className: "hyle-toc-m", children: [
|
|
1342
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("summary", { children: [
|
|
1343
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "file" }),
|
|
1344
|
-
s.toc,
|
|
1345
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev-down", className: "hyle-chev" })
|
|
1346
|
-
] }),
|
|
1347
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("nav", { className: "hyle-toc-list", "aria-label": s.toc, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TocList, { toc: entries }) })
|
|
1348
|
-
] }),
|
|
1349
|
-
wide: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("aside", { className: "hyle-toc-d", "aria-label": s.toc, children: [
|
|
1350
|
-
entries.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1351
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "hyle-toc-title", children: s.toc }),
|
|
1352
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("nav", { className: "hyle-toc-list", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TocList, { toc: entries }) })
|
|
1353
|
-
] }),
|
|
1354
|
-
aside
|
|
1355
|
-
] })
|
|
1356
|
-
};
|
|
1357
|
-
}
|
|
1358
|
-
function Body({ article, components, locale }) {
|
|
1359
|
-
const { content, publication } = article;
|
|
1360
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "hyle-body hyle-prose", lang: article.fallback ? void 0 : publication.locale, children: content.format === "hast" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(HastContent, { tree: content.tree, title: publication.title, description: publication.description, components: components ?? {}, locale }) : content.format === "html" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TrustedServerHtml, { html: content.html }) : null });
|
|
1361
|
-
}
|
|
1362
|
-
function Languages({ alternates, current, c }) {
|
|
1363
|
-
if (alternates.length < 2) return null;
|
|
1364
|
-
const { Link, s } = c;
|
|
1365
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("nav", { className: "hyle-langs", "aria-label": s.languages, children: [
|
|
1366
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: s.readIn }),
|
|
1367
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { children: alternates.map((a) => {
|
|
1368
|
-
const label = languageName(a.locale, a.locale);
|
|
1369
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: a.locale === current ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: c.href(a.canonical_path, a.locale), hrefLang: a.locale, lang: a.locale, "aria-current": "true", children: label }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Link, { href: c.href(a.canonical_path, a.locale), hrefLang: a.locale, lang: a.locale, children: label }) }, a.locale);
|
|
1370
|
-
}) })
|
|
1496
|
+
function ProseBody({ id, className, lang, ...content }) {
|
|
1497
|
+
const generated = (0, import_react2.useId)();
|
|
1498
|
+
const rootId = id ?? `hyle-body${generated}`;
|
|
1499
|
+
const s = stringsFor(content.locale);
|
|
1500
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1501
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { id: rootId, className, lang, children: renderHast(content, true) }),
|
|
1502
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_code_copy.CodeCopy, { rootId, copyLabel: s.copyCode, copiedLabel: s.copied, blockedLabel: s.copyBlocked }),
|
|
1503
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_fragment_alias.FragmentAlias, {})
|
|
1371
1504
|
] });
|
|
1372
1505
|
}
|
|
1373
|
-
function LdScript({ json: json2 }) {
|
|
1374
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("script", { type: "application/ld+json", dangerouslySetInnerHTML: { __html: json2 } });
|
|
1375
|
-
}
|
|
1376
|
-
function ArticlePage({ article, engagement, origin, jsonLd, imageUrl, ...base }) {
|
|
1377
|
-
const { publication: pub } = article;
|
|
1378
|
-
const c = ctx(base, pub.locale);
|
|
1379
|
-
const { s } = c;
|
|
1380
|
-
const jsonLdOrigin = bareOrigin(origin);
|
|
1381
|
-
const author = articleAuthor(article, jsonLd)?.name;
|
|
1382
|
-
const toc = Toc({ toc: article.toc, c, aside: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.aside", slots: base.slots, className: "hyle-slot-wrap" }) });
|
|
1383
|
-
const notTranslated = article.fallback ? s.fallbackTitle.replace("{language}", languageName(article.fallback.requested_locale, c.locale)) : void 0;
|
|
1384
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("article", { className: "hyle-article", "data-hyle-page": "article", lang: c.locale, children: [
|
|
1385
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "hyle-head", children: [
|
|
1386
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.before", slots: base.slots, className: "hyle-eyebrow" }),
|
|
1387
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h1", { className: "hyle-title", children: pub.title }),
|
|
1388
|
-
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
1389
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-meta", children: [
|
|
1390
|
-
author ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1391
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: author.slice(0, 2).toUpperCase() }),
|
|
1392
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1393
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "hyle-sr", children: [
|
|
1394
|
-
s.by,
|
|
1395
|
-
" "
|
|
1396
|
-
] }),
|
|
1397
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "by", children: author })
|
|
1398
|
-
] })
|
|
1399
|
-
] }) : null,
|
|
1400
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1401
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "calendar" }),
|
|
1402
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("time", { dateTime: pub.published_at, title: pub.published_at, children: formatDate(pub.published_at, c.locale) })
|
|
1403
|
-
] }),
|
|
1404
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1405
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "globe" }),
|
|
1406
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { lang: pub.locale, children: languageName(pub.locale, c.locale) })
|
|
1407
|
-
] }),
|
|
1408
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.meta", slots: base.slots, tag: "span" })
|
|
1409
|
-
] }),
|
|
1410
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Languages, { alternates: article.alternates, current: pub.locale, c }),
|
|
1411
|
-
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1412
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }),
|
|
1413
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
1414
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: notTranslated }),
|
|
1415
|
-
" ",
|
|
1416
|
-
s.fallbackBody
|
|
1417
|
-
] })
|
|
1418
|
-
] }) : null
|
|
1419
|
-
] }),
|
|
1420
|
-
toc.narrow,
|
|
1421
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
1422
|
-
engagement ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_comments.Comments, { path: pub.canonical_path, endpoint: engagement.endpoint ?? "/api/hyle/engage", signInHref: engagement.signInHref, locale: c.locale, labels: s.comments }) : null,
|
|
1423
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Pager, { prev: article.prev, next: article.next, c }),
|
|
1424
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.after", slots: base.slots, className: "hyle-after" }),
|
|
1425
|
-
toc.wide,
|
|
1426
|
-
jsonLdOrigin ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LdScript, { json: articleJsonLd({ article, origin: jsonLdOrigin, href: c.href, jsonLd, imageUrl }) }) : null
|
|
1427
|
-
] }) });
|
|
1428
|
-
}
|
|
1429
|
-
function ListPage({ list, olderHref, description, origin, path, ...base }) {
|
|
1430
|
-
const c = ctx(base, "en");
|
|
1431
|
-
const { s, Link } = c;
|
|
1432
|
-
const Row = base.slots?.["list.item"];
|
|
1433
|
-
const groups = /* @__PURE__ */ new Map();
|
|
1434
|
-
for (const item of list.items) groups.set(item.published_at.slice(0, 7), [...groups.get(item.published_at.slice(0, 7)) ?? [], item]);
|
|
1435
|
-
const notTranslated = list.fallback ? s.fallbackTitle.replace("{language}", languageName(list.fallback.requested_locale, c.locale)) : void 0;
|
|
1436
|
-
const jsonLdOrigin = bareOrigin(origin);
|
|
1437
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-listpage", "data-hyle-page": "list", lang: c.locale, children: [
|
|
1438
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "hyle-head", children: [
|
|
1439
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h1", { className: "hyle-title", children: list.section.title }),
|
|
1440
|
-
description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "hyle-desc", children: description }) : null,
|
|
1441
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "list.header", slots: base.slots, className: "hyle-slot-wrap" }),
|
|
1442
|
-
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1443
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }),
|
|
1444
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
1445
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: notTranslated }),
|
|
1446
|
-
" ",
|
|
1447
|
-
s.fallbackBody
|
|
1448
|
-
] })
|
|
1449
|
-
] }) : null
|
|
1450
|
-
] }),
|
|
1451
|
-
list.items.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-empty", "data-slot-state": "empty", children: [
|
|
1452
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "file" }),
|
|
1453
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { children: s.emptyTitle }),
|
|
1454
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: s.emptyBody }),
|
|
1455
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "list.empty", slots: base.slots })
|
|
1456
|
-
] }) : [...groups].map(([month, items]) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { "aria-label": formatDate(`${month}-01`, c.locale, { month: "long", year: "numeric" }), children: [
|
|
1457
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { className: "hyle-year", children: formatDate(`${month}-01`, c.locale, { month: "long", year: "numeric" }) }),
|
|
1458
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "hyle-items", children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: Row ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Row, { item, href: c.href(item.canonical_path), locale: c.locale }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { className: "hyle-item", href: c.href(item.canonical_path), children: [
|
|
1459
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("time", { dateTime: item.published_at, title: item.published_at, children: formatDate(item.published_at, c.locale) }),
|
|
1460
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
1461
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "t", children: item.title }),
|
|
1462
|
-
item.description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: item.description }) : null
|
|
1463
|
-
] })
|
|
1464
|
-
] }) }, item.canonical_path)) })
|
|
1465
|
-
] }, month)),
|
|
1466
|
-
olderHref ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("nav", { className: "hyle-pagination", "aria-label": s.pager, children: [
|
|
1467
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "sp" }),
|
|
1468
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { className: "hyle-btn sm", href: olderHref, rel: "next", children: [
|
|
1469
|
-
s.older,
|
|
1470
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev" })
|
|
1471
|
-
] })
|
|
1472
|
-
] }) : null,
|
|
1473
|
-
jsonLdOrigin && path ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LdScript, { json: listJsonLd({ list, origin: jsonLdOrigin, href: c.href, path, locale: c.locale, description }) }) : null
|
|
1474
|
-
] }) });
|
|
1475
|
-
}
|
|
1476
1506
|
|
|
1477
1507
|
// src/react/index.ts
|
|
1478
|
-
var
|
|
1508
|
+
var import_mermaid_diagram2 = require("./mermaid-diagram.cjs");
|
|
1509
|
+
var import_print_coordinator = require("./print-coordinator.cjs");
|
|
1510
|
+
|
|
1511
|
+
// src/react/pages.tsx
|
|
1512
|
+
var import_comments = require("./comments.cjs");
|
|
1479
1513
|
|
|
1480
1514
|
// src/react/comments-api.ts
|
|
1515
|
+
var REACTION_KINDS = ["like", "love", "insightful", "celebrate"];
|
|
1516
|
+
var isCursor = (v) => typeof v === "string" && /^[A-Za-z0-9_-]{1,200}$/.test(v);
|
|
1481
1517
|
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1482
1518
|
var count = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.trunc(v) : 0;
|
|
1519
|
+
function parseCounts(v) {
|
|
1520
|
+
if (!isObject2(v)) return void 0;
|
|
1521
|
+
return Object.fromEntries(REACTION_KINDS.map((kind) => [kind, count(v[kind])]).filter(([, n]) => n > 0));
|
|
1522
|
+
}
|
|
1523
|
+
var toVote = (v) => v === 1 || v === -1 ? v : null;
|
|
1524
|
+
var toUnrenderable = (v) => v === true ? { unrenderable: true } : {};
|
|
1525
|
+
var toMine = (v) => Array.isArray(v) ? { my_reactions: REACTION_KINDS.filter((kind) => v.includes(kind)) } : {};
|
|
1483
1526
|
function toComment(raw) {
|
|
1484
1527
|
if (!isObject2(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string") return void 0;
|
|
1485
1528
|
const depth = typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1;
|
|
@@ -1487,6 +1530,7 @@ function toComment(raw) {
|
|
|
1487
1530
|
const name = typeof raw.author_name === "string" ? raw.author_name : author;
|
|
1488
1531
|
const body = isObject2(raw.body) && raw.body.format === "hast" ? { format: "hast", tree: raw.body.tree } : null;
|
|
1489
1532
|
const removed = raw.removed === true || body === null;
|
|
1533
|
+
const reactions = parseCounts(raw.reaction_counts);
|
|
1490
1534
|
return {
|
|
1491
1535
|
id: raw.id,
|
|
1492
1536
|
parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
|
|
@@ -1495,11 +1539,14 @@ function toComment(raw) {
|
|
|
1495
1539
|
created_at: raw.created_at,
|
|
1496
1540
|
edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
|
|
1497
1541
|
like_count: count(raw.like_count),
|
|
1542
|
+
...Number.isSafeInteger(raw.score) ? { score: raw.score } : {},
|
|
1543
|
+
...reactions ? { reaction_counts: reactions } : {},
|
|
1498
1544
|
removed,
|
|
1499
1545
|
...removed && (raw.removed_by === "moderator" || raw.removed_by === "author") ? { removed_by: raw.removed_by } : {},
|
|
1546
|
+
...removed ? {} : toUnrenderable(raw.unrenderable),
|
|
1500
1547
|
body,
|
|
1501
1548
|
// Viewer members exist only on a live comment of a viewer-aware listing; a tombstone never carries them.
|
|
1502
|
-
...!removed && typeof raw.mine === "boolean" ? { mine: raw.mine, liked_by_me: raw.liked_by_me === true, can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null } : {}
|
|
1549
|
+
...!removed && typeof raw.mine === "boolean" ? { mine: raw.mine, liked_by_me: raw.liked_by_me === true, can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null, ..."my_vote" in raw ? { my_vote: toVote(raw.my_vote) } : {}, ...toMine(raw.my_reactions) } : {}
|
|
1503
1550
|
};
|
|
1504
1551
|
}
|
|
1505
1552
|
function toHeld(raw) {
|
|
@@ -1513,20 +1560,22 @@ function toHeld(raw) {
|
|
|
1513
1560
|
created_at: raw.created_at,
|
|
1514
1561
|
edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
|
|
1515
1562
|
can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null,
|
|
1563
|
+
...toUnrenderable(raw.unrenderable),
|
|
1516
1564
|
body: { format: "hast", tree: raw.body.tree }
|
|
1517
1565
|
};
|
|
1518
1566
|
}
|
|
1519
1567
|
function parseListing(data) {
|
|
1520
1568
|
if (!isObject2(data) || data.kind !== "comments" || !Array.isArray(data.comments)) return void 0;
|
|
1521
1569
|
const comments = data.comments.map(toComment).filter((c) => c !== void 0);
|
|
1522
|
-
const viewer = Array.isArray(data.mine_held) ? { liked_by_me: data.liked_by_me === true, mine_held: data.mine_held.slice(0, 5).map(toHeld).filter((h) => h !== void 0) } : {};
|
|
1523
|
-
|
|
1570
|
+
const viewer = Array.isArray(data.mine_held) ? { liked_by_me: data.liked_by_me === true, ...toMine(data.my_reactions), mine_held: data.mine_held.slice(0, 5).map(toHeld).filter((h) => h !== void 0) } : {};
|
|
1571
|
+
const reactions = parseCounts(data.reaction_counts);
|
|
1572
|
+
return { cp: 1, kind: "comments", publication_id: String(data.publication_id ?? ""), comment_count: count(data.comment_count), like_count: count(data.like_count), ...reactions ? { reaction_counts: reactions } : {}, truncated: data.truncated === true, next_cursor: isCursor(data.next_cursor) ? data.next_cursor : null, comments, ...viewer };
|
|
1524
1573
|
}
|
|
1525
1574
|
var untilMs = (iso) => {
|
|
1526
1575
|
const t = iso ? Date.parse(iso) : NaN;
|
|
1527
1576
|
return Number.isFinite(t) ? t : void 0;
|
|
1528
1577
|
};
|
|
1529
|
-
function buildThread(listing, localHeld) {
|
|
1578
|
+
function buildThread(listing, localHeld, unseen = [], newestOnTop = false) {
|
|
1530
1579
|
const byId = /* @__PURE__ */ new Map();
|
|
1531
1580
|
const roots = [];
|
|
1532
1581
|
const place = (node, parentId) => {
|
|
@@ -1544,11 +1593,16 @@ function buildThread(listing, localHeld) {
|
|
|
1544
1593
|
mine: !removed && c.mine === true,
|
|
1545
1594
|
canEditUntil: untilMs(c.can_edit_until),
|
|
1546
1595
|
likedByMe: !removed && c.liked_by_me === true,
|
|
1596
|
+
myReactions: removed ? void 0 : c.my_reactions,
|
|
1547
1597
|
name: removed ? null : c.author_name ?? null,
|
|
1548
1598
|
createdAt: c.created_at,
|
|
1549
1599
|
editedAt: c.edited_at,
|
|
1550
1600
|
likes: c.like_count,
|
|
1601
|
+
score: c.score,
|
|
1602
|
+
myVote: c.my_vote,
|
|
1603
|
+
reactions: c.reaction_counts,
|
|
1551
1604
|
tree: c.body?.tree,
|
|
1605
|
+
unrenderable: c.unrenderable,
|
|
1552
1606
|
text: void 0,
|
|
1553
1607
|
kids: []
|
|
1554
1608
|
};
|
|
@@ -1566,21 +1620,47 @@ function buildThread(listing, localHeld) {
|
|
|
1566
1620
|
for (const h of listing.mine_held ?? []) {
|
|
1567
1621
|
heldIds.add(h.id);
|
|
1568
1622
|
const parent = h.parent_id ? byId.get(h.parent_id) : void 0;
|
|
1569
|
-
addHeld({ id: h.id, depth: Math.min(4, (parent?.depth ?? h.depth - 1) + 1), status: "held", removedBy: void 0, mine: true, canEditUntil: untilMs(h.can_edit_until), likedByMe: false, name: h.author_name, createdAt: h.created_at, editedAt: h.edited_at, likes: 0, tree: h.body?.tree, text: void 0, kids: [] }, h.parent_id, true);
|
|
1623
|
+
addHeld({ id: h.id, depth: Math.min(4, (parent?.depth ?? h.depth - 1) + 1), status: "held", removedBy: void 0, mine: true, canEditUntil: untilMs(h.can_edit_until), likedByMe: false, name: h.author_name, createdAt: h.created_at, editedAt: h.edited_at, likes: 0, tree: h.body?.tree, unrenderable: h.unrenderable, text: void 0, kids: [] }, h.parent_id, true);
|
|
1570
1624
|
}
|
|
1571
1625
|
if (listing.mine_held === void 0) {
|
|
1572
1626
|
for (const h of localHeld) {
|
|
1573
1627
|
if (byId.has(h.id) || heldIds.has(h.id)) continue;
|
|
1574
1628
|
const parent = h.parentId ? byId.get(h.parentId) : void 0;
|
|
1575
|
-
addHeld(
|
|
1629
|
+
addHeld(localNode(h, "held", parent), h.parentId, false);
|
|
1576
1630
|
}
|
|
1577
1631
|
}
|
|
1632
|
+
for (const u of [...unseen].reverse()) {
|
|
1633
|
+
if (byId.has(u.id) || heldIds.has(u.id) || u.status === "held" && listing.mine_held === void 0) continue;
|
|
1634
|
+
const parent = u.parentId ? byId.get(u.parentId) : void 0;
|
|
1635
|
+
const node = localNode(u, u.status, parent);
|
|
1636
|
+
if (u.status === "held") addHeld(node, u.parentId, true);
|
|
1637
|
+
else if (parent) parent.kids.push(node);
|
|
1638
|
+
else if (newestOnTop) roots.unshift(node);
|
|
1639
|
+
else roots.push(node);
|
|
1640
|
+
byId.set(u.id, node);
|
|
1641
|
+
}
|
|
1578
1642
|
return [...mine, ...roots];
|
|
1579
1643
|
}
|
|
1644
|
+
var localNode = (c, status, parent) => ({
|
|
1645
|
+
id: c.id,
|
|
1646
|
+
depth: Math.min(4, (parent?.depth ?? 0) + 1),
|
|
1647
|
+
status,
|
|
1648
|
+
removedBy: void 0,
|
|
1649
|
+
mine: true,
|
|
1650
|
+
canEditUntil: void 0,
|
|
1651
|
+
likedByMe: false,
|
|
1652
|
+
name: c.name,
|
|
1653
|
+
createdAt: c.createdAt,
|
|
1654
|
+
editedAt: null,
|
|
1655
|
+
likes: 0,
|
|
1656
|
+
tree: void 0,
|
|
1657
|
+
text: c.text,
|
|
1658
|
+
kids: []
|
|
1659
|
+
});
|
|
1580
1660
|
|
|
1581
1661
|
// src/react/comments-body.tsx
|
|
1582
1662
|
var import_hast_util_to_jsx_runtime2 = require("hast-util-to-jsx-runtime");
|
|
1583
|
-
var
|
|
1663
|
+
var import_react3 = require("react");
|
|
1584
1664
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1585
1665
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1586
1666
|
var ALLOWED = /* @__PURE__ */ new Set(["p", "a", "em", "strong", "del", "code", "pre", "blockquote", "ul", "ol", "li", "br"]);
|
|
@@ -1605,12 +1685,12 @@ function CommentBody({ tree }) {
|
|
|
1605
1685
|
if (error instanceof HastLimitError) return null;
|
|
1606
1686
|
throw error;
|
|
1607
1687
|
}
|
|
1608
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-body", children: (0, import_hast_util_to_jsx_runtime2.toJsxRuntime)({ type: "root", children }, { Fragment:
|
|
1688
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-body", children: (0, import_hast_util_to_jsx_runtime2.toJsxRuntime)({ type: "root", children }, { Fragment: import_react3.Fragment, jsx: import_jsx_runtime5.jsx, jsxs: import_jsx_runtime5.jsxs, elementAttributeNameCase: "react", stylePropertyNameCase: "dom" }) });
|
|
1609
1689
|
}
|
|
1610
1690
|
|
|
1611
1691
|
// src/react/embed.tsx
|
|
1612
1692
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1613
|
-
function HyleListView({ items, layout = "list", title, headingLevel = 2, moreHref, ...base }) {
|
|
1693
|
+
function HyleListView({ items, layout = "list", title, headingLevel = 2, moreHref, olderHref, ...base }) {
|
|
1614
1694
|
const c = ctx(base, "en");
|
|
1615
1695
|
const { s, Link } = c;
|
|
1616
1696
|
const Row = base.slots?.["list.item"];
|
|
@@ -1620,12 +1700,13 @@ function HyleListView({ items, layout = "list", title, headingLevel = 2, moreHre
|
|
|
1620
1700
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle hyle-embed", "data-layout": layout, lang: c.locale, children: [
|
|
1621
1701
|
title ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Heading, { className: "hyle-title", children: title }) : null,
|
|
1622
1702
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "hyle-items", children: safe.map((item) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("li", { children: Row ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Row, { item, href: c.href(item.canonical_path), locale: c.locale }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Link, { className: "hyle-item", href: c.href(item.canonical_path), children: [
|
|
1623
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: item.published_at, title: item.published_at, children: formatDate(item.published_at, c.locale) }),
|
|
1703
|
+
item.published_at ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: item.published_at, title: item.published_at, children: formatDate(item.published_at, c.locale) }) : null,
|
|
1624
1704
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
1625
1705
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "t", children: item.title }),
|
|
1626
1706
|
item.description ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: item.description }) : null
|
|
1627
1707
|
] })
|
|
1628
1708
|
] }) }, item.canonical_path)) }),
|
|
1709
|
+
olderHref ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OlderNav, { href: olderHref, c }) : null,
|
|
1629
1710
|
moreHref ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { className: "hyle-more", href: moreHref, children: s.viewAll }) : null
|
|
1630
1711
|
] });
|
|
1631
1712
|
}
|
|
@@ -1679,7 +1760,7 @@ function StaticThread({ nodes, locale, s, level = 1 }) {
|
|
|
1679
1760
|
] }) : null
|
|
1680
1761
|
] })
|
|
1681
1762
|
] }),
|
|
1682
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CommentBody, { tree: node.tree })
|
|
1763
|
+
node.unrenderable ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-cm-body", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.unrenderable }) }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CommentBody, { tree: node.tree })
|
|
1683
1764
|
] })
|
|
1684
1765
|
] }),
|
|
1685
1766
|
kids
|
|
@@ -1715,24 +1796,368 @@ function HyleCommentsFallback({ locale }) {
|
|
|
1715
1796
|
] }) }) });
|
|
1716
1797
|
}
|
|
1717
1798
|
|
|
1718
|
-
// src/react/
|
|
1719
|
-
var
|
|
1720
|
-
var
|
|
1721
|
-
var
|
|
1722
|
-
var
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1799
|
+
// src/react/seo.ts
|
|
1800
|
+
var BARE_HTTPS_ORIGIN = /^https:\/\/[^/]+$/;
|
|
1801
|
+
var bareOrigin = (origin) => origin && BARE_HTTPS_ORIGIN.test(origin) ? origin : void 0;
|
|
1802
|
+
var absoluteUrl = (origin, href) => origin + encodeURI(href);
|
|
1803
|
+
var modifiedAt = (pub) => pub.updated_at && Date.parse(pub.updated_at) > Date.parse(pub.published_at) ? pub.updated_at : void 0;
|
|
1804
|
+
var wordCountOf = (pub) => Number.isInteger(pub.word_count) && pub.word_count > 0 ? pub.word_count : void 0;
|
|
1805
|
+
var WORDS_PER_MINUTE = 275;
|
|
1806
|
+
var readingMinutes = (wordCount) => Math.max(1, Math.ceil(wordCount / WORDS_PER_MINUTE));
|
|
1807
|
+
var breadcrumbItems = (article, jsonLd) => [
|
|
1808
|
+
...jsonLd?.breadcrumbRoot ? [{ title: jsonLd.breadcrumbRoot.name, canonical_path: "/" }] : [],
|
|
1809
|
+
...article.breadcrumbs
|
|
1810
|
+
];
|
|
1811
|
+
var crumbHref = (href, path, locale) => path === "/" ? href("/", locale).replace(/(.)\/$/, "$1") : href(path, locale);
|
|
1812
|
+
function articleAuthor(article, jsonLd) {
|
|
1813
|
+
const authored = article.publication.author;
|
|
1814
|
+
if (authored?.name) return { name: authored.name, ...authored.url ? { url: authored.url } : {} };
|
|
1815
|
+
const given = jsonLd?.author?.(article);
|
|
1816
|
+
if (given && typeof given.name === "string" && given.name) return given;
|
|
1817
|
+
const fromFrontmatter = article.frontmatter.author;
|
|
1818
|
+
return typeof fromFrontmatter === "string" && fromFrontmatter ? { name: fromFrontmatter } : void 0;
|
|
1733
1819
|
}
|
|
1734
|
-
|
|
1735
|
-
|
|
1820
|
+
var UNSAFE_URL = /[\u0000- \u007f\\]/;
|
|
1821
|
+
var positive = (n) => typeof n === "number" && Number.isInteger(n) && n > 0 ? n : void 0;
|
|
1822
|
+
function validOgImage(image, origin) {
|
|
1823
|
+
if (!image || typeof image.url !== "string" || UNSAFE_URL.test(image.url)) return void 0;
|
|
1824
|
+
const relative = image.url.startsWith("/") && !image.url.startsWith("//");
|
|
1825
|
+
const url = relative ? origin ? origin + image.url : void 0 : image.url;
|
|
1826
|
+
if (!url) return void 0;
|
|
1827
|
+
try {
|
|
1828
|
+
const parsed = new URL(url);
|
|
1829
|
+
if (parsed.protocol !== "https:" || relative && parsed.origin !== origin) return void 0;
|
|
1830
|
+
} catch {
|
|
1831
|
+
return void 0;
|
|
1832
|
+
}
|
|
1833
|
+
const width = positive(image.width);
|
|
1834
|
+
const height = positive(image.height);
|
|
1835
|
+
const type = typeof image.type === "string" && image.type ? image.type : "image/png";
|
|
1836
|
+
return { url, type, ...width ? { width } : {}, ...height ? { height } : {}, ...typeof image.alt === "string" && image.alt ? { alt: image.alt } : {} };
|
|
1837
|
+
}
|
|
1838
|
+
function hreflangLanguages(members, defaultLocale, selfUrl, url) {
|
|
1839
|
+
const defaultMember = members.find((m) => m.locale === defaultLocale);
|
|
1840
|
+
return { ...Object.fromEntries(members.map((m) => [m.locale, url(m)])), "x-default": defaultMember ? url(defaultMember) : selfUrl };
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// src/react/jsonld.ts
|
|
1844
|
+
var script = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
|
|
1845
|
+
var organization = (publisher) => ({ "@type": "Organization", "@id": publisher.id, name: publisher.name, ...publisher.logo ? { logo: publisher.logo } : {} });
|
|
1846
|
+
var webSite = (website) => ({ "@type": "WebSite", "@id": website.id, name: website.name });
|
|
1847
|
+
function articleJsonLd({ article, origin, href, jsonLd, imageUrl, imageWidth, imageHeight }) {
|
|
1848
|
+
const { publication: pub } = article;
|
|
1849
|
+
const url = (path) => absoluteUrl(origin, href(path, pub.locale));
|
|
1850
|
+
const canonical = url(pub.canonical_path);
|
|
1851
|
+
const id = (fragment) => ({ "@id": `${canonical}#${fragment}` });
|
|
1852
|
+
const full = jsonLd !== void 0;
|
|
1853
|
+
const author = articleAuthor(article, jsonLd);
|
|
1854
|
+
const publisher = jsonLd?.publisher;
|
|
1855
|
+
const website = jsonLd?.website?.(pub.locale);
|
|
1856
|
+
const modified = modifiedAt(pub);
|
|
1857
|
+
const words = wordCountOf(pub);
|
|
1858
|
+
const publisherNode = publisher ? organization(publisher) : void 0;
|
|
1859
|
+
const section = article.breadcrumbs[0]?.title;
|
|
1860
|
+
const graph = [
|
|
1861
|
+
...full ? [{
|
|
1862
|
+
"@type": "WebPage",
|
|
1863
|
+
...id("webpage"),
|
|
1864
|
+
url: canonical,
|
|
1865
|
+
name: pub.title,
|
|
1866
|
+
...pub.description ? { description: pub.description } : {},
|
|
1867
|
+
inLanguage: pub.locale,
|
|
1868
|
+
...website ? { isPartOf: webSite(website) } : {},
|
|
1869
|
+
...publisherNode ? { publisher: publisherNode } : {},
|
|
1870
|
+
breadcrumb: id("breadcrumb"),
|
|
1871
|
+
mainEntity: id("article")
|
|
1872
|
+
}] : [],
|
|
1873
|
+
{
|
|
1874
|
+
"@type": "BlogPosting",
|
|
1875
|
+
...id("article"),
|
|
1876
|
+
headline: pub.title,
|
|
1877
|
+
...pub.description ? { description: pub.description } : {},
|
|
1878
|
+
datePublished: pub.published_at,
|
|
1879
|
+
...section ? { articleSection: section } : {},
|
|
1880
|
+
...modified ? { dateModified: modified } : {},
|
|
1881
|
+
...words ? { wordCount: words } : {},
|
|
1882
|
+
url: canonical,
|
|
1883
|
+
mainEntityOfPage: full ? id("webpage") : canonical,
|
|
1884
|
+
...author ? { author: { "@type": "Person", ...author.id ? { "@id": author.id } : {}, name: author.name, ...author.url ? { url: author.url } : {} } } : {},
|
|
1885
|
+
...publisherNode ? { publisher: publisherNode } : {},
|
|
1886
|
+
inLanguage: pub.locale,
|
|
1887
|
+
...imageUrl ? { image: imageWidth && imageHeight ? { "@type": "ImageObject", url: imageUrl, width: imageWidth, height: imageHeight } : [imageUrl] } : {}
|
|
1888
|
+
},
|
|
1889
|
+
{
|
|
1890
|
+
"@type": "BreadcrumbList",
|
|
1891
|
+
...id("breadcrumb"),
|
|
1892
|
+
itemListElement: breadcrumbItems(article, jsonLd).map((b, i) => ({
|
|
1893
|
+
"@type": "ListItem",
|
|
1894
|
+
position: i + 1,
|
|
1895
|
+
name: b.title,
|
|
1896
|
+
item: absoluteUrl(origin, crumbHref(href, b.canonical_path, pub.locale).replace(/^\/$/, ""))
|
|
1897
|
+
}))
|
|
1898
|
+
}
|
|
1899
|
+
];
|
|
1900
|
+
return script({ "@context": "https://schema.org", "@graph": graph });
|
|
1901
|
+
}
|
|
1902
|
+
function listJsonLd({ list, origin, href, path, locale, description, jsonLd, cursor }) {
|
|
1903
|
+
const url = absoluteUrl(origin, href(path)) + (cursor ? `?cursor=${cursor}` : "");
|
|
1904
|
+
const website = jsonLd?.website?.(locale);
|
|
1905
|
+
return script({
|
|
1906
|
+
"@context": "https://schema.org",
|
|
1907
|
+
"@type": "CollectionPage",
|
|
1908
|
+
...jsonLd ? { "@id": `${url}#webpage` } : {},
|
|
1909
|
+
url,
|
|
1910
|
+
...website ? { isPartOf: webSite(website) } : {},
|
|
1911
|
+
...jsonLd?.publisher ? { publisher: organization(jsonLd.publisher) } : {},
|
|
1912
|
+
name: list.section.title,
|
|
1913
|
+
...description ? { description } : {},
|
|
1914
|
+
inLanguage: locale,
|
|
1915
|
+
mainEntity: {
|
|
1916
|
+
"@type": "ItemList",
|
|
1917
|
+
itemListElement: list.items.map((item, i) => ({ "@type": "ListItem", position: i + 1, url: absoluteUrl(origin, href(item.canonical_path)), name: item.title }))
|
|
1918
|
+
}
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
// src/react/pages.tsx
|
|
1923
|
+
var import_toc_spy = require("./toc-spy.cjs");
|
|
1924
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1925
|
+
function Slot({ name, slots, tag: Tag = "div", className }) {
|
|
1926
|
+
const fill = slots?.[name];
|
|
1927
|
+
return fill ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Tag, { "data-slot": name, className, children: fill }) : null;
|
|
1928
|
+
}
|
|
1929
|
+
function Shell({ children }) {
|
|
1930
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "hyle", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "hyle-page", children }) });
|
|
1931
|
+
}
|
|
1932
|
+
function ctx(p, fallbackLocale) {
|
|
1933
|
+
const locale = p.locale ?? fallbackLocale;
|
|
1934
|
+
return { s: stringsFor(locale), locale, href: (path, linkLocale) => p.toHref ? p.toHref(path, linkLocale ?? locale) : path, Link: p.components?.Link ?? "a" };
|
|
1935
|
+
}
|
|
1936
|
+
function Pager({ prev, next, c }) {
|
|
1937
|
+
if (!prev && !next) return null;
|
|
1938
|
+
const { Link, s } = c;
|
|
1939
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("nav", { className: "hyle-pager", "aria-label": s.pager, children: [
|
|
1940
|
+
prev ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Link, { href: c.href(prev.canonical_path), rel: "prev", children: [
|
|
1941
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "dir", children: [
|
|
1942
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "chev-left" }),
|
|
1943
|
+
s.prev
|
|
1944
|
+
] }),
|
|
1945
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "ttl", children: prev.title })
|
|
1946
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "none", "aria-hidden": "true" }),
|
|
1947
|
+
next ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Link, { href: c.href(next.canonical_path), rel: "next", className: "next", children: [
|
|
1948
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "dir", children: [
|
|
1949
|
+
s.next,
|
|
1950
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "chev" })
|
|
1951
|
+
] }),
|
|
1952
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "ttl", children: next.title })
|
|
1953
|
+
] }) : null
|
|
1954
|
+
] });
|
|
1955
|
+
}
|
|
1956
|
+
function OlderNav({ href, c }) {
|
|
1957
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("nav", { className: "hyle-pagination", "aria-label": c.s.pager, children: [
|
|
1958
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sp" }),
|
|
1959
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(c.Link, { className: "hyle-btn sm", href, rel: "next", children: [
|
|
1960
|
+
c.s.older,
|
|
1961
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "chev" })
|
|
1962
|
+
] })
|
|
1963
|
+
] });
|
|
1964
|
+
}
|
|
1965
|
+
function TocList({ toc }) {
|
|
1966
|
+
const groups = [];
|
|
1967
|
+
for (const entry of toc) {
|
|
1968
|
+
const last = groups.at(-1);
|
|
1969
|
+
if (entry.depth === 3 && last) last.subs.push(entry);
|
|
1970
|
+
else groups.push({ entry, subs: [] });
|
|
1971
|
+
}
|
|
1972
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { children: groups.map(({ entry, subs }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("li", { children: [
|
|
1973
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("a", { href: `#${scopeId(entry.id)}`, children: entry.text }),
|
|
1974
|
+
subs.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { children: subs.map((sub) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("a", { href: `#${scopeId(sub.id)}`, children: sub.text }) }, sub.id)) }) : null
|
|
1975
|
+
] }, entry.id)) });
|
|
1976
|
+
}
|
|
1977
|
+
function Toc({ toc, c, aside, spy, className }) {
|
|
1978
|
+
const entries = toc.filter((t) => t.depth === 2 || t.depth === 3);
|
|
1979
|
+
if (entries.length === 0 && !aside) return { narrow: null, wide: null };
|
|
1980
|
+
const { s } = c;
|
|
1981
|
+
const classes = (own) => className ? `${className} ${own}` : own;
|
|
1982
|
+
return {
|
|
1983
|
+
narrow: entries.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("details", { className: classes("hyle-toc-m"), children: [
|
|
1984
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("summary", { children: [
|
|
1985
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "file" }),
|
|
1986
|
+
s.toc,
|
|
1987
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "chev-down", className: "hyle-chev" })
|
|
1988
|
+
] }),
|
|
1989
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("nav", { className: "hyle-toc-list", "aria-label": s.toc, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(TocList, { toc: entries }) })
|
|
1990
|
+
] }),
|
|
1991
|
+
wide: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("aside", { className: classes("hyle-toc-d"), "aria-label": s.toc, children: [
|
|
1992
|
+
entries.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
1993
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "hyle-toc-title", children: s.toc }),
|
|
1994
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("nav", { className: "hyle-toc-list", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(TocList, { toc: entries }) })
|
|
1995
|
+
] }),
|
|
1996
|
+
aside,
|
|
1997
|
+
spy && entries.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_toc_spy.TocSpy, { ids: entries.map((t) => scopeId(t.id)) }) : null
|
|
1998
|
+
] })
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
function Body({ article, components, locale }) {
|
|
2002
|
+
const { content, publication } = article;
|
|
2003
|
+
const lang = article.fallback ? void 0 : publication.locale;
|
|
2004
|
+
if (content.format === "hast") {
|
|
2005
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ProseBody, { className: "hyle-body hyle-prose", lang, tree: content.tree, title: publication.title, description: publication.description, components: components ?? {}, locale });
|
|
2006
|
+
}
|
|
2007
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "hyle-body hyle-prose", lang, children: content.format === "html" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(TrustedServerHtml, { html: content.html }) : null });
|
|
2008
|
+
}
|
|
2009
|
+
function Languages({ alternates, current, c }) {
|
|
2010
|
+
if (alternates.length < 2) return null;
|
|
2011
|
+
const { Link, s } = c;
|
|
2012
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("nav", { className: "hyle-langs", "aria-label": s.languages, children: [
|
|
2013
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: s.readIn }),
|
|
2014
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { children: alternates.map((a) => {
|
|
2015
|
+
const label = languageName(a.locale, a.locale);
|
|
2016
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { children: a.locale === current ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("a", { href: c.href(a.canonical_path, a.locale), hrefLang: a.locale, lang: a.locale, "aria-current": "true", children: label }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Link, { href: c.href(a.canonical_path, a.locale), hrefLang: a.locale, lang: a.locale, children: label }) }, a.locale);
|
|
2017
|
+
}) })
|
|
2018
|
+
] });
|
|
2019
|
+
}
|
|
2020
|
+
function LdScript({ json: json2 }) {
|
|
2021
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("script", { type: "application/ld+json", dangerouslySetInnerHTML: { __html: json2 } });
|
|
2022
|
+
}
|
|
2023
|
+
function Crumbs({ items, c }) {
|
|
2024
|
+
const { Link } = c;
|
|
2025
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("nav", { className: "hyle-crumbs", "aria-label": c.s.crumbs, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ol", { children: items.map((b, i) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { "aria-current": i === items.length - 1 ? "page" : void 0, children: i === items.length - 1 ? b.title : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Link, { href: crumbHref(c.href, b.canonical_path, c.locale), children: b.title }) }, b.canonical_path)) }) });
|
|
2026
|
+
}
|
|
2027
|
+
function ArticlePage({ article, engagement, origin, jsonLd, imageUrl, imageWidth, imageHeight, related, ...base }) {
|
|
2028
|
+
const { publication: pub } = article;
|
|
2029
|
+
const c = ctx(base, pub.locale);
|
|
2030
|
+
const { s } = c;
|
|
2031
|
+
const jsonLdOrigin = bareOrigin(origin);
|
|
2032
|
+
const author = articleAuthor(article, jsonLd)?.name;
|
|
2033
|
+
const modified = modifiedAt(pub);
|
|
2034
|
+
const words = wordCountOf(pub);
|
|
2035
|
+
const toc = Toc({ toc: article.toc, c, spy: true, aside: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "article.aside", slots: base.slots, className: "hyle-slot-wrap" }) });
|
|
2036
|
+
const notTranslated = article.fallback ? s.fallbackTitle.replace("{language}", languageName(article.fallback.requested_locale, c.locale)) : void 0;
|
|
2037
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("article", { className: "hyle-article", "data-hyle-page": "article", lang: c.locale, children: [
|
|
2038
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("header", { className: "hyle-head", children: [
|
|
2039
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "article.before", slots: base.slots, className: "hyle-eyebrow" }),
|
|
2040
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Crumbs, { items: breadcrumbItems(article, jsonLd), c }),
|
|
2041
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h1", { className: "hyle-title", children: pub.title }),
|
|
2042
|
+
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
2043
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-meta", children: [
|
|
2044
|
+
author ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { children: [
|
|
2045
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: author.slice(0, 2).toUpperCase() }),
|
|
2046
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { children: [
|
|
2047
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "hyle-sr", children: [
|
|
2048
|
+
s.by,
|
|
2049
|
+
" "
|
|
2050
|
+
] }),
|
|
2051
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "by", children: author })
|
|
2052
|
+
] })
|
|
2053
|
+
] }) : null,
|
|
2054
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { children: [
|
|
2055
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "calendar" }),
|
|
2056
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("time", { dateTime: pub.published_at, title: pub.published_at, children: formatDate(pub.published_at, c.locale) })
|
|
2057
|
+
] }),
|
|
2058
|
+
modified ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { children: [
|
|
2059
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "calendar" }),
|
|
2060
|
+
s.updated,
|
|
2061
|
+
" ",
|
|
2062
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("time", { dateTime: modified, title: modified, children: formatDate(modified, c.locale) })
|
|
2063
|
+
] }) : null,
|
|
2064
|
+
words ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { children: [
|
|
2065
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "clock" }),
|
|
2066
|
+
s.readingTime.replace("{n}", String(readingMinutes(words)))
|
|
2067
|
+
] }) : null,
|
|
2068
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { children: [
|
|
2069
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "globe" }),
|
|
2070
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { lang: pub.locale, children: languageName(pub.locale, c.locale) })
|
|
2071
|
+
] }),
|
|
2072
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "article.meta", slots: base.slots, tag: "span" })
|
|
2073
|
+
] }),
|
|
2074
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Languages, { alternates: article.alternates, current: pub.locale, c }),
|
|
2075
|
+
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
2076
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "alert" }),
|
|
2077
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
|
|
2078
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("b", { children: notTranslated }),
|
|
2079
|
+
" ",
|
|
2080
|
+
s.fallbackBody
|
|
2081
|
+
] })
|
|
2082
|
+
] }) : null
|
|
2083
|
+
] }),
|
|
2084
|
+
toc.narrow,
|
|
2085
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
2086
|
+
engagement ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_comments.Comments, { path: pub.canonical_path, endpoint: engagement.endpoint ?? "/api/hyle/engage", signInHref: engagement.signInHref, locale: c.locale, labels: s.comments }) : null,
|
|
2087
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Pager, { prev: article.prev, next: article.next, c }),
|
|
2088
|
+
related ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
2089
|
+
related.items.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(HyleListView, { items: related.items, title: related.title ?? s.moreInSection, ...base, locale: c.locale }) : null,
|
|
2090
|
+
article.children.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(HyleListView, { items: article.children.map((child) => ({ ...child, description: null, published_at: "" })), title: s.subPages, ...base, locale: c.locale }) : null
|
|
2091
|
+
] }) : null,
|
|
2092
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "article.after", slots: base.slots, className: "hyle-after" }),
|
|
2093
|
+
toc.wide,
|
|
2094
|
+
jsonLdOrigin ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(LdScript, { json: articleJsonLd({ article, origin: jsonLdOrigin, href: c.href, jsonLd, imageUrl, imageWidth, imageHeight }) }) : null
|
|
2095
|
+
] }) });
|
|
2096
|
+
}
|
|
2097
|
+
function ListPage({ list, olderHref, description, origin, path, jsonLd, cursor, ...base }) {
|
|
2098
|
+
const c = ctx(base, "en");
|
|
2099
|
+
const { s, Link } = c;
|
|
2100
|
+
const Row = base.slots?.["list.item"];
|
|
2101
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2102
|
+
for (const item of list.items) groups.set(item.published_at.slice(0, 7), [...groups.get(item.published_at.slice(0, 7)) ?? [], item]);
|
|
2103
|
+
const notTranslated = list.fallback ? s.fallbackTitle.replace("{language}", languageName(list.fallback.requested_locale, c.locale)) : void 0;
|
|
2104
|
+
const jsonLdOrigin = bareOrigin(origin);
|
|
2105
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-listpage", "data-hyle-page": "list", lang: c.locale, children: [
|
|
2106
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("header", { className: "hyle-head", children: [
|
|
2107
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h1", { className: "hyle-title", children: list.section.title }),
|
|
2108
|
+
description ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "hyle-desc", children: description }) : null,
|
|
2109
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "list.header", slots: base.slots, className: "hyle-slot-wrap" }),
|
|
2110
|
+
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
2111
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "alert" }),
|
|
2112
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
|
|
2113
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("b", { children: notTranslated }),
|
|
2114
|
+
" ",
|
|
2115
|
+
s.fallbackBody
|
|
2116
|
+
] })
|
|
2117
|
+
] }) : null
|
|
2118
|
+
] }),
|
|
2119
|
+
list.items.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-empty", "data-slot-state": "empty", children: [
|
|
2120
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "file" }),
|
|
2121
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h2", { children: s.emptyTitle }),
|
|
2122
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { children: s.emptyBody }),
|
|
2123
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "list.empty", slots: base.slots })
|
|
2124
|
+
] }) : [...groups].map(([month, items]) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("section", { "aria-label": formatDate(`${month}-01`, c.locale, { month: "long", year: "numeric" }), children: [
|
|
2125
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h2", { className: "hyle-year", children: formatDate(`${month}-01`, c.locale, { month: "long", year: "numeric" }) }),
|
|
2126
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "hyle-items", children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { children: Row ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Row, { item, href: c.href(item.canonical_path), locale: c.locale }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Link, { className: "hyle-item", href: c.href(item.canonical_path), children: [
|
|
2127
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("time", { dateTime: item.published_at, title: item.published_at, children: formatDate(item.published_at, c.locale) }),
|
|
2128
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
|
|
2129
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "t", children: item.title }),
|
|
2130
|
+
item.description ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { children: item.description }) : null
|
|
2131
|
+
] })
|
|
2132
|
+
] }) }, item.canonical_path)) })
|
|
2133
|
+
] }, month)),
|
|
2134
|
+
olderHref ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(OlderNav, { href: olderHref, c }) : null,
|
|
2135
|
+
jsonLdOrigin && path ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(LdScript, { json: listJsonLd({ list, origin: jsonLdOrigin, href: c.href, path, locale: c.locale, description, jsonLd, cursor }) }) : null
|
|
2136
|
+
] }) });
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
// src/react/index.ts
|
|
2140
|
+
var import_comments2 = require("./comments.cjs");
|
|
2141
|
+
var import_reactions = require("./reactions.cjs");
|
|
2142
|
+
|
|
2143
|
+
// src/react/docs.tsx
|
|
2144
|
+
var import_docs_enhance = require("./docs-enhance.cjs");
|
|
2145
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
2146
|
+
var ROOT_ID = "hyle-docs";
|
|
2147
|
+
var NAV_ID = "hyle-docs-nav";
|
|
2148
|
+
function navTreeOf(article) {
|
|
2149
|
+
if (article.nav && !article.nav.truncated && article.nav.items.length > 0) return article.nav.items;
|
|
2150
|
+
const { publication: pub } = article;
|
|
2151
|
+
const here = {
|
|
2152
|
+
slug: pub.slug,
|
|
2153
|
+
title: pub.title,
|
|
2154
|
+
canonical_path: pub.canonical_path,
|
|
2155
|
+
children: article.children.map((child) => ({ ...child, children: [] }))
|
|
2156
|
+
};
|
|
2157
|
+
return [article.ancestors.reduceRight((inner, a) => ({ ...a, children: [inner] }), here)];
|
|
2158
|
+
}
|
|
2159
|
+
function pathTo(nodes, path) {
|
|
2160
|
+
for (const node of nodes) {
|
|
1736
2161
|
if (node.canonical_path === path) return [node.canonical_path];
|
|
1737
2162
|
const below = pathTo(node.children, path);
|
|
1738
2163
|
if (below.length > 0) return [node.canonical_path, ...below];
|
|
@@ -1741,15 +2166,15 @@ function pathTo(nodes, path) {
|
|
|
1741
2166
|
}
|
|
1742
2167
|
function Branch({ nodes, current, onPath, c }) {
|
|
1743
2168
|
const { Link } = c;
|
|
1744
|
-
return /* @__PURE__ */ (0,
|
|
1745
|
-
const link = /* @__PURE__ */ (0,
|
|
1746
|
-
if (node.children.length === 0) return /* @__PURE__ */ (0,
|
|
1747
|
-
return /* @__PURE__ */ (0,
|
|
1748
|
-
/* @__PURE__ */ (0,
|
|
1749
|
-
/* @__PURE__ */ (0,
|
|
2169
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("ul", { children: nodes.map((node) => {
|
|
2170
|
+
const link = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Link, { href: c.href(node.canonical_path), ...node.canonical_path === current ? { "aria-current": "page" } : {}, children: node.title });
|
|
2171
|
+
if (node.children.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("li", { children: link }, node.canonical_path);
|
|
2172
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("details", { ...onPath.has(node.canonical_path) ? { open: true } : {}, children: [
|
|
2173
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("summary", { children: [
|
|
2174
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Icon, { name: "chev" }),
|
|
1750
2175
|
link
|
|
1751
2176
|
] }),
|
|
1752
|
-
/* @__PURE__ */ (0,
|
|
2177
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Branch, { nodes: node.children, current, onPath, c })
|
|
1753
2178
|
] }) }, node.canonical_path);
|
|
1754
2179
|
}) });
|
|
1755
2180
|
}
|
|
@@ -1763,47 +2188,47 @@ function DocsPage({ article, ...base }) {
|
|
|
1763
2188
|
const siteName = article.breadcrumbs[0]?.title ?? "";
|
|
1764
2189
|
const headingIds = article.toc.filter((t) => t.depth === 2 || t.depth === 3).map((t) => scopeId(t.id));
|
|
1765
2190
|
const notTranslated = article.fallback ? s.fallbackTitle.replace("{language}", languageName(article.fallback.requested_locale, c.locale)) : void 0;
|
|
1766
|
-
return /* @__PURE__ */ (0,
|
|
1767
|
-
/* @__PURE__ */ (0,
|
|
1768
|
-
/* @__PURE__ */ (0,
|
|
1769
|
-
/* @__PURE__ */ (0,
|
|
2191
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "hyle-docs", id: ROOT_ID, lang: c.locale, children: [
|
|
2192
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_docs_enhance.DocsEnhance, { headingIds, rootId: ROOT_ID }),
|
|
2193
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("button", { type: "button", className: "hyle-nav-bar", popoverTarget: NAV_ID, children: [
|
|
2194
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Icon, { name: "file" }),
|
|
1770
2195
|
s.menu,
|
|
1771
|
-
/* @__PURE__ */ (0,
|
|
1772
|
-
/* @__PURE__ */ (0,
|
|
2196
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "cur", children: pub.title }),
|
|
2197
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Icon, { name: "chev-down", className: "hyle-chev" })
|
|
1773
2198
|
] }),
|
|
1774
|
-
/* @__PURE__ */ (0,
|
|
1775
|
-
/* @__PURE__ */ (0,
|
|
1776
|
-
/* @__PURE__ */ (0,
|
|
1777
|
-
/* @__PURE__ */ (0,
|
|
1778
|
-
/* @__PURE__ */ (0,
|
|
2199
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("aside", { className: "hyle-nav-d", id: NAV_ID, popover: "auto", "aria-label": s.docs, children: [
|
|
2200
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "hyle-side-head", children: [
|
|
2201
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("b", { children: siteName }),
|
|
2202
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Slot, { name: "docs.version", slots: base.slots, tag: "span" }),
|
|
2203
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { type: "button", className: "hyle-nav-x", popoverTarget: NAV_ID, popoverTargetAction: "hide", "aria-label": s.closeMenu, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Icon, { name: "x" }) })
|
|
1779
2204
|
] }),
|
|
1780
|
-
/* @__PURE__ */ (0,
|
|
1781
|
-
/* @__PURE__ */ (0,
|
|
1782
|
-
/* @__PURE__ */ (0,
|
|
2205
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Slot, { name: "docs.sidebar-header", slots: base.slots, className: "hyle-side-slot" }),
|
|
2206
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("nav", { className: "hyle-tree", "aria-label": s.docs, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Branch, { nodes: tree, current: pub.canonical_path, onPath, c }) }),
|
|
2207
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Slot, { name: "docs.sidebar-footer", slots: base.slots, className: "hyle-side-slot" })
|
|
1783
2208
|
] }),
|
|
1784
|
-
/* @__PURE__ */ (0,
|
|
1785
|
-
notTranslated ? /* @__PURE__ */ (0,
|
|
1786
|
-
/* @__PURE__ */ (0,
|
|
1787
|
-
/* @__PURE__ */ (0,
|
|
1788
|
-
/* @__PURE__ */ (0,
|
|
2209
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "hyle-docs-main", "data-hyle-page": "docs", children: [
|
|
2210
|
+
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
2211
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Icon, { name: "alert" }),
|
|
2212
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { children: [
|
|
2213
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("b", { children: notTranslated }),
|
|
1789
2214
|
" ",
|
|
1790
2215
|
s.fallbackBody
|
|
1791
2216
|
] })
|
|
1792
2217
|
] }) : null,
|
|
1793
|
-
/* @__PURE__ */ (0,
|
|
1794
|
-
/* @__PURE__ */ (0,
|
|
1795
|
-
pub.description ? /* @__PURE__ */ (0,
|
|
1796
|
-
/* @__PURE__ */ (0,
|
|
1797
|
-
/* @__PURE__ */ (0,
|
|
2218
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("nav", { className: "hyle-crumbs", "aria-label": s.crumbs, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("ol", { children: article.breadcrumbs.map((b, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("li", { "aria-current": i === article.breadcrumbs.length - 1 ? "page" : void 0, children: i === article.breadcrumbs.length - 1 ? b.title : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Link, { href: c.href(b.canonical_path), children: b.title }) }, b.canonical_path)) }) }),
|
|
2219
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("h1", { className: "hyle-title", children: pub.title }),
|
|
2220
|
+
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
2221
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("p", { className: "hyle-updated", children: [
|
|
2222
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Icon, { name: "calendar" }),
|
|
1798
2223
|
s.updated,
|
|
1799
2224
|
" ",
|
|
1800
|
-
/* @__PURE__ */ (0,
|
|
2225
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("time", { dateTime: pub.updated_at, title: pub.updated_at, children: formatDate(pub.updated_at, c.locale) })
|
|
1801
2226
|
] }),
|
|
1802
2227
|
toc.narrow,
|
|
1803
|
-
/* @__PURE__ */ (0,
|
|
1804
|
-
/* @__PURE__ */ (0,
|
|
1805
|
-
/* @__PURE__ */ (0,
|
|
1806
|
-
/* @__PURE__ */ (0,
|
|
2228
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
2229
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Pager, { prev: article.prev, next: article.next, c }),
|
|
2230
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Slot, { name: "docs.after", slots: base.slots, className: "hyle-after" }),
|
|
2231
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "hyle-docs-end", "aria-hidden": "true" })
|
|
1807
2232
|
] }),
|
|
1808
2233
|
toc.wide
|
|
1809
2234
|
] }) });
|
|
@@ -1843,7 +2268,7 @@ function safeRedirectTarget(to) {
|
|
|
1843
2268
|
}
|
|
1844
2269
|
|
|
1845
2270
|
// src/next/resolve.ts
|
|
1846
|
-
var DEFAULT_REVALIDATE =
|
|
2271
|
+
var DEFAULT_REVALIDATE = 86400;
|
|
1847
2272
|
var MAX_TAGS2 = 64;
|
|
1848
2273
|
function workspaceTags(workspaceId, sections = []) {
|
|
1849
2274
|
const workspaceTag = `hyle:1:ws:${workspaceId}`;
|
|
@@ -1873,6 +2298,12 @@ function fetchResolver(options) {
|
|
|
1873
2298
|
function resolverFor(options) {
|
|
1874
2299
|
return options.resolver ?? fetchResolver(options);
|
|
1875
2300
|
}
|
|
2301
|
+
function articleImage(options, article) {
|
|
2302
|
+
const { canonical_path, locale, title, updated_at } = article.publication;
|
|
2303
|
+
const edited = Date.parse(updated_at);
|
|
2304
|
+
const fallback = { url: `/api/hyle/og${canonical_path.split("/").map(encodeURIComponent).join("/")}?locale=${encodeURIComponent(locale)}${Number.isNaN(edited) ? "" : `&v=${edited}`}`, width: 1200, height: 630, alt: title };
|
|
2305
|
+
return validOgImage(options.ogImage ? options.ogImage(article) : options.ogImageRoute ? fallback : void 0, bareOrigin(options.siteOrigin));
|
|
2306
|
+
}
|
|
1876
2307
|
var CURSOR = /^[A-Za-z0-9_-]{1,256}$/;
|
|
1877
2308
|
var validCursor = (value) => typeof value === "string" && CURSOR.test(value) ? value : void 0;
|
|
1878
2309
|
var LOCALE_TAG2 = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
|
|
@@ -1892,47 +2323,434 @@ function isRejectedRequest(error) {
|
|
|
1892
2323
|
return error instanceof Cp1ClientError && error.status >= 400 && error.status < 500 && ![401, 403, 429].includes(error.status);
|
|
1893
2324
|
}
|
|
1894
2325
|
|
|
1895
|
-
// src/next/
|
|
1896
|
-
var
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
2326
|
+
// src/next/embed.tsx
|
|
2327
|
+
var import_navigation2 = require("next/navigation");
|
|
2328
|
+
|
|
2329
|
+
// src/next/engage.ts
|
|
2330
|
+
var import_node_crypto3 = require("crypto");
|
|
2331
|
+
var ENGAGE_CSRF_HEADER = "x-hyle-engage";
|
|
2332
|
+
var DEFAULT_TIMEOUT_MS2 = 1e4;
|
|
2333
|
+
var DEFAULT_SHARE_MS = 3e3;
|
|
2334
|
+
var MAX_SHARED = 100;
|
|
2335
|
+
var MAX_SHARED_BYTES = 8 * 1024 * 1024;
|
|
2336
|
+
var MAX_SHARED_ENTRY_BYTES = 256 * 1024;
|
|
2337
|
+
var MAX_BODY_BYTES2 = 20 * 1024;
|
|
2338
|
+
var MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
2339
|
+
var MAX_COMMENT_CHARACTERS = 4e3;
|
|
2340
|
+
var MAX_PATH_LENGTH2 = 1024;
|
|
2341
|
+
var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
2342
|
+
var CONTROL = /[\u0000-\u001f\u007f\\]/;
|
|
2343
|
+
var HEADERS = { "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" };
|
|
2344
|
+
var isSwitchedOff = (value) => {
|
|
2345
|
+
const v = value?.trim().toLowerCase() ?? "";
|
|
2346
|
+
return v !== "" && v !== "1" && v !== "true";
|
|
2347
|
+
};
|
|
2348
|
+
var json = (status, body, extra = {}) => new Response(JSON.stringify(body), { status, headers: { ...HEADERS, "Content-Type": "application/json; charset=utf-8", ...extra } });
|
|
2349
|
+
var refuse = (status, code, extra = {}) => json(status, { error: { code } }, extra);
|
|
2350
|
+
function isSitePath2(value) {
|
|
2351
|
+
if (typeof value !== "string" || value.length > MAX_PATH_LENGTH2 || !value.startsWith("/") || value.startsWith("//")) return false;
|
|
2352
|
+
if (CONTROL.test(value) || /[?#]/.test(value)) return false;
|
|
2353
|
+
return !value.split("/").some((segment) => segment === "." || segment === "..");
|
|
2354
|
+
}
|
|
2355
|
+
function match(segments) {
|
|
2356
|
+
const [a, b, ...rest] = segments;
|
|
2357
|
+
if (a === "session" && b === void 0) return { local: "session", action: () => "session", methods: ["GET"], rebuild: () => void 0 };
|
|
2358
|
+
if (a === "comments" && b === void 0) {
|
|
2359
|
+
return {
|
|
2360
|
+
action: (m) => m === "GET" ? "comments.list" : "comments.create",
|
|
2361
|
+
methods: ["GET", "POST"],
|
|
2362
|
+
rebuild: (method, body, url) => {
|
|
2363
|
+
if (method === "GET") {
|
|
2364
|
+
const query = listingQuery(url.searchParams);
|
|
2365
|
+
return query && { upstream: "/comments", query };
|
|
2366
|
+
}
|
|
2367
|
+
const clean2 = pick(body, ["path", "body", "parent_id"], ["path", "body"]);
|
|
2368
|
+
if (!clean2 || !isSitePath2(clean2.path) || !isCommentText(clean2.body)) return void 0;
|
|
2369
|
+
if (clean2.parent_id === null) delete clean2.parent_id;
|
|
2370
|
+
if (clean2.parent_id !== void 0 && !(typeof clean2.parent_id === "string" && UUID2.test(clean2.parent_id))) return void 0;
|
|
2371
|
+
return { upstream: "/comments", body: clean2 };
|
|
2372
|
+
}
|
|
2373
|
+
};
|
|
2374
|
+
}
|
|
2375
|
+
if (a === "comments" && typeof b === "string" && UUID2.test(b) && rest.length === 0) {
|
|
2376
|
+
return {
|
|
2377
|
+
action: (m) => m === "PATCH" ? "comments.edit" : "comments.delete",
|
|
2378
|
+
methods: ["PATCH", "DELETE"],
|
|
2379
|
+
rebuild: (method, body) => {
|
|
2380
|
+
if (method === "DELETE") return body === void 0 ? { upstream: `/comments/${b}` } : void 0;
|
|
2381
|
+
const clean2 = pick(body, ["body"], ["body"]);
|
|
2382
|
+
return clean2 && isCommentText(clean2.body) ? { upstream: `/comments/${b}`, body: clean2 } : void 0;
|
|
2383
|
+
}
|
|
2384
|
+
};
|
|
2385
|
+
}
|
|
2386
|
+
if (a === "reactions" && b === void 0) {
|
|
2387
|
+
return {
|
|
2388
|
+
action: (m) => m === "PUT" ? "reactions.add" : "reactions.remove",
|
|
2389
|
+
methods: ["PUT", "DELETE"],
|
|
2390
|
+
rebuild: (_method, body) => {
|
|
2391
|
+
const type = body?.subject_type;
|
|
2392
|
+
const subject = type === "article" ? "path" : type === "comment" ? "comment_id" : void 0;
|
|
2393
|
+
const clean2 = subject && pick(body, ["subject_type", subject, "kind"], ["subject_type", subject]);
|
|
2394
|
+
if (!clean2 || clean2.kind !== void 0 && !REACTION_KINDS.includes(clean2.kind)) return void 0;
|
|
2395
|
+
const valid = type === "article" ? isSitePath2(clean2.path) : typeof clean2.comment_id === "string" && UUID2.test(clean2.comment_id);
|
|
2396
|
+
return valid ? { upstream: "/reactions", body: clean2 } : void 0;
|
|
2397
|
+
}
|
|
2398
|
+
};
|
|
2399
|
+
}
|
|
2400
|
+
if (a === "votes" && b === void 0) {
|
|
2401
|
+
return {
|
|
2402
|
+
action: (m) => m === "PUT" ? "votes.set" : "votes.remove",
|
|
2403
|
+
methods: ["PUT", "DELETE"],
|
|
2404
|
+
rebuild: (method, body) => {
|
|
2405
|
+
const keys = method === "PUT" ? ["comment_id", "value"] : ["comment_id"];
|
|
2406
|
+
const clean2 = pick(body, keys, keys);
|
|
2407
|
+
if (!clean2 || typeof clean2.comment_id !== "string" || !UUID2.test(clean2.comment_id)) return void 0;
|
|
2408
|
+
if (method === "PUT" && clean2.value !== 1 && clean2.value !== -1) return void 0;
|
|
2409
|
+
return { upstream: "/votes", body: clean2 };
|
|
2410
|
+
}
|
|
2411
|
+
};
|
|
2412
|
+
}
|
|
2413
|
+
return void 0;
|
|
2414
|
+
}
|
|
2415
|
+
function listingQuery(params) {
|
|
2416
|
+
const keys = [...params.keys()];
|
|
2417
|
+
if (new Set(keys).size !== keys.length || keys.some((k) => k !== "path" && k !== "cursor" && k !== "sort")) return void 0;
|
|
2418
|
+
const path = params.get("path");
|
|
2419
|
+
const cursor = params.get("cursor");
|
|
2420
|
+
const sort = params.get("sort");
|
|
2421
|
+
if (!isSitePath2(path) || cursor !== null && !isCursor(cursor) || sort !== null && sort !== "new" && sort !== "top") return void 0;
|
|
2422
|
+
return new URLSearchParams({ path, ...cursor === null ? {} : { cursor }, ...sort === null ? {} : { sort } });
|
|
2423
|
+
}
|
|
2424
|
+
function pick(body, allowed, required) {
|
|
2425
|
+
if (!body || Object.keys(body).some((k) => !allowed.includes(k)) || !required.every((k) => k in body)) return void 0;
|
|
2426
|
+
return Object.fromEntries(allowed.filter((k) => k in body).map((k) => [k, body[k]]));
|
|
2427
|
+
}
|
|
2428
|
+
function isCommentText(value) {
|
|
2429
|
+
return typeof value === "string" && value.trim().length > 0 && [...value].length <= MAX_COMMENT_CHARACTERS && !/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/.test(value);
|
|
2430
|
+
}
|
|
2431
|
+
function sameOriginProblem(req, write, allowedOrigins) {
|
|
2432
|
+
const site = req.headers.get("sec-fetch-site");
|
|
2433
|
+
if (site !== null && site !== "same-origin") return true;
|
|
2434
|
+
if (!write) return false;
|
|
2435
|
+
const origin = req.headers.get("origin");
|
|
2436
|
+
if (origin === null) return true;
|
|
2437
|
+
let parsed;
|
|
2438
|
+
try {
|
|
2439
|
+
parsed = new URL(origin);
|
|
2440
|
+
} catch {
|
|
2441
|
+
return true;
|
|
2442
|
+
}
|
|
2443
|
+
if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
|
|
2444
|
+
if (allowedOrigins) return !allowedOrigins.some((o) => safeOrigin(o) === parsed.origin);
|
|
2445
|
+
const host = req.headers.get("x-forwarded-host")?.split(",")[0]?.trim() || req.headers.get("host") || new URL(req.url).host;
|
|
2446
|
+
const proto = req.headers.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase();
|
|
2447
|
+
if (proto && proto !== parsed.protocol.slice(0, -1)) return true;
|
|
2448
|
+
return parsed.host !== host;
|
|
2449
|
+
}
|
|
2450
|
+
var safeOrigin = (value) => {
|
|
2451
|
+
try {
|
|
2452
|
+
return new URL(value).origin;
|
|
2453
|
+
} catch {
|
|
2454
|
+
return void 0;
|
|
2455
|
+
}
|
|
2456
|
+
};
|
|
2457
|
+
async function readBody(req, expected) {
|
|
2458
|
+
if (!expected) return { kind: "ok", body: void 0 };
|
|
2459
|
+
if (!/^application\/json(\s*;|$)/i.test(req.headers.get("content-type") ?? "")) return { kind: "refused", response: refuse(415, "UNSUPPORTED_MEDIA_TYPE") };
|
|
2460
|
+
if (Number(req.headers.get("content-length")) > MAX_BODY_BYTES2) return { kind: "refused", response: refuse(413, "PAYLOAD_TOO_LARGE") };
|
|
2461
|
+
if (!req.body) return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
2462
|
+
const reader = req.body.getReader();
|
|
2463
|
+
const chunks = [];
|
|
2464
|
+
let total = 0;
|
|
2465
|
+
for (; ; ) {
|
|
2466
|
+
const { done, value } = await reader.read();
|
|
2467
|
+
if (done) break;
|
|
2468
|
+
total += value.byteLength;
|
|
2469
|
+
if (total > MAX_BODY_BYTES2) {
|
|
2470
|
+
await reader.cancel().catch(() => {
|
|
2471
|
+
});
|
|
2472
|
+
return { kind: "refused", response: refuse(413, "PAYLOAD_TOO_LARGE") };
|
|
2473
|
+
}
|
|
2474
|
+
chunks.push(value);
|
|
2475
|
+
}
|
|
2476
|
+
try {
|
|
2477
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
2478
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return { kind: "ok", body: parsed };
|
|
2479
|
+
} catch {
|
|
2480
|
+
}
|
|
2481
|
+
return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
2482
|
+
}
|
|
2483
|
+
var SUB_CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
|
|
2484
|
+
function validReader(r) {
|
|
2485
|
+
if (!r || typeof r.sub !== "string" || typeof r.name !== "string") return null;
|
|
2486
|
+
if (r.sub.length < 1 || [...r.sub].length > 255 || SUB_CONTROL.test(r.sub)) return null;
|
|
2487
|
+
const name = cleanDisplayName(r.name);
|
|
2488
|
+
return name === void 0 ? null : { sub: r.sub, name };
|
|
2489
|
+
}
|
|
2490
|
+
function relayFailure(status, retryAfter) {
|
|
2491
|
+
if (status === 400) return refuse(400, "VALIDATION_ERROR");
|
|
2492
|
+
if (status === 404) return refuse(404, "NOT_FOUND");
|
|
2493
|
+
if (status === 409) return refuse(409, "INVALID_TRANSITION");
|
|
2494
|
+
if (status === 413) return refuse(413, "PAYLOAD_TOO_LARGE");
|
|
2495
|
+
if (status === 429) {
|
|
2496
|
+
const seconds = Math.min(3600, Math.max(1, Math.trunc(Number(retryAfter)) || 60));
|
|
2497
|
+
return refuse(429, "RATE_LIMITED", { "Retry-After": String(seconds) });
|
|
2498
|
+
}
|
|
2499
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2500
|
+
}
|
|
2501
|
+
function createEngagementRoute(options) {
|
|
2502
|
+
let ready;
|
|
2503
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
2504
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2505
|
+
let cacheBytes = 0;
|
|
2506
|
+
const clearCache = () => {
|
|
2507
|
+
cache.clear();
|
|
2508
|
+
cacheBytes = 0;
|
|
2509
|
+
};
|
|
2510
|
+
async function listing(viewer, call) {
|
|
2511
|
+
if (!viewer) return call(void 0);
|
|
2512
|
+
let out = await call(viewer.sign("read"));
|
|
2513
|
+
if (out.status === 401) out = await call(viewer.sign("read"));
|
|
2514
|
+
if (out.status !== 401 && out.status !== 404 && !(out.status === 429 && out.throttle === "viewer")) return out;
|
|
2515
|
+
return { ...await call(void 0), noShare: true };
|
|
2516
|
+
}
|
|
2517
|
+
function shared(key, call) {
|
|
2518
|
+
const ttl = options.cacheTtlMs ?? DEFAULT_SHARE_MS;
|
|
2519
|
+
if (ttl <= 0) return call();
|
|
2520
|
+
const hit = cache.get(key);
|
|
2521
|
+
if (hit && Date.now() - hit.at < ttl) {
|
|
2522
|
+
cache.delete(key);
|
|
2523
|
+
cache.set(key, hit);
|
|
2524
|
+
return hit.result;
|
|
2525
|
+
}
|
|
2526
|
+
if (hit) forget(key, hit);
|
|
2527
|
+
const entry = { at: Date.now(), result: call(), bytes: 0 };
|
|
2528
|
+
cache.set(key, entry);
|
|
2529
|
+
entry.result.then(
|
|
2530
|
+
(o) => {
|
|
2531
|
+
if (cache.get(key) !== entry) return;
|
|
2532
|
+
if (![200, 400, 404].includes(o.status) || o.noShare || o.text.length > MAX_SHARED_ENTRY_BYTES) return forget(key, entry);
|
|
2533
|
+
entry.bytes = o.text.length;
|
|
2534
|
+
cacheBytes += entry.bytes;
|
|
2535
|
+
while ((cacheBytes > MAX_SHARED_BYTES || cache.size > MAX_SHARED) && cache.size > 0) {
|
|
2536
|
+
const oldest = cache.entries().next().value;
|
|
2537
|
+
forget(oldest[0], oldest[1]);
|
|
2538
|
+
}
|
|
2539
|
+
},
|
|
2540
|
+
() => forget(key, entry)
|
|
2541
|
+
);
|
|
2542
|
+
return entry.result;
|
|
2543
|
+
}
|
|
2544
|
+
function forget(key, entry) {
|
|
2545
|
+
if (cache.get(key) !== entry) return;
|
|
2546
|
+
cache.delete(key);
|
|
2547
|
+
cacheBytes -= entry.bytes;
|
|
2548
|
+
}
|
|
2549
|
+
function configured() {
|
|
2550
|
+
if (ready !== void 0) return ready;
|
|
2551
|
+
try {
|
|
2552
|
+
const baseUrl = options.baseUrl?.trim() ?? "";
|
|
2553
|
+
checkBaseUrl(baseUrl);
|
|
2554
|
+
if (!options.token?.trim() || !options.workspaceId?.trim() || !options.signingKey) throw new TypeError("not provisioned");
|
|
2555
|
+
ready = { base: baseUrl.replace(/\/+$/, ""), key: engagementSigningKey(options.signingKey.trim()) };
|
|
2556
|
+
} catch {
|
|
2557
|
+
ready = null;
|
|
2558
|
+
}
|
|
2559
|
+
return ready;
|
|
2560
|
+
}
|
|
2561
|
+
async function reader(req, config) {
|
|
2562
|
+
try {
|
|
2563
|
+
const found = validReader(await options.getReader(req));
|
|
2564
|
+
if (!found) return null;
|
|
2565
|
+
const claims = { sub: found.sub, name: found.name, workspace: options.workspaceId.trim() };
|
|
2566
|
+
const sign2 = (scope) => signReaderAssertion(config.key, claims, void 0, scope);
|
|
2567
|
+
return { reader: found, assertion: sign2(), sign: sign2 };
|
|
2568
|
+
} catch {
|
|
2569
|
+
return null;
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
async function handle(req, ctx2) {
|
|
2573
|
+
const env = options.env ?? process.env;
|
|
2574
|
+
if (isSwitchedOff(env.HYLE_ENGAGE_ENABLED) || isSwitchedOff(env.HYLE_CONTENT_ENABLED)) return refuse(404, "NOT_FOUND");
|
|
2575
|
+
const config = configured();
|
|
2576
|
+
const route = match((await ctx2.params).path ?? []);
|
|
2577
|
+
if (!config || !route) return refuse(404, "NOT_FOUND");
|
|
2578
|
+
if (!route.methods.includes(req.method)) return refuse(405, "METHOD_NOT_ALLOWED", { Allow: route.methods.join(", ") });
|
|
2579
|
+
const write = req.method !== "GET";
|
|
2580
|
+
if (sameOriginProblem(req, write, options.allowedOrigins)) return refuse(403, "FORBIDDEN");
|
|
2581
|
+
if (options.onRequest) {
|
|
2582
|
+
try {
|
|
2583
|
+
const early = await options.onRequest(req, { action: route.action(req.method) });
|
|
2584
|
+
if (early instanceof Response) {
|
|
2585
|
+
const headers = new Headers(early.headers);
|
|
2586
|
+
headers.set("cache-control", "no-store");
|
|
2587
|
+
return new Response(early.body, { status: early.status, headers });
|
|
2588
|
+
}
|
|
2589
|
+
} catch {
|
|
2590
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
if (route.local === "session") {
|
|
2594
|
+
const who = await reader(req, config);
|
|
2595
|
+
return json(200, { data: { reader: who ? { id: (0, import_node_crypto3.createHash)("sha256").update(who.reader.sub).digest("base64url"), name: who.reader.name } : null } });
|
|
2596
|
+
}
|
|
2597
|
+
let assertion;
|
|
2598
|
+
let viewer = null;
|
|
2599
|
+
if (route.action(req.method) === "comments.list") viewer = await reader(req, config);
|
|
2600
|
+
if (write) {
|
|
2601
|
+
const who = await reader(req, config);
|
|
2602
|
+
if (!who) return refuse(401, "UNAUTHENTICATED");
|
|
2603
|
+
assertion = who.assertion;
|
|
2604
|
+
}
|
|
2605
|
+
const url = new URL(req.url);
|
|
2606
|
+
const hasBody = write && !(req.method === "DELETE" && (await ctx2.params).path?.[0] === "comments");
|
|
2607
|
+
const body = await readBody(req, hasBody);
|
|
2608
|
+
if (body.kind === "refused") return body.response;
|
|
2609
|
+
const built = route.rebuild(req.method, body.body, url);
|
|
2610
|
+
if (!built) return refuse(400, "VALIDATION_ERROR");
|
|
2611
|
+
const baseHeaders = new Headers({ authorization: `Bearer ${options.token.trim()}`, accept: "application/json" });
|
|
2612
|
+
if (built.body) baseHeaders.set("content-type", "application/json");
|
|
2613
|
+
const target = `${config.base}/cp1/engage${built.upstream}${built.query ? `?${built.query}` : ""}`;
|
|
2614
|
+
const call = async (withAssertion = assertion) => {
|
|
2615
|
+
const headers = new Headers(baseHeaders);
|
|
2616
|
+
if (withAssertion) headers.set("hyle-reader-assertion", withAssertion);
|
|
2617
|
+
const res = await fetchImpl(target, {
|
|
2618
|
+
method: req.method,
|
|
2619
|
+
headers,
|
|
2620
|
+
...built.body ? { body: JSON.stringify(built.body) } : {},
|
|
2621
|
+
redirect: "error",
|
|
2622
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS2)
|
|
2623
|
+
});
|
|
2624
|
+
return { status: res.status, ok: res.ok, text: await readCapped(res, MAX_RESPONSE_BYTES), retryAfter: res.headers.get("retry-after"), throttle: res.headers.get("hyle-throttle") };
|
|
2625
|
+
};
|
|
2626
|
+
try {
|
|
2627
|
+
const out = route.action(req.method) === "comments.list" ? await shared(`${viewer?.reader.sub ?? ""}
|
|
2628
|
+
${built.query.toString()}`, () => listing(viewer, call)) : await call();
|
|
2629
|
+
if (!out.ok) return relayFailure(out.status, out.retryAfter);
|
|
2630
|
+
if (write) clearCache();
|
|
2631
|
+
const data = JSON.parse(out.text).data;
|
|
2632
|
+
return typeof data === "object" && data !== null ? json(out.status === 201 ? 201 : 200, { data }) : refuse(502, "UPSTREAM_ERROR");
|
|
2633
|
+
} catch {
|
|
2634
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
return { GET: handle, POST: handle, PATCH: handle, PUT: handle, DELETE: handle };
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
// src/next/embed.tsx
|
|
2641
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
2642
|
+
async function resolveEmbed(options, run) {
|
|
2643
|
+
try {
|
|
2644
|
+
return { result: await run() };
|
|
2645
|
+
} catch (error) {
|
|
2646
|
+
if (isRejectedRequest(error)) return {};
|
|
2647
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2648
|
+
return { failure: options.onError ? options.onError(error) : null };
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
async function HyleList({ options, limit = 5, locale, layout, title, headingLevel, moreHref, cursor, olderHref }) {
|
|
2652
|
+
const resolve = resolverFor(options);
|
|
2653
|
+
const route = routeContext(locale ? { ...options, locale } : options, {});
|
|
2654
|
+
const path = sitePathFrom(route.basePath, void 0);
|
|
2655
|
+
if (path === void 0) return null;
|
|
2656
|
+
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale, limit, validCursor(cursor)));
|
|
2657
|
+
if (failure !== void 0) return failure;
|
|
2658
|
+
const next = olderHref && result?.kind === "list" ? validCursor(result.next_cursor) : void 0;
|
|
2659
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.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 });
|
|
2660
|
+
}
|
|
2661
|
+
async function HyleArticle({ options, path, locale, headingLevel }) {
|
|
2662
|
+
if (!isSitePath2(path)) return null;
|
|
2663
|
+
const resolve = resolverFor(options);
|
|
2664
|
+
const route = routeContext(locale ? { ...options, locale } : options, {});
|
|
2665
|
+
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale));
|
|
2666
|
+
if (failure !== void 0) return failure;
|
|
2667
|
+
if (result?.kind !== "article") return null;
|
|
2668
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HyleArticleView, { article: result, headingLevel, components: options.components, slots: options.slots, locale: route.locale, toHref: route.toHref });
|
|
2669
|
+
}
|
|
2670
|
+
var MAX_LISTING_BYTES = 4 * 1024 * 1024;
|
|
2671
|
+
var COMMENTS_TIMEOUT_MS = 1e4;
|
|
2672
|
+
async function HyleComments({ options, path, revalidate = 60, interactive }) {
|
|
2673
|
+
checkBaseUrl(options.baseUrl);
|
|
2674
|
+
if (!options.token) throw new TypeError("token is required");
|
|
2675
|
+
if (!isSitePath2(path)) return null;
|
|
2676
|
+
const locale = options.locale ?? "en";
|
|
2677
|
+
let listing;
|
|
2678
|
+
let fetchedAt;
|
|
2679
|
+
try {
|
|
2680
|
+
const init = {
|
|
2681
|
+
headers: { authorization: `Bearer ${options.token}`, accept: "application/json" },
|
|
2682
|
+
redirect: "error",
|
|
2683
|
+
signal: AbortSignal.timeout(COMMENTS_TIMEOUT_MS),
|
|
2684
|
+
next: { revalidate }
|
|
2685
|
+
};
|
|
2686
|
+
const res = await fetch(`${options.baseUrl.replace(/\/+$/, "")}/cp1/engage/comments?${new URLSearchParams({ path })}`, init);
|
|
2687
|
+
if (!res.ok) {
|
|
2688
|
+
if (res.status !== 404) console.error(`hyle: comments answered HTTP ${res.status}`);
|
|
2689
|
+
return null;
|
|
2690
|
+
}
|
|
2691
|
+
listing = parseListing(JSON.parse(await readCapped(res, MAX_LISTING_BYTES)).data);
|
|
2692
|
+
const date = Date.parse(res.headers.get("date") ?? "");
|
|
2693
|
+
fetchedAt = Number.isFinite(date) ? date : void 0;
|
|
2694
|
+
} catch (error) {
|
|
2695
|
+
(0, import_navigation2.unstable_rethrow)(error);
|
|
2696
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2697
|
+
return null;
|
|
2698
|
+
}
|
|
2699
|
+
if (!listing) return null;
|
|
2700
|
+
if (!interactive) return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HyleCommentsView, { listing, locale });
|
|
2701
|
+
const config = interactive === true ? {} : interactive;
|
|
2702
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "hyle hyle-embed", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_comments2.Comments, { path, endpoint: config.endpoint ?? "/api/hyle/engage", signInHref: config.signInHref, locale, labels: stringsFor(locale).comments, initial: listing, initialAt: fetchedAt }) });
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2705
|
+
// src/next/page.tsx
|
|
2706
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2707
|
+
function hylePage(options) {
|
|
2708
|
+
const resolve = resolverFor(options);
|
|
2709
|
+
async function relatedItems(article) {
|
|
2710
|
+
const { limit = 5, title } = options.related ?? {};
|
|
2711
|
+
const section = article.breadcrumbs[0]?.canonical_path ?? (normalizeBasePath(options.basePath) || "/");
|
|
2712
|
+
const { result } = await resolveEmbed(options, () => resolve(section, article.publication.locale, limit + 1));
|
|
2713
|
+
const items = result?.kind === "list" ? result.items.filter((item) => item.canonical_path !== article.publication.canonical_path).slice(0, limit) : [];
|
|
2714
|
+
return { title, items };
|
|
2715
|
+
}
|
|
2716
|
+
return async function HylePage({ params, searchParams }) {
|
|
2717
|
+
const { path, locale, toHref } = routeContext(options, await params ?? {});
|
|
2718
|
+
if (path === void 0) (0, import_navigation3.notFound)();
|
|
2719
|
+
try {
|
|
2720
|
+
const cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
2721
|
+
const result = await resolve(path, locale, options.listLimit, cursor, options.layout === "docs" ? "tree" : void 0);
|
|
2722
|
+
switch (result.kind) {
|
|
2723
|
+
case "article": {
|
|
2724
|
+
const image = articleImage(options, result);
|
|
2725
|
+
const related = options.related && options.layout !== "docs" ? await relatedItems(result) : void 0;
|
|
2726
|
+
const props = { article: result, components: options.components, slots: options.slots, locale, toHref };
|
|
2727
|
+
return options.layout === "docs" ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(DocsPage, { ...props }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ArticlePage, { ...props, origin: options.siteOrigin, jsonLd: options.jsonLd, imageUrl: image?.url, imageWidth: image?.width, imageHeight: image?.height, related, ...options.engagement ? { engagement: options.engagement } : {} });
|
|
2728
|
+
}
|
|
2729
|
+
case "list": {
|
|
2730
|
+
const list = options.list?.title ? { ...result, section: { ...result.section, title: options.list.title } } : result;
|
|
2731
|
+
const next = options.paginate === "searchParams" ? validCursor(result.next_cursor) : void 0;
|
|
2732
|
+
const olderHref = next ? `${toHref(path)}?cursor=${next}` : void 0;
|
|
2733
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ListPage, { list, ...olderHref ? { olderHref } : {}, ...options.list?.description ? { description: options.list.description } : {}, components: options.components, slots: options.slots, locale, toHref, origin: options.siteOrigin, path, jsonLd: options.jsonLd, cursor });
|
|
2734
|
+
}
|
|
2735
|
+
case "redirect": {
|
|
2736
|
+
const to = safeRedirectTarget(result.to);
|
|
2737
|
+
if (to === void 0) throw new Cp1ClientError("INVALID_RESPONSE", "hyle returned an unsafe redirect target", 502, "");
|
|
2738
|
+
const target = safeRedirectTarget(toHref(to));
|
|
2739
|
+
if (target === void 0) throw new Cp1ClientError("INVALID_RESPONSE", "hyle returned an unsafe redirect target", 502, "");
|
|
2740
|
+
if (target === toHref(path)) (0, import_navigation3.notFound)();
|
|
2741
|
+
return result.status === 301 ? (0, import_navigation3.permanentRedirect)(target) : (0, import_navigation3.redirect)(target);
|
|
2742
|
+
}
|
|
2743
|
+
case "notfound":
|
|
2744
|
+
case "disabled":
|
|
2745
|
+
(0, import_navigation3.notFound)();
|
|
2746
|
+
}
|
|
2747
|
+
} catch (error) {
|
|
2748
|
+
if (isRejectedRequest(error)) (0, import_navigation3.notFound)();
|
|
2749
|
+
if (!options.onError) throw error;
|
|
2750
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2751
|
+
return options.onError(error);
|
|
2752
|
+
}
|
|
2753
|
+
};
|
|
1936
2754
|
}
|
|
1937
2755
|
|
|
1938
2756
|
// src/next/sitemap.ts
|
|
@@ -1976,27 +2794,81 @@ async function hyleSitemap(options) {
|
|
|
1976
2794
|
|
|
1977
2795
|
// src/next/metadata.ts
|
|
1978
2796
|
var titled = (template, title) => template?.includes("%s") ? { absolute: template.replace("%s", () => title) } : title;
|
|
2797
|
+
var LARGE_PREVIEW = "max-image-preview:large";
|
|
2798
|
+
var addDirective = (inherited) => {
|
|
2799
|
+
const tokens = (inherited ?? "").split(",").map((t) => t.trim()).filter(Boolean);
|
|
2800
|
+
return (tokens.includes(LARGE_PREVIEW) ? tokens : [...tokens, LARGE_PREVIEW]).join(", ");
|
|
2801
|
+
};
|
|
2802
|
+
var ROBOTS_KEYS = /* @__PURE__ */ new Set(["noarchive", "nosnippet", "noimageindex", "nocache", "notranslate", "indexifembedded", "nositelinkssearchbox", "unavailable_after", "max-video-preview", "max-image-preview", "max-snippet"]);
|
|
2803
|
+
var ROBOTS_ALIASES = {
|
|
2804
|
+
none: { index: false, follow: false },
|
|
2805
|
+
all: { index: true, follow: true },
|
|
2806
|
+
index: { index: true },
|
|
2807
|
+
noindex: { index: false },
|
|
2808
|
+
follow: { follow: true },
|
|
2809
|
+
nofollow: { follow: false }
|
|
2810
|
+
};
|
|
2811
|
+
function composeRobots(inherited) {
|
|
2812
|
+
const basic = addDirective(inherited?.basic);
|
|
2813
|
+
const object = {};
|
|
2814
|
+
for (const token of basic.split(", ")) {
|
|
2815
|
+
const colon = token.indexOf(":");
|
|
2816
|
+
const key = colon < 0 ? token : token.slice(0, colon);
|
|
2817
|
+
if (ROBOTS_KEYS.has(key)) object[key] = colon < 0 ? true : token.slice(colon + 1);
|
|
2818
|
+
else if (ROBOTS_ALIASES[key] && colon < 0) Object.assign(object, ROBOTS_ALIASES[key]);
|
|
2819
|
+
else return basic;
|
|
2820
|
+
}
|
|
2821
|
+
return { ...object, googleBot: addDirective(inherited?.googleBot) };
|
|
2822
|
+
}
|
|
2823
|
+
function hyleFeedLink(options, locale) {
|
|
2824
|
+
const { feed } = options;
|
|
2825
|
+
if (!feed || typeof feed.path === "function" && !locale) return void 0;
|
|
2826
|
+
const href = typeof feed.path === "function" ? feed.path(locale) : feed.path;
|
|
2827
|
+
const origin = bareOrigin(options.siteOrigin);
|
|
2828
|
+
return { url: origin ? absoluteUrl(origin, href) : href, title: feed.title ?? (options.siteName ? `${options.siteName} feed` : "Feed") };
|
|
2829
|
+
}
|
|
1979
2830
|
function hyleMetadata(options) {
|
|
1980
2831
|
const resolve = resolverFor(options);
|
|
1981
2832
|
const origin = bareOrigin(options.siteOrigin);
|
|
1982
|
-
return async function generateMetadata({ params, searchParams }) {
|
|
2833
|
+
return async function generateMetadata({ params, searchParams }, parent) {
|
|
1983
2834
|
const { path, locale, toHref } = routeContext(options, await params ?? {});
|
|
1984
2835
|
if (path === void 0) return {};
|
|
1985
2836
|
const link = (sitePath, linkLocale) => {
|
|
1986
2837
|
const href = toHref(sitePath, linkLocale);
|
|
1987
2838
|
return origin ? absoluteUrl(origin, href) : href;
|
|
1988
2839
|
};
|
|
2840
|
+
const withTypes = async (alternates, markdown) => {
|
|
2841
|
+
const feed = hyleFeedLink(options, locale);
|
|
2842
|
+
const types = {
|
|
2843
|
+
...parent ? (await parent).alternates?.types : void 0,
|
|
2844
|
+
...feed ? { "application/rss+xml": [feed] } : {},
|
|
2845
|
+
...markdown ? { "text/markdown": [{ url: markdown }] } : {}
|
|
2846
|
+
};
|
|
2847
|
+
return Object.keys(types).length ? { ...alternates, types } : alternates;
|
|
2848
|
+
};
|
|
1989
2849
|
try {
|
|
1990
2850
|
const cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
1991
2851
|
const result = await resolve(path, locale, options.listLimit, cursor, options.layout === "docs" ? "tree" : void 0);
|
|
2852
|
+
const parentMeta = parent ? await parent : void 0;
|
|
2853
|
+
const parentImages = parentMeta?.openGraph?.images;
|
|
1992
2854
|
if (result.kind === "list") {
|
|
1993
2855
|
const title = (options.list?.title || result.section.title) + (cursor ? ` - ${stringsFor(locale).older}` : "");
|
|
1994
2856
|
const description2 = options.list?.description;
|
|
2857
|
+
const ogLocale = locale && options.ogLocale?.(locale) || locale;
|
|
2858
|
+
const canonical2 = link(path) + (cursor ? `?cursor=${cursor}` : "");
|
|
1995
2859
|
return {
|
|
1996
2860
|
title: titled(options.titleTemplate, title),
|
|
1997
2861
|
...description2 ? { description: description2 } : {},
|
|
1998
|
-
alternates: { canonical:
|
|
1999
|
-
openGraph: {
|
|
2862
|
+
alternates: await withTypes({ canonical: canonical2 }),
|
|
2863
|
+
openGraph: {
|
|
2864
|
+
type: "website",
|
|
2865
|
+
title,
|
|
2866
|
+
...description2 ? { description: description2 } : {},
|
|
2867
|
+
url: canonical2,
|
|
2868
|
+
...options.siteName ? { siteName: options.siteName } : {},
|
|
2869
|
+
...ogLocale ? { locale: ogLocale } : {},
|
|
2870
|
+
...parentImages?.length ? { images: parentImages } : {}
|
|
2871
|
+
}
|
|
2000
2872
|
};
|
|
2001
2873
|
}
|
|
2002
2874
|
if (result.kind !== "article") return {};
|
|
@@ -2005,16 +2877,24 @@ function hyleMetadata(options) {
|
|
|
2005
2877
|
const description = pub.description ?? void 0;
|
|
2006
2878
|
const author = articleAuthor(result, options.jsonLd)?.name;
|
|
2007
2879
|
const modified = modifiedAt(pub);
|
|
2008
|
-
const image =
|
|
2880
|
+
const image = articleImage(options, result);
|
|
2009
2881
|
const alternateLocale = options.ogLocale ? alternates.filter((a) => a.locale !== pub.locale).flatMap((a) => options.ogLocale?.(a.locale) ?? []) : [];
|
|
2010
2882
|
const { twitter } = options;
|
|
2883
|
+
const inherited = parentMeta?.robots;
|
|
2884
|
+
const section = result.breadcrumbs[0]?.title;
|
|
2885
|
+
const words = wordCountOf(pub);
|
|
2011
2886
|
return {
|
|
2012
2887
|
title: titled(options.titleTemplate, pub.title),
|
|
2013
2888
|
...description ? { description } : {},
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2889
|
+
// Next replaces a parent's robots per key, so keep the inherited directives (a host's noindex) and add ours once.
|
|
2890
|
+
robots: composeRobots(inherited),
|
|
2891
|
+
alternates: await withTypes(
|
|
2892
|
+
{
|
|
2893
|
+
canonical,
|
|
2894
|
+
...alternates.length > 1 ? { languages: hreflangLanguages(alternates, default_locale, canonical, (a) => link(a.canonical_path, a.locale)) } : {}
|
|
2895
|
+
},
|
|
2896
|
+
options.markdownTwin ? `${canonical}.md` : void 0
|
|
2897
|
+
),
|
|
2018
2898
|
openGraph: {
|
|
2019
2899
|
type: "article",
|
|
2020
2900
|
title: pub.title,
|
|
@@ -2025,9 +2905,12 @@ function hyleMetadata(options) {
|
|
|
2025
2905
|
...alternateLocale.length ? { alternateLocale } : {},
|
|
2026
2906
|
publishedTime: pub.published_at,
|
|
2027
2907
|
...modified ? { modifiedTime: modified } : {},
|
|
2908
|
+
...section ? { section } : {},
|
|
2028
2909
|
...author ? { authors: [author] } : {},
|
|
2029
|
-
...image ? { images: [image] } : {}
|
|
2910
|
+
...image ? { images: [image] } : parentImages?.length ? { images: parentImages } : {}
|
|
2030
2911
|
},
|
|
2912
|
+
// Next replaces a parent's `other` whole, so the inherited keys are carried over.
|
|
2913
|
+
...words ? { other: { ...parentMeta?.other, "twitter:label1": stringsFor(locale).readingTimeLabel, "twitter:data1": stringsFor(locale).readingTime.replace("{n}", String(readingMinutes(words))) } } : {},
|
|
2031
2914
|
...image ? {
|
|
2032
2915
|
twitter: {
|
|
2033
2916
|
card: "summary_large_image",
|
|
@@ -2038,729 +2921,419 @@ function hyleMetadata(options) {
|
|
|
2038
2921
|
images: [image]
|
|
2039
2922
|
}
|
|
2040
2923
|
} : {}
|
|
2041
|
-
};
|
|
2042
|
-
} catch (error) {
|
|
2043
|
-
if (isRejectedRequest(error)) return {};
|
|
2044
|
-
throw error;
|
|
2045
|
-
}
|
|
2046
|
-
};
|
|
2047
|
-
}
|
|
2048
|
-
|
|
2049
|
-
// src/next/feed.ts
|
|
2050
|
-
var import_navigation3 = require("next/navigation");
|
|
2051
|
-
var xml = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
2052
|
-
var tag = (name, value) => `<${name}>${xml(value)}</${name}>`;
|
|
2053
|
-
var response = (body, status, headers) => new Response(body, { status, ...headers ? { headers } : {} });
|
|
2054
|
-
async function hyleFeed(options) {
|
|
2055
|
-
const origin = options.siteOrigin;
|
|
2056
|
-
if (!origin || !BARE_HTTPS_ORIGIN.test(origin)) {
|
|
2057
|
-
console.error("hyle: hyleFeed needs `siteOrigin`, a bare https origin such as https://example.com");
|
|
2058
|
-
return response(null, 404);
|
|
2059
|
-
}
|
|
2060
|
-
const { path, locale, toHref } = routeContext(options, {});
|
|
2061
|
-
if (path === void 0) return response(null, 404);
|
|
2062
|
-
const url = (sitePath) => origin + encodeURI(toHref(sitePath));
|
|
2063
|
-
try {
|
|
2064
|
-
const result = await resolverFor(options)(path, locale, options.limit ?? 50);
|
|
2065
|
-
if (result.kind !== "list") return response(null, 503);
|
|
2066
|
-
const items = result.items.filter((item) => item.canonical_path.startsWith("/")).map((item) => {
|
|
2067
|
-
const link = url(item.canonical_path);
|
|
2068
|
-
const published = new Date(item.published_at);
|
|
2069
|
-
return `<item>${tag("title", item.title)}${tag("link", link)}<guid isPermaLink="true">${xml(link)}</guid>${Number.isNaN(published.getTime()) ? "" : tag("pubDate", published.toUTCString())}${item.description ? tag("description", item.description) : ""}</item>`;
|
|
2070
|
-
});
|
|
2071
|
-
const channel = [
|
|
2072
|
-
tag("title", options.list?.title || result.section.title),
|
|
2073
|
-
tag("link", url(path)),
|
|
2074
|
-
tag("description", options.list?.description ?? ""),
|
|
2075
|
-
locale ? tag("language", locale) : "",
|
|
2076
|
-
`<atom:link href="${xml(origin + encodeURI(options.feedPath ?? "/feed.xml"))}" rel="self" type="application/rss+xml"/>`,
|
|
2077
|
-
...items
|
|
2078
|
-
].join("");
|
|
2079
|
-
return response(
|
|
2080
|
-
`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel>${channel}</channel></rss>`,
|
|
2081
|
-
200,
|
|
2082
|
-
{ "content-type": "application/rss+xml; charset=utf-8" }
|
|
2083
|
-
);
|
|
2084
|
-
} catch (error) {
|
|
2085
|
-
(0, import_navigation3.unstable_rethrow)(error);
|
|
2086
|
-
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2087
|
-
return response(null, 503);
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
|
-
// src/next/revalidate.ts
|
|
2092
|
-
var import_cache = require("next/cache");
|
|
2093
|
-
var isSwitchedOff = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
2094
|
-
function createRevalidateRoute(options) {
|
|
2095
|
-
let cached;
|
|
2096
|
-
return {
|
|
2097
|
-
async POST(req) {
|
|
2098
|
-
if (isSwitchedOff((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return new Response(null, { status: 404 });
|
|
2099
|
-
const workspaceId = options.workspaceId?.trim();
|
|
2100
|
-
const secrets = options.secrets.map((s) => s?.trim()).filter((s) => Boolean(s));
|
|
2101
|
-
if (!workspaceId && secrets.length === 0) return new Response(null, { status: 404 });
|
|
2102
|
-
if (!workspaceId || secrets.length === 0) return new Response(null, { status: 503 });
|
|
2103
|
-
const key = `${workspaceId}\0${secrets.join("\0")}`;
|
|
2104
|
-
if (cached?.key !== key) {
|
|
2105
|
-
cached = { key, route: createRevalidationCallbackRoute({ workspaceId, secrets, revalidateTag: (tag2) => (0, import_cache.revalidateTag)(tag2, { expire: 0 }) }) };
|
|
2106
|
-
}
|
|
2107
|
-
return cached.route.POST(req);
|
|
2108
|
-
}
|
|
2109
|
-
};
|
|
2110
|
-
}
|
|
2111
|
-
|
|
2112
|
-
// src/next/root.ts
|
|
2113
|
-
var import_navigation4 = require("next/navigation");
|
|
2114
|
-
|
|
2115
|
-
// src/next/mount-match.ts
|
|
2116
|
-
function activeMounts(mounts) {
|
|
2117
|
-
const out = [];
|
|
2118
|
-
for (const { prefix, default_section, name, locales } of mounts) {
|
|
2119
|
-
try {
|
|
2120
|
-
const normalized = normalizeBasePath(prefix);
|
|
2121
|
-
out.push({
|
|
2122
|
-
prefix: normalized,
|
|
2123
|
-
defaultSection: default_section,
|
|
2124
|
-
depth: normalized === "" ? 0 : normalized.split("/").length - 1,
|
|
2125
|
-
...name ? { name } : {},
|
|
2126
|
-
...locales ? { locales } : {}
|
|
2127
|
-
});
|
|
2128
|
-
} catch (error) {
|
|
2129
|
-
console.error(`hyle: ignoring a mount with an invalid prefix (${error instanceof Error ? error.name : "Error"})`);
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
return out;
|
|
2133
|
-
}
|
|
2134
|
-
var prefixMatches = (prefix, path) => prefix === "" || path === prefix || path.startsWith(`${prefix}/`);
|
|
2135
|
-
function isReserved(path, reserved) {
|
|
2136
|
-
return reserved.some((entry) => entry.endsWith("/*") ? prefixMatches(entry.slice(0, -2), path) : entry === path);
|
|
2137
|
-
}
|
|
2138
|
-
|
|
2139
|
-
// src/next/root.ts
|
|
2140
|
-
var MOUNTS_MAX_STALE_MS = 15 * 60 * 1e3;
|
|
2141
|
-
var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
2142
|
-
var NONE = { mounts: [], reserved: [], defaultLocale: "" };
|
|
2143
|
-
var lastKnownGood = /* @__PURE__ */ new Map();
|
|
2144
|
-
function mountsLoader(config) {
|
|
2145
|
-
if (!config.workspaceId) throw new TypeError("hyleRootPage: `workspaceId` is required for the fetch cache");
|
|
2146
|
-
const client = createHyleClient({ baseUrl: config.baseUrl, token: config.token });
|
|
2147
|
-
const init = { next: { revalidate: config.revalidate ?? DEFAULT_REVALIDATE, tags: workspaceTags(config.workspaceId).slice(0, 1) } };
|
|
2148
|
-
const key = `${new URL(config.baseUrl).origin}|${config.workspaceId}`;
|
|
2149
|
-
return async function load() {
|
|
2150
|
-
try {
|
|
2151
|
-
const result = await client.mounts({ init });
|
|
2152
|
-
if (result.kind !== "mounts") {
|
|
2153
|
-
lastKnownGood.delete(key);
|
|
2154
|
-
return NONE;
|
|
2155
|
-
}
|
|
2156
|
-
const loaded = { mounts: activeMounts(result.mounts), reserved: result.reserved, defaultLocale: result.default_locale };
|
|
2157
|
-
lastKnownGood.set(key, { loaded, at: Date.now() });
|
|
2158
|
-
return loaded;
|
|
2159
|
-
} catch (error) {
|
|
2160
|
-
if (isRejectedRequest(error)) {
|
|
2161
|
-
lastKnownGood.delete(key);
|
|
2162
|
-
return NONE;
|
|
2163
|
-
}
|
|
2164
|
-
if (error instanceof Cp1ClientError && (error.status === 401 || error.status === 403)) {
|
|
2165
|
-
lastKnownGood.delete(key);
|
|
2166
|
-
throw error;
|
|
2167
|
-
}
|
|
2168
|
-
const kept = lastKnownGood.get(key);
|
|
2169
|
-
if (kept && Date.now() - kept.at <= MOUNTS_MAX_STALE_MS) return kept.loaded;
|
|
2170
|
-
throw error;
|
|
2171
|
-
}
|
|
2172
|
-
};
|
|
2173
|
-
}
|
|
2174
|
-
var asArray = (options) => Array.isArray(options) ? options : [options];
|
|
2175
|
-
function setup(options) {
|
|
2176
|
-
const configs = asArray(options);
|
|
2177
|
-
if (configs.length === 0) throw new TypeError("hyleRootPage: pass at least one workspace config");
|
|
2178
|
-
const param = configs[0].param ?? "hyle";
|
|
2179
|
-
if (configs.some((c) => (c.param ?? "hyle") !== param)) throw new TypeError("hyleRootPage: every config must use the same `param`");
|
|
2180
|
-
return { configs, param, loaders: configs.map(mountsLoader) };
|
|
2181
|
-
}
|
|
2182
|
-
var sectionsOf = (config, mount) => [
|
|
2183
|
-
...config.sections ?? [],
|
|
2184
|
-
...SECTION_SLUG.test(mount.defaultSection) ? [mount.defaultSection] : []
|
|
2185
|
-
];
|
|
2186
|
-
function mountOptionsOf(config, mount) {
|
|
2187
|
-
const { mountOptions, ...rest } = config;
|
|
2188
|
-
return { ...rest, ...mountOptions?.[mount.prefix === "" ? "/" : mount.prefix], basePath: mount.prefix, sections: sectionsOf(config, mount) };
|
|
2189
|
-
}
|
|
2190
|
-
function rootMounts(options) {
|
|
2191
|
-
const { configs, param, loaders } = setup(options);
|
|
2192
|
-
return {
|
|
2193
|
-
param,
|
|
2194
|
-
async locate(path) {
|
|
2195
|
-
const loaded = await Promise.all(loaders.map((load) => load()));
|
|
2196
|
-
let best;
|
|
2197
|
-
loaded.forEach(({ mounts, reserved }, index2) => {
|
|
2198
|
-
if (isReserved(path, reserved)) return;
|
|
2199
|
-
for (const mount2 of mounts) if (prefixMatches(mount2.prefix, path) && (!best || mount2.depth > best.mount.depth)) best = { index: index2, mount: mount2 };
|
|
2200
|
-
});
|
|
2201
|
-
if (!best) return void 0;
|
|
2202
|
-
const { index, mount } = best;
|
|
2203
|
-
return { options: mountOptionsOf(configs[index], mount), mount, index };
|
|
2204
|
-
},
|
|
2205
|
-
async all() {
|
|
2206
|
-
const out = [];
|
|
2207
|
-
for (const [index, load] of loaders.entries()) {
|
|
2208
|
-
const { mounts, defaultLocale } = await load();
|
|
2209
|
-
for (const mount of mounts) out.push({ options: mountOptionsOf(configs[index], mount), mount, index, defaultLocale });
|
|
2210
|
-
}
|
|
2211
|
-
return out;
|
|
2212
|
-
}
|
|
2213
|
-
};
|
|
2214
|
-
}
|
|
2215
|
-
function createRouter(options, make) {
|
|
2216
|
-
const mounts = rootMounts(options);
|
|
2217
|
-
const handlers = /* @__PURE__ */ new Map();
|
|
2218
|
-
return async function route(params) {
|
|
2219
|
-
const raw = params[mounts.param];
|
|
2220
|
-
const segments = typeof raw === "string" ? [raw] : raw;
|
|
2221
|
-
const path = sitePathFrom("", segments);
|
|
2222
|
-
if (path === void 0 || path === "/" || !segments) return void 0;
|
|
2223
|
-
const hit = await mounts.locate(path);
|
|
2224
|
-
if (!hit) return void 0;
|
|
2225
|
-
const { mount, index } = hit;
|
|
2226
|
-
const id = `${index}|${mount.prefix}|${mount.defaultSection}`;
|
|
2227
|
-
let handler = handlers.get(id);
|
|
2228
|
-
if (!handler) {
|
|
2229
|
-
handler = make(hit.options);
|
|
2230
|
-
handlers.set(id, handler);
|
|
2231
|
-
}
|
|
2232
|
-
return { handler, params: { ...params, [mounts.param]: segments.slice(mount.depth) } };
|
|
2233
|
-
};
|
|
2234
|
-
}
|
|
2235
|
-
function hyleRootPage(options) {
|
|
2236
|
-
const route = createRouter(options, hylePage);
|
|
2237
|
-
return async function HyleRootPage({ params, searchParams }) {
|
|
2238
|
-
const hit = await route(await params ?? {});
|
|
2239
|
-
if (!hit) (0, import_navigation4.notFound)();
|
|
2240
|
-
return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
|
|
2241
|
-
};
|
|
2242
|
-
}
|
|
2243
|
-
function hyleRootMetadata(options) {
|
|
2244
|
-
const route = createRouter(options, hyleMetadata);
|
|
2245
|
-
return async function generateMetadata({ params }) {
|
|
2246
|
-
const hit = await route(await params ?? {});
|
|
2247
|
-
return hit ? hit.handler({ params: Promise.resolve(hit.params) }) : {};
|
|
2924
|
+
};
|
|
2925
|
+
} catch (error) {
|
|
2926
|
+
if (isRejectedRequest(error)) return {};
|
|
2927
|
+
throw error;
|
|
2928
|
+
}
|
|
2248
2929
|
};
|
|
2249
2930
|
}
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2931
|
+
|
|
2932
|
+
// src/next/feed.ts
|
|
2933
|
+
var import_navigation4 = require("next/navigation");
|
|
2934
|
+
var xml = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
2935
|
+
var tag = (name, value) => `<${name}>${xml(value)}</${name}>`;
|
|
2936
|
+
var response = (body, status, headers) => new Response(body, { status, ...headers ? { headers } : {} });
|
|
2937
|
+
async function hyleFeed(options) {
|
|
2938
|
+
const origin = options.siteOrigin;
|
|
2939
|
+
if (!origin || !BARE_HTTPS_ORIGIN.test(origin)) {
|
|
2940
|
+
console.error("hyle: hyleFeed needs `siteOrigin`, a bare https origin such as https://example.com");
|
|
2941
|
+
return response(null, 404);
|
|
2942
|
+
}
|
|
2943
|
+
const { path, locale, toHref } = routeContext(options, {});
|
|
2944
|
+
if (path === void 0) return response(null, 404);
|
|
2945
|
+
const url = (sitePath) => origin + encodeURI(toHref(sitePath));
|
|
2946
|
+
try {
|
|
2947
|
+
const result = await resolverFor(options)(path, locale, options.limit ?? 50);
|
|
2948
|
+
if (result.kind !== "list") return response(null, 503);
|
|
2949
|
+
const items = result.items.filter((item) => item.canonical_path.startsWith("/")).map((item) => {
|
|
2950
|
+
const link = url(item.canonical_path);
|
|
2951
|
+
const published = new Date(item.published_at);
|
|
2952
|
+
return `<item>${tag("title", item.title)}${tag("link", link)}<guid isPermaLink="true">${xml(link)}</guid>${Number.isNaN(published.getTime()) ? "" : tag("pubDate", published.toUTCString())}${item.description ? tag("description", item.description) : ""}</item>`;
|
|
2953
|
+
});
|
|
2954
|
+
const channel = [
|
|
2955
|
+
tag("title", options.list?.title || result.section.title),
|
|
2956
|
+
tag("link", url(path)),
|
|
2957
|
+
tag("description", options.list?.description ?? ""),
|
|
2958
|
+
locale ? tag("language", locale) : "",
|
|
2959
|
+
`<atom:link href="${xml(origin + encodeURI(options.feedPath ?? "/feed.xml"))}" rel="self" type="application/rss+xml"/>`,
|
|
2960
|
+
...items
|
|
2961
|
+
].join("");
|
|
2962
|
+
return response(
|
|
2963
|
+
`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel>${channel}</channel></rss>`,
|
|
2964
|
+
200,
|
|
2965
|
+
{ "content-type": "application/rss+xml; charset=utf-8" }
|
|
2966
|
+
);
|
|
2967
|
+
} catch (error) {
|
|
2968
|
+
(0, import_navigation4.unstable_rethrow)(error);
|
|
2969
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2970
|
+
return response(null, 503);
|
|
2256
2971
|
}
|
|
2257
|
-
return [...entries.values()];
|
|
2258
2972
|
}
|
|
2259
2973
|
|
|
2260
|
-
// src/next/
|
|
2261
|
-
var
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
}
|
|
2266
|
-
var reply = (body, status, headers = {}) => (
|
|
2267
|
-
// noindex on every answer: the .md twin must never compete with the page it mirrors.
|
|
2268
|
-
new Response(body, { status, headers: { "X-Robots-Tag": "noindex", ...headers } })
|
|
2269
|
-
);
|
|
2270
|
-
function createMarkdownRoute(options) {
|
|
2271
|
-
const mounts = rootMounts(options);
|
|
2974
|
+
// src/next/revalidate.ts
|
|
2975
|
+
var import_cache = require("next/cache");
|
|
2976
|
+
var isSwitchedOff2 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
2977
|
+
function createRevalidateRoute(options) {
|
|
2978
|
+
let cached;
|
|
2272
2979
|
return {
|
|
2273
|
-
async
|
|
2274
|
-
|
|
2275
|
-
const
|
|
2276
|
-
const
|
|
2277
|
-
if (
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
const result = await resolverFor(hit.options)(path, locale, void 0, void 0, void 0, "md");
|
|
2283
|
-
if (result.kind === "article" && result.content.format === "md") {
|
|
2284
|
-
const markdown = result.content.markdown.replaceAll("](/assets/", `](${ASSET_ROUTE_PREFIX}/`);
|
|
2285
|
-
return reply(markdown, 200, { "Content-Type": "text/markdown; charset=utf-8" });
|
|
2286
|
-
}
|
|
2287
|
-
if (result.kind === "redirect") {
|
|
2288
|
-
const to = safeRedirectTarget(result.to);
|
|
2289
|
-
const target = to === void 0 ? void 0 : safeRedirectTarget(toHref(to));
|
|
2290
|
-
if (target === void 0) return reply(null, 502);
|
|
2291
|
-
return target === toHref(path) ? reply(null, 404) : reply(null, result.status === 301 ? 308 : 307, { Location: `${target}.md` });
|
|
2292
|
-
}
|
|
2293
|
-
return reply(null, 404);
|
|
2294
|
-
} catch (error) {
|
|
2295
|
-
if (isRejectedRequest(error)) return reply(null, 404);
|
|
2296
|
-
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2297
|
-
return reply(null, 502);
|
|
2980
|
+
async POST(req) {
|
|
2981
|
+
if (isSwitchedOff2((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return new Response(null, { status: 404 });
|
|
2982
|
+
const workspaceId = options.workspaceId?.trim();
|
|
2983
|
+
const secrets = options.secrets.map((s) => s?.trim()).filter((s) => Boolean(s));
|
|
2984
|
+
if (!workspaceId && secrets.length === 0) return new Response(null, { status: 404 });
|
|
2985
|
+
if (!workspaceId || secrets.length === 0) return new Response(null, { status: 503 });
|
|
2986
|
+
const key = `${workspaceId}\0${secrets.join("\0")}`;
|
|
2987
|
+
if (cached?.key !== key) {
|
|
2988
|
+
cached = { key, route: createRevalidationCallbackRoute({ workspaceId, secrets, revalidateTag: (tag2) => (0, import_cache.revalidateTag)(tag2, { expire: 0 }), onCommentEvent: options.onCommentEvent }) };
|
|
2298
2989
|
}
|
|
2990
|
+
return cached.route.POST(req);
|
|
2299
2991
|
}
|
|
2300
2992
|
};
|
|
2301
2993
|
}
|
|
2302
2994
|
|
|
2303
|
-
// src/next/
|
|
2995
|
+
// src/next/root.ts
|
|
2304
2996
|
var import_navigation5 = require("next/navigation");
|
|
2305
|
-
var oneLine = (text) => text.replace(/\s+/g, " ").trim();
|
|
2306
|
-
var linkTarget = (url) => url.replace(/[()]/g, (c) => c === "(" ? "%28" : "%29");
|
|
2307
|
-
function createLlmsTxtRoute(options, llms) {
|
|
2308
|
-
const origin = bareOrigin(llms.origin);
|
|
2309
|
-
if (!origin) throw new TypeError("createLlmsTxtRoute: `origin` must be a bare https origin such as https://example.com");
|
|
2310
|
-
const mounts = rootMounts(options);
|
|
2311
|
-
return {
|
|
2312
|
-
async GET() {
|
|
2313
|
-
try {
|
|
2314
|
-
const lines = [`# ${oneLine(llms.title ?? new URL(origin).host)}`, ...llms.description ? ["", `> ${oneLine(llms.description)}`] : []];
|
|
2315
|
-
for (const { options: mountOptions, mount, defaultLocale } of await mounts.all()) {
|
|
2316
|
-
if (mount.locales && !mount.locales.includes(defaultLocale)) continue;
|
|
2317
|
-
const { basePath, toHref } = routeContext({ ...mountOptions, locale: () => defaultLocale }, {});
|
|
2318
|
-
const resolve = resolverFor(mountOptions);
|
|
2319
|
-
const client = { resolve: ({ path, locale, limit, cursor }) => resolve(path, locale, limit, cursor) };
|
|
2320
|
-
const { paths } = await listPublicationPaths({ client, basePath, locale: defaultLocale });
|
|
2321
|
-
lines.push("", `## ${oneLine(mount.name ?? mount.defaultSection)}`, "");
|
|
2322
|
-
for (const { path, title, description } of paths) {
|
|
2323
|
-
lines.push(`- [${oneLine(title).replace(/[[\]]/g, "")}](${linkTarget(absoluteUrl(origin, toHref(path)))}.md)${description ? `: ${oneLine(description)}` : ""}`);
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
return new Response(`${lines.join("\n")}
|
|
2327
|
-
`, { headers: { "Content-Type": "text/plain; charset=utf-8" } });
|
|
2328
|
-
} catch (error) {
|
|
2329
|
-
(0, import_navigation5.unstable_rethrow)(error);
|
|
2330
|
-
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2331
|
-
return new Response(null, { status: 503 });
|
|
2332
|
-
}
|
|
2333
|
-
}
|
|
2334
|
-
};
|
|
2335
|
-
}
|
|
2336
2997
|
|
|
2337
|
-
// src/next/
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
var PARTIAL_CACHE_CONTROL = "no-store";
|
|
2342
|
-
var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
|
|
2343
|
-
var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
|
|
2344
|
-
var isSwitchedOff2 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
2345
|
-
function capped(body, max) {
|
|
2346
|
-
let seen = 0;
|
|
2347
|
-
return body.pipeThrough(
|
|
2348
|
-
new TransformStream({
|
|
2349
|
-
transform(chunk, controller) {
|
|
2350
|
-
seen += chunk.byteLength;
|
|
2351
|
-
if (seen > max) return controller.error(new Error("asset too large"));
|
|
2352
|
-
controller.enqueue(chunk);
|
|
2353
|
-
}
|
|
2354
|
-
})
|
|
2355
|
-
);
|
|
2356
|
-
}
|
|
2357
|
-
function createAssetRoute(options) {
|
|
2358
|
-
let client;
|
|
2359
|
-
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
2360
|
-
async function serve(req, ctx2, head) {
|
|
2361
|
-
if (isSwitchedOff2((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
|
|
2362
|
-
const file = (await ctx2.params).file;
|
|
2363
|
-
if (typeof file !== "string" || !ASSET_FILE.test(file)) return empty(404);
|
|
2364
|
-
try {
|
|
2365
|
-
client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
|
|
2366
|
-
} catch {
|
|
2367
|
-
return empty(404);
|
|
2368
|
-
}
|
|
2369
|
-
let upstream;
|
|
2998
|
+
// src/next/mount-match.ts
|
|
2999
|
+
function activeMounts(mounts) {
|
|
3000
|
+
const out = [];
|
|
3001
|
+
for (const { prefix, default_section, name, locales } of mounts) {
|
|
2370
3002
|
try {
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
3003
|
+
const normalized = normalizeBasePath(prefix);
|
|
3004
|
+
out.push({
|
|
3005
|
+
prefix: normalized,
|
|
3006
|
+
defaultSection: default_section,
|
|
3007
|
+
depth: normalized === "" ? 0 : normalized.split("/").length - 1,
|
|
3008
|
+
...name ? { name } : {},
|
|
3009
|
+
...locales ? { locales } : {}
|
|
2374
3010
|
});
|
|
2375
|
-
} catch {
|
|
2376
|
-
|
|
2377
|
-
}
|
|
2378
|
-
const drop = () => void upstream.body?.cancel().catch(() => {
|
|
2379
|
-
});
|
|
2380
|
-
const etag = upstream.headers.get("etag");
|
|
2381
|
-
if (upstream.status === 304) {
|
|
2382
|
-
drop();
|
|
2383
|
-
return new Response(null, { status: 304, headers: { "Cache-Control": CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS, ...etag ? { ETag: etag } : {} } });
|
|
2384
|
-
}
|
|
2385
|
-
if (upstream.status === 404 || upstream.status === 416) {
|
|
2386
|
-
drop();
|
|
2387
|
-
const range = upstream.status === 416 ? upstream.headers.get("content-range") : null;
|
|
2388
|
-
return empty(upstream.status, range ? { "Content-Range": range } : {});
|
|
2389
|
-
}
|
|
2390
|
-
const type = upstream.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase();
|
|
2391
|
-
const length = Number(upstream.headers.get("content-length"));
|
|
2392
|
-
const expectedStatus = upstream.status === 200 || upstream.status === 206;
|
|
2393
|
-
if (!expectedStatus || !upstream.body || !type || !ASSET_CONTENT_TYPES.has(type) || Number.isFinite(length) && length > maxBytes) {
|
|
2394
|
-
drop();
|
|
2395
|
-
return empty(502);
|
|
2396
|
-
}
|
|
2397
|
-
const headers = new Headers({ "Content-Type": type, "Accept-Ranges": "bytes", "Cache-Control": upstream.status === 206 ? PARTIAL_CACHE_CONTROL : CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS });
|
|
2398
|
-
if (etag) headers.set("ETag", etag);
|
|
2399
|
-
const contentRange = upstream.headers.get("content-range");
|
|
2400
|
-
if (upstream.status === 206 && contentRange) headers.set("Content-Range", contentRange);
|
|
2401
|
-
if (!upstream.headers.get("content-encoding") && upstream.headers.get("content-length")) headers.set("Content-Length", String(length));
|
|
2402
|
-
if (head) {
|
|
2403
|
-
drop();
|
|
2404
|
-
return new Response(null, { status: upstream.status, headers });
|
|
3011
|
+
} catch (error) {
|
|
3012
|
+
console.error(`hyle: ignoring a mount with an invalid prefix (${error instanceof Error ? error.name : "Error"})`);
|
|
2405
3013
|
}
|
|
2406
|
-
return new Response(capped(upstream.body, maxBytes), { status: upstream.status, headers });
|
|
2407
3014
|
}
|
|
2408
|
-
return
|
|
3015
|
+
return out;
|
|
2409
3016
|
}
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
// src/next/engage.ts
|
|
2415
|
-
var ENGAGE_CSRF_HEADER = "x-hyle-engage";
|
|
2416
|
-
var DEFAULT_TIMEOUT_MS3 = 1e4;
|
|
2417
|
-
var DEFAULT_SHARE_MS = 3e3;
|
|
2418
|
-
var MAX_SHARED = 100;
|
|
2419
|
-
var MAX_SHARED_BYTES = 8 * 1024 * 1024;
|
|
2420
|
-
var MAX_SHARED_ENTRY_BYTES = 256 * 1024;
|
|
2421
|
-
var MAX_BODY_BYTES2 = 20 * 1024;
|
|
2422
|
-
var MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
2423
|
-
var MAX_COMMENT_CHARACTERS = 4e3;
|
|
2424
|
-
var MAX_PATH_LENGTH2 = 1024;
|
|
2425
|
-
var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
2426
|
-
var CONTROL = /[\u0000-\u001f\u007f\\]/;
|
|
2427
|
-
var HEADERS = { "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" };
|
|
2428
|
-
var isSwitchedOff3 = (value) => {
|
|
2429
|
-
const v = value?.trim().toLowerCase() ?? "";
|
|
2430
|
-
return v !== "" && v !== "1" && v !== "true";
|
|
2431
|
-
};
|
|
2432
|
-
var json = (status, body, extra = {}) => new Response(JSON.stringify(body), { status, headers: { ...HEADERS, "Content-Type": "application/json; charset=utf-8", ...extra } });
|
|
2433
|
-
var refuse = (status, code, extra = {}) => json(status, { error: { code } }, extra);
|
|
2434
|
-
function isSitePath2(value) {
|
|
2435
|
-
if (typeof value !== "string" || value.length > MAX_PATH_LENGTH2 || !value.startsWith("/") || value.startsWith("//")) return false;
|
|
2436
|
-
if (CONTROL.test(value) || /[?#]/.test(value)) return false;
|
|
2437
|
-
return !value.split("/").some((segment) => segment === "." || segment === "..");
|
|
3017
|
+
var prefixMatches = (prefix, path) => prefix === "" || path === prefix || path.startsWith(`${prefix}/`);
|
|
3018
|
+
function isReserved(path, reserved) {
|
|
3019
|
+
return reserved.some((entry) => entry.endsWith("/*") ? prefixMatches(entry.slice(0, -2), path) : entry === path);
|
|
2438
3020
|
}
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
return { upstream: "/comments", body: clean2 };
|
|
3021
|
+
|
|
3022
|
+
// src/next/root.ts
|
|
3023
|
+
var MOUNTS_MAX_STALE_MS = 15 * 60 * 1e3;
|
|
3024
|
+
var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
3025
|
+
var NONE = { mounts: [], reserved: [], defaultLocale: "" };
|
|
3026
|
+
var lastKnownGood = /* @__PURE__ */ new Map();
|
|
3027
|
+
function mountsLoader(config) {
|
|
3028
|
+
if (!config.workspaceId) throw new TypeError("hyleRootPage: `workspaceId` is required for the fetch cache");
|
|
3029
|
+
const client = createHyleClient({ baseUrl: config.baseUrl, token: config.token });
|
|
3030
|
+
const init = { next: { revalidate: config.revalidate ?? DEFAULT_REVALIDATE, tags: workspaceTags(config.workspaceId).slice(0, 1) } };
|
|
3031
|
+
const key = `${new URL(config.baseUrl).origin}|${config.workspaceId}`;
|
|
3032
|
+
return async function load() {
|
|
3033
|
+
try {
|
|
3034
|
+
const result = await client.mounts({ init });
|
|
3035
|
+
if (result.kind !== "mounts") {
|
|
3036
|
+
lastKnownGood.delete(key);
|
|
3037
|
+
return NONE;
|
|
2457
3038
|
}
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
if (method === "DELETE") return body === void 0 ? { upstream: `/comments/${b}` } : void 0;
|
|
2466
|
-
const clean2 = pick(body, ["body"], ["body"]);
|
|
2467
|
-
return clean2 && isCommentText(clean2.body) ? { upstream: `/comments/${b}`, body: clean2 } : void 0;
|
|
3039
|
+
const loaded = { mounts: activeMounts(result.mounts), reserved: result.reserved, defaultLocale: result.default_locale };
|
|
3040
|
+
lastKnownGood.set(key, { loaded, at: Date.now() });
|
|
3041
|
+
return loaded;
|
|
3042
|
+
} catch (error) {
|
|
3043
|
+
if (isRejectedRequest(error)) {
|
|
3044
|
+
lastKnownGood.delete(key);
|
|
3045
|
+
return NONE;
|
|
2468
3046
|
}
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
return {
|
|
2473
|
-
action: (m) => m === "PUT" ? "reactions.add" : "reactions.remove",
|
|
2474
|
-
methods: ["PUT", "DELETE"],
|
|
2475
|
-
rebuild: (_method, body) => {
|
|
2476
|
-
const type = body?.subject_type;
|
|
2477
|
-
const clean2 = type === "article" ? pick(body, ["subject_type", "path"], ["subject_type", "path"]) : type === "comment" ? pick(body, ["subject_type", "comment_id"], ["subject_type", "comment_id"]) : void 0;
|
|
2478
|
-
if (!clean2) return void 0;
|
|
2479
|
-
const valid = type === "article" ? isSitePath2(clean2.path) : typeof clean2.comment_id === "string" && UUID2.test(clean2.comment_id);
|
|
2480
|
-
return valid ? { upstream: "/reactions", body: clean2 } : void 0;
|
|
3047
|
+
if (error instanceof Cp1ClientError && (error.status === 401 || error.status === 403)) {
|
|
3048
|
+
lastKnownGood.delete(key);
|
|
3049
|
+
throw error;
|
|
2481
3050
|
}
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
}
|
|
2486
|
-
|
|
2487
|
-
if (!body || Object.keys(body).some((k) => !allowed.includes(k)) || !required.every((k) => k in body)) return void 0;
|
|
2488
|
-
return Object.fromEntries(allowed.filter((k) => k in body).map((k) => [k, body[k]]));
|
|
3051
|
+
const kept = lastKnownGood.get(key);
|
|
3052
|
+
if (kept && Date.now() - kept.at <= MOUNTS_MAX_STALE_MS) return kept.loaded;
|
|
3053
|
+
throw error;
|
|
3054
|
+
}
|
|
3055
|
+
};
|
|
2489
3056
|
}
|
|
2490
|
-
|
|
2491
|
-
|
|
3057
|
+
var asArray = (options) => Array.isArray(options) ? options : [options];
|
|
3058
|
+
function setup(options) {
|
|
3059
|
+
const configs = asArray(options);
|
|
3060
|
+
if (configs.length === 0) throw new TypeError("hyleRootPage: pass at least one workspace config");
|
|
3061
|
+
const param = configs[0].param ?? "hyle";
|
|
3062
|
+
if (configs.some((c) => (c.param ?? "hyle") !== param)) throw new TypeError("hyleRootPage: every config must use the same `param`");
|
|
3063
|
+
return { configs, param, loaders: configs.map(mountsLoader) };
|
|
2492
3064
|
}
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
try {
|
|
2501
|
-
parsed = new URL(origin);
|
|
2502
|
-
} catch {
|
|
2503
|
-
return true;
|
|
2504
|
-
}
|
|
2505
|
-
if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
|
|
2506
|
-
if (allowedOrigins) return !allowedOrigins.some((o) => safeOrigin(o) === parsed.origin);
|
|
2507
|
-
const host = req.headers.get("x-forwarded-host")?.split(",")[0]?.trim() || req.headers.get("host") || new URL(req.url).host;
|
|
2508
|
-
const proto = req.headers.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase();
|
|
2509
|
-
if (proto && proto !== parsed.protocol.slice(0, -1)) return true;
|
|
2510
|
-
return parsed.host !== host;
|
|
3065
|
+
var sectionsOf = (config, mount) => [
|
|
3066
|
+
...config.sections ?? [],
|
|
3067
|
+
...SECTION_SLUG.test(mount.defaultSection) ? [mount.defaultSection] : []
|
|
3068
|
+
];
|
|
3069
|
+
function mountOptionsOf(config, mount) {
|
|
3070
|
+
const { mountOptions, ...rest } = config;
|
|
3071
|
+
return { ...rest, ...mountOptions?.[mount.prefix === "" ? "/" : mount.prefix], basePath: mount.prefix, sections: sectionsOf(config, mount) };
|
|
2511
3072
|
}
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
if (Number(req.headers.get("content-length")) > MAX_BODY_BYTES2) return { kind: "refused", response: refuse(413, "PAYLOAD_TOO_LARGE") };
|
|
2523
|
-
if (!req.body) return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
2524
|
-
const reader = req.body.getReader();
|
|
2525
|
-
const chunks = [];
|
|
2526
|
-
let total = 0;
|
|
2527
|
-
for (; ; ) {
|
|
2528
|
-
const { done, value } = await reader.read();
|
|
2529
|
-
if (done) break;
|
|
2530
|
-
total += value.byteLength;
|
|
2531
|
-
if (total > MAX_BODY_BYTES2) {
|
|
2532
|
-
await reader.cancel().catch(() => {
|
|
3073
|
+
function rootMounts(options) {
|
|
3074
|
+
const { configs, param, loaders } = setup(options);
|
|
3075
|
+
return {
|
|
3076
|
+
param,
|
|
3077
|
+
async locate(path) {
|
|
3078
|
+
const loaded = await Promise.all(loaders.map((load) => load()));
|
|
3079
|
+
let best;
|
|
3080
|
+
loaded.forEach(({ mounts, reserved }, index2) => {
|
|
3081
|
+
if (isReserved(path, reserved)) return;
|
|
3082
|
+
for (const mount2 of mounts) if (prefixMatches(mount2.prefix, path) && (!best || mount2.depth > best.mount.depth)) best = { index: index2, mount: mount2 };
|
|
2533
3083
|
});
|
|
2534
|
-
|
|
3084
|
+
if (!best) return void 0;
|
|
3085
|
+
const { index, mount } = best;
|
|
3086
|
+
return { options: mountOptionsOf(configs[index], mount), mount, index };
|
|
3087
|
+
},
|
|
3088
|
+
async all() {
|
|
3089
|
+
const out = [];
|
|
3090
|
+
for (const [index, load] of loaders.entries()) {
|
|
3091
|
+
const { mounts, defaultLocale } = await load();
|
|
3092
|
+
for (const mount of mounts) out.push({ options: mountOptionsOf(configs[index], mount), mount, index, defaultLocale });
|
|
3093
|
+
}
|
|
3094
|
+
return out;
|
|
2535
3095
|
}
|
|
2536
|
-
|
|
2537
|
-
}
|
|
2538
|
-
try {
|
|
2539
|
-
const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
2540
|
-
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return { kind: "ok", body: parsed };
|
|
2541
|
-
} catch {
|
|
2542
|
-
}
|
|
2543
|
-
return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
3096
|
+
};
|
|
2544
3097
|
}
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
3098
|
+
function createRouter(options, make) {
|
|
3099
|
+
const mounts = rootMounts(options);
|
|
3100
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
3101
|
+
return async function route(params) {
|
|
3102
|
+
const raw = params[mounts.param];
|
|
3103
|
+
const segments = typeof raw === "string" ? [raw] : raw;
|
|
3104
|
+
const path = sitePathFrom("", segments);
|
|
3105
|
+
if (path === void 0 || path === "/" || !segments) return void 0;
|
|
3106
|
+
const hit = await mounts.locate(path);
|
|
3107
|
+
if (!hit) return void 0;
|
|
3108
|
+
const { mount, index } = hit;
|
|
3109
|
+
const id = `${index}|${mount.prefix}|${mount.defaultSection}`;
|
|
3110
|
+
let handler = handlers.get(id);
|
|
3111
|
+
if (!handler) {
|
|
3112
|
+
handler = make(hit.options);
|
|
3113
|
+
handlers.set(id, handler);
|
|
3114
|
+
}
|
|
3115
|
+
return { handler, params: { ...params, [mounts.param]: segments.slice(mount.depth) } };
|
|
3116
|
+
};
|
|
2551
3117
|
}
|
|
2552
|
-
function
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
return refuse(429, "RATE_LIMITED", { "Retry-After": String(seconds) });
|
|
2560
|
-
}
|
|
2561
|
-
return refuse(502, "UPSTREAM_ERROR");
|
|
3118
|
+
function hyleRootPage(options) {
|
|
3119
|
+
const route = createRouter(options, hylePage);
|
|
3120
|
+
return async function HyleRootPage({ params, searchParams }) {
|
|
3121
|
+
const hit = await route(await params ?? {});
|
|
3122
|
+
if (!hit) (0, import_navigation5.notFound)();
|
|
3123
|
+
return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
|
|
3124
|
+
};
|
|
2562
3125
|
}
|
|
2563
|
-
function
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
const clearCache = () => {
|
|
2569
|
-
cache.clear();
|
|
2570
|
-
cacheBytes = 0;
|
|
3126
|
+
function hyleRootMetadata(options) {
|
|
3127
|
+
const route = createRouter(options, hyleMetadata);
|
|
3128
|
+
return async function generateMetadata({ params, searchParams }, parent) {
|
|
3129
|
+
const hit = await route(await params ?? {});
|
|
3130
|
+
return hit ? hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} }, parent) : {};
|
|
2571
3131
|
};
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
3132
|
+
}
|
|
3133
|
+
async function hyleRootSitemap(options, sitemap) {
|
|
3134
|
+
const entries = /* @__PURE__ */ new Map();
|
|
3135
|
+
for (const { options: mountOptions, mount, defaultLocale } of await rootMounts(options).all()) {
|
|
3136
|
+
for (const locale of mount.locales ?? [defaultLocale]) {
|
|
3137
|
+
for (const entry of await hyleSitemap({ ...mountOptions, ...sitemap, locale, defaultLocale })) entries.set(entry.url, entry);
|
|
3138
|
+
}
|
|
2578
3139
|
}
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
3140
|
+
return [...entries.values()];
|
|
3141
|
+
}
|
|
3142
|
+
|
|
3143
|
+
// src/next/markdown.ts
|
|
3144
|
+
var MD_ROUTE_PREFIX = "/api/hyle/md";
|
|
3145
|
+
function markdownRewritePath(pathname) {
|
|
3146
|
+
if (!pathname.startsWith("/") || !pathname.endsWith(".md") || pathname.endsWith("/.md") || pathname.startsWith("/api/")) return void 0;
|
|
3147
|
+
return MD_ROUTE_PREFIX + pathname.slice(0, -3);
|
|
3148
|
+
}
|
|
3149
|
+
var reply = (body, status, headers = {}) => (
|
|
3150
|
+
// noindex on every answer: the .md twin must never compete with the page it mirrors.
|
|
3151
|
+
new Response(body, { status, headers: { "X-Robots-Tag": "noindex", ...headers } })
|
|
3152
|
+
);
|
|
3153
|
+
function createMarkdownRoute(options) {
|
|
3154
|
+
const mounts = rootMounts(options);
|
|
3155
|
+
return {
|
|
3156
|
+
async GET(_req, ctx2) {
|
|
3157
|
+
const params = await ctx2.params ?? {};
|
|
3158
|
+
const segments = params.path;
|
|
3159
|
+
const path = sitePathFrom("", typeof segments === "string" ? [segments] : segments);
|
|
3160
|
+
if (path === void 0 || path === "/") return reply(null, 404);
|
|
3161
|
+
try {
|
|
3162
|
+
const hit = await mounts.locate(path);
|
|
3163
|
+
if (!hit) return reply(null, 404);
|
|
3164
|
+
const { locale, toHref } = routeContext({ ...hit.options, basePath: "", param: "path" }, params);
|
|
3165
|
+
const result = await resolverFor(hit.options)(path, locale, void 0, void 0, void 0, "md");
|
|
3166
|
+
if (result.kind === "article" && result.content.format === "md") {
|
|
3167
|
+
const markdown = result.content.markdown.replaceAll("](/assets/", `](${ASSET_ROUTE_PREFIX}/`);
|
|
3168
|
+
return reply(markdown, 200, { "Content-Type": "text/markdown; charset=utf-8" });
|
|
3169
|
+
}
|
|
3170
|
+
if (result.kind === "redirect") {
|
|
3171
|
+
const to = safeRedirectTarget(result.to);
|
|
3172
|
+
const target = to === void 0 ? void 0 : safeRedirectTarget(toHref(to));
|
|
3173
|
+
if (target === void 0) return reply(null, 502);
|
|
3174
|
+
return target === toHref(path) ? reply(null, 404) : reply(null, result.status === 301 ? 308 : 307, { Location: `${target}.md` });
|
|
3175
|
+
}
|
|
3176
|
+
return reply(null, 404);
|
|
3177
|
+
} catch (error) {
|
|
3178
|
+
if (isRejectedRequest(error)) return reply(null, 404);
|
|
3179
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
3180
|
+
return reply(null, 502);
|
|
3181
|
+
}
|
|
2587
3182
|
}
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
3183
|
+
};
|
|
3184
|
+
}
|
|
3185
|
+
|
|
3186
|
+
// src/next/llms.ts
|
|
3187
|
+
var import_navigation6 = require("next/navigation");
|
|
3188
|
+
var oneLine = (text) => text.replace(/\s+/g, " ").trim();
|
|
3189
|
+
var linkTarget = (url) => url.replace(/[()]/g, (c) => c === "(" ? "%28" : "%29");
|
|
3190
|
+
function createLlmsTxtRoute(options, llms) {
|
|
3191
|
+
const origin = bareOrigin(llms.origin);
|
|
3192
|
+
if (!origin) throw new TypeError("createLlmsTxtRoute: `origin` must be a bare https origin such as https://example.com");
|
|
3193
|
+
const mounts = rootMounts(options);
|
|
3194
|
+
return {
|
|
3195
|
+
async GET() {
|
|
3196
|
+
try {
|
|
3197
|
+
const lines = [`# ${oneLine(llms.title ?? new URL(origin).host)}`, ...llms.description ? ["", `> ${oneLine(llms.description)}`] : []];
|
|
3198
|
+
for (const { options: mountOptions, mount, defaultLocale } of await mounts.all()) {
|
|
3199
|
+
if (mount.locales && !mount.locales.includes(defaultLocale)) continue;
|
|
3200
|
+
const { basePath, toHref } = routeContext({ ...mountOptions, locale: () => defaultLocale }, {});
|
|
3201
|
+
const resolve = resolverFor(mountOptions);
|
|
3202
|
+
const client = { resolve: ({ path, locale, limit, cursor }) => resolve(path, locale, limit, cursor) };
|
|
3203
|
+
const { paths } = await listPublicationPaths({ client, basePath, locale: defaultLocale });
|
|
3204
|
+
lines.push("", `## ${oneLine(mount.name ?? mount.defaultSection)}`, "");
|
|
3205
|
+
for (const { path, title, description } of paths) {
|
|
3206
|
+
lines.push(`- [${oneLine(title).replace(/[[\]]/g, "")}](${linkTarget(absoluteUrl(origin, toHref(path)))}.md)${description ? `: ${oneLine(description)}` : ""}`);
|
|
3207
|
+
}
|
|
2600
3208
|
}
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
3209
|
+
return new Response(`${lines.join("\n")}
|
|
3210
|
+
`, { headers: { "Content-Type": "text/plain; charset=utf-8" } });
|
|
3211
|
+
} catch (error) {
|
|
3212
|
+
(0, import_navigation6.unstable_rethrow)(error);
|
|
3213
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
3214
|
+
return new Response(null, { status: 503 });
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
};
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3220
|
+
// src/next/og.tsx
|
|
3221
|
+
var import_og = require("next/og");
|
|
3222
|
+
|
|
3223
|
+
// src/next/asset.ts
|
|
3224
|
+
var DEFAULT_MAX_BYTES = 16 * 1024 * 1024;
|
|
3225
|
+
var DEFAULT_TIMEOUT_MS3 = 3e4;
|
|
3226
|
+
var CACHE_CONTROL = "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400";
|
|
3227
|
+
var PARTIAL_CACHE_CONTROL = "no-store";
|
|
3228
|
+
var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
|
|
3229
|
+
var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
|
|
3230
|
+
var isSwitchedOff3 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
3231
|
+
function capped(body, max) {
|
|
3232
|
+
let seen = 0;
|
|
3233
|
+
return body.pipeThrough(
|
|
3234
|
+
new TransformStream({
|
|
3235
|
+
transform(chunk, controller) {
|
|
3236
|
+
seen += chunk.byteLength;
|
|
3237
|
+
if (seen > max) return controller.error(new Error("asset too large"));
|
|
3238
|
+
controller.enqueue(chunk);
|
|
3239
|
+
}
|
|
3240
|
+
})
|
|
3241
|
+
);
|
|
3242
|
+
}
|
|
3243
|
+
function createAssetRoute(options) {
|
|
3244
|
+
let client;
|
|
3245
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
3246
|
+
async function serve(req, ctx2, head) {
|
|
3247
|
+
if (isSwitchedOff3((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
|
|
3248
|
+
const file = (await ctx2.params).file;
|
|
3249
|
+
if (typeof file !== "string" || !ASSET_FILE.test(file)) return empty(404);
|
|
2613
3250
|
try {
|
|
2614
|
-
|
|
2615
|
-
checkBaseUrl(baseUrl);
|
|
2616
|
-
if (!options.token?.trim() || !options.workspaceId?.trim() || !options.signingKey) throw new TypeError("not provisioned");
|
|
2617
|
-
ready = { base: baseUrl.replace(/\/+$/, ""), key: engagementSigningKey(options.signingKey.trim()) };
|
|
3251
|
+
client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
|
|
2618
3252
|
} catch {
|
|
2619
|
-
|
|
3253
|
+
return empty(404);
|
|
2620
3254
|
}
|
|
2621
|
-
|
|
2622
|
-
}
|
|
2623
|
-
async function reader(req, config) {
|
|
3255
|
+
let upstream;
|
|
2624
3256
|
try {
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
return { reader: found, assertion: sign2(), sign: sign2 };
|
|
3257
|
+
upstream = await client.asset(file, {
|
|
3258
|
+
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS3,
|
|
3259
|
+
headers: { range: req.headers.get("range"), "if-range": req.headers.get("if-range"), "if-none-match": req.headers.get("if-none-match") }
|
|
3260
|
+
});
|
|
2630
3261
|
} catch {
|
|
2631
|
-
return
|
|
3262
|
+
return empty(502);
|
|
2632
3263
|
}
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
const
|
|
2636
|
-
if (
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
if (!config || !route) return refuse(404, "NOT_FOUND");
|
|
2640
|
-
if (!route.methods.includes(req.method)) return refuse(405, "METHOD_NOT_ALLOWED", { Allow: route.methods.join(", ") });
|
|
2641
|
-
const write = req.method !== "GET";
|
|
2642
|
-
if (sameOriginProblem(req, write, options.allowedOrigins)) return refuse(403, "FORBIDDEN");
|
|
2643
|
-
if (options.onRequest) {
|
|
2644
|
-
try {
|
|
2645
|
-
const early = await options.onRequest(req, { action: route.action(req.method) });
|
|
2646
|
-
if (early instanceof Response) {
|
|
2647
|
-
const headers = new Headers(early.headers);
|
|
2648
|
-
headers.set("cache-control", "no-store");
|
|
2649
|
-
return new Response(early.body, { status: early.status, headers });
|
|
2650
|
-
}
|
|
2651
|
-
} catch {
|
|
2652
|
-
return refuse(502, "UPSTREAM_ERROR");
|
|
2653
|
-
}
|
|
3264
|
+
const drop = () => void upstream.body?.cancel().catch(() => {
|
|
3265
|
+
});
|
|
3266
|
+
const etag = upstream.headers.get("etag");
|
|
3267
|
+
if (upstream.status === 304) {
|
|
3268
|
+
drop();
|
|
3269
|
+
return new Response(null, { status: 304, headers: { "Cache-Control": CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS, ...etag ? { ETag: etag } : {} } });
|
|
2654
3270
|
}
|
|
2655
|
-
if (
|
|
2656
|
-
|
|
2657
|
-
|
|
3271
|
+
if (upstream.status === 404 || upstream.status === 416) {
|
|
3272
|
+
drop();
|
|
3273
|
+
const range = upstream.status === 416 ? upstream.headers.get("content-range") : null;
|
|
3274
|
+
return empty(upstream.status, range ? { "Content-Range": range } : {});
|
|
2658
3275
|
}
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
if (
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
assertion = who.assertion;
|
|
3276
|
+
const type = upstream.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase();
|
|
3277
|
+
const length = Number(upstream.headers.get("content-length"));
|
|
3278
|
+
const expectedStatus = upstream.status === 200 || upstream.status === 206;
|
|
3279
|
+
if (!expectedStatus || !upstream.body || !type || !ASSET_CONTENT_TYPES.has(type) || Number.isFinite(length) && length > maxBytes) {
|
|
3280
|
+
drop();
|
|
3281
|
+
return empty(502);
|
|
2666
3282
|
}
|
|
2667
|
-
const
|
|
2668
|
-
|
|
2669
|
-
const
|
|
2670
|
-
if (
|
|
2671
|
-
|
|
2672
|
-
if (
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
const target = `${config.base}/cp1/engage${built.upstream}${built.query ? `?${built.query}` : ""}`;
|
|
2676
|
-
const call = async (withAssertion = assertion) => {
|
|
2677
|
-
const headers = new Headers(baseHeaders);
|
|
2678
|
-
if (withAssertion) headers.set("hyle-reader-assertion", withAssertion);
|
|
2679
|
-
const res = await fetchImpl(target, {
|
|
2680
|
-
method: req.method,
|
|
2681
|
-
headers,
|
|
2682
|
-
...built.body ? { body: JSON.stringify(built.body) } : {},
|
|
2683
|
-
redirect: "error",
|
|
2684
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS3)
|
|
2685
|
-
});
|
|
2686
|
-
return { status: res.status, ok: res.ok, text: await readCapped(res, MAX_RESPONSE_BYTES), retryAfter: res.headers.get("retry-after"), throttle: res.headers.get("hyle-throttle") };
|
|
2687
|
-
};
|
|
2688
|
-
try {
|
|
2689
|
-
const out = route.action(req.method) === "comments.list" ? await shared(`${viewer?.reader.sub ?? ""}
|
|
2690
|
-
${built.query.toString()}`, () => listing(viewer, call)) : await call();
|
|
2691
|
-
if (!out.ok) return relayFailure(out.status, out.retryAfter);
|
|
2692
|
-
if (write) clearCache();
|
|
2693
|
-
const data = JSON.parse(out.text).data;
|
|
2694
|
-
return typeof data === "object" && data !== null ? json(out.status === 201 ? 201 : 200, { data }) : refuse(502, "UPSTREAM_ERROR");
|
|
2695
|
-
} catch {
|
|
2696
|
-
return refuse(502, "UPSTREAM_ERROR");
|
|
3283
|
+
const headers = new Headers({ "Content-Type": type, "Accept-Ranges": "bytes", "Cache-Control": upstream.status === 206 ? PARTIAL_CACHE_CONTROL : CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS });
|
|
3284
|
+
if (etag) headers.set("ETag", etag);
|
|
3285
|
+
const contentRange = upstream.headers.get("content-range");
|
|
3286
|
+
if (upstream.status === 206 && contentRange) headers.set("Content-Range", contentRange);
|
|
3287
|
+
if (!upstream.headers.get("content-encoding") && upstream.headers.get("content-length")) headers.set("Content-Length", String(length));
|
|
3288
|
+
if (head) {
|
|
3289
|
+
drop();
|
|
3290
|
+
return new Response(null, { status: upstream.status, headers });
|
|
2697
3291
|
}
|
|
3292
|
+
return new Response(capped(upstream.body, maxBytes), { status: upstream.status, headers });
|
|
2698
3293
|
}
|
|
2699
|
-
return { GET:
|
|
3294
|
+
return { GET: (req, ctx2) => serve(req, ctx2, false), HEAD: (req, ctx2) => serve(req, ctx2, true) };
|
|
2700
3295
|
}
|
|
2701
3296
|
|
|
2702
|
-
// src/next/
|
|
2703
|
-
var
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
} catch (error) {
|
|
2708
|
-
if (isRejectedRequest(error)) return {};
|
|
2709
|
-
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2710
|
-
return { failure: options.onError ? options.onError(error) : null };
|
|
2711
|
-
}
|
|
2712
|
-
}
|
|
2713
|
-
async function HyleList({ options, limit = 5, locale, layout, title, headingLevel, moreHref }) {
|
|
2714
|
-
const resolve = resolverFor(options);
|
|
2715
|
-
const route = routeContext(locale ? { ...options, locale } : options, {});
|
|
2716
|
-
const path = sitePathFrom(route.basePath, void 0);
|
|
2717
|
-
if (path === void 0) return null;
|
|
2718
|
-
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale, limit));
|
|
2719
|
-
if (failure !== void 0) return failure;
|
|
2720
|
-
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HyleListView, { items: result?.kind === "list" ? result.items : [], layout, title, headingLevel, moreHref, components: options.components, slots: options.slots, locale: route.locale, toHref: route.toHref });
|
|
2721
|
-
}
|
|
2722
|
-
async function HyleArticle({ options, path, locale, headingLevel }) {
|
|
2723
|
-
if (!isSitePath2(path)) return null;
|
|
3297
|
+
// src/next/og.tsx
|
|
3298
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
3299
|
+
var SIZE = { width: 1200, height: 630 };
|
|
3300
|
+
var MAX_TITLE = 140;
|
|
3301
|
+
function createOgImageRoute(options) {
|
|
2724
3302
|
const resolve = resolverFor(options);
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
}
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
3303
|
+
return {
|
|
3304
|
+
async GET(req, ctx2) {
|
|
3305
|
+
if (isSwitchedOff3(process.env.HYLE_CONTENT_ENABLED)) return new Response(null, { status: 404 });
|
|
3306
|
+
const segments = (await ctx2.params).path;
|
|
3307
|
+
const route = routeContext({ ...options, basePath: "", param: "path" }, { path: segments });
|
|
3308
|
+
if (!segments?.length || route.path === void 0) return new Response(null, { status: 404 });
|
|
3309
|
+
const path = route.path;
|
|
3310
|
+
const load = async (locale) => {
|
|
3311
|
+
const first = await resolve(path, locale);
|
|
3312
|
+
const target = first.kind === "redirect" ? safeRedirectTarget(first.to) : void 0;
|
|
3313
|
+
return target ? resolve(target, locale) : first;
|
|
3314
|
+
};
|
|
3315
|
+
let title;
|
|
3316
|
+
try {
|
|
3317
|
+
let result = await load();
|
|
3318
|
+
const wanted = new URL(req.url).searchParams.get("locale");
|
|
3319
|
+
if (result.kind === "article" && wanted && wanted !== result.publication.locale && result.alternates.some((a) => a.locale === wanted)) result = await load(wanted);
|
|
3320
|
+
if (result.kind !== "article") return new Response(null, { status: 404 });
|
|
3321
|
+
title = result.publication.title;
|
|
3322
|
+
} catch (error) {
|
|
3323
|
+
return new Response(null, { status: isRejectedRequest(error) ? 404 : 502 });
|
|
3324
|
+
}
|
|
3325
|
+
const chars = [...title];
|
|
3326
|
+
const shown = chars.length > MAX_TITLE ? `${chars.slice(0, MAX_TITLE - 1).join("")}\u2026` : title;
|
|
3327
|
+
return new import_og.ImageResponse(
|
|
3328
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { style: { display: "flex", flexDirection: "column", justifyContent: "space-between", width: "100%", height: "100%", padding: 80, background: "#111827", color: "#ffffff" }, children: [
|
|
3329
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { style: { fontSize: 64, fontWeight: 700, lineHeight: 1.2 }, children: shown }),
|
|
3330
|
+
options.siteName ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { style: { fontSize: 32, color: "#9ca3af" }, children: options.siteName }) : null
|
|
3331
|
+
] }),
|
|
3332
|
+
// shortcut: @vercel/og fetches Google Fonts / emoji assets at render time for non-Latin titles and emoji (no switch to disable it), upgrade to a satori render with bundled fonts if a host needs zero egress.
|
|
3333
|
+
{ ...SIZE, headers: { "cache-control": "public, max-age=3600, s-maxage=31536000, immutable" } }
|
|
3334
|
+
);
|
|
2751
3335
|
}
|
|
2752
|
-
|
|
2753
|
-
const date = Date.parse(res.headers.get("date") ?? "");
|
|
2754
|
-
fetchedAt = Number.isFinite(date) ? date : void 0;
|
|
2755
|
-
} catch (error) {
|
|
2756
|
-
(0, import_navigation6.unstable_rethrow)(error);
|
|
2757
|
-
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2758
|
-
return null;
|
|
2759
|
-
}
|
|
2760
|
-
if (!listing) return null;
|
|
2761
|
-
if (!interactive) return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HyleCommentsView, { listing, locale });
|
|
2762
|
-
const config = interactive === true ? {} : interactive;
|
|
2763
|
-
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "hyle hyle-embed", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_comments2.Comments, { path, endpoint: config.endpoint ?? "/api/hyle/engage", signInHref: config.signInHref, locale, labels: stringsFor(locale).comments, initial: listing, initialAt: fetchedAt }) });
|
|
3336
|
+
};
|
|
2764
3337
|
}
|
|
2765
3338
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2766
3339
|
0 && (module.exports = {
|
|
@@ -2774,9 +3347,11 @@ async function HyleComments({ options, path, revalidate = 60, interactive }) {
|
|
|
2774
3347
|
createEngagementRoute,
|
|
2775
3348
|
createLlmsTxtRoute,
|
|
2776
3349
|
createMarkdownRoute,
|
|
3350
|
+
createOgImageRoute,
|
|
2777
3351
|
createRevalidateRoute,
|
|
2778
3352
|
fetchResolver,
|
|
2779
3353
|
hyleFeed,
|
|
3354
|
+
hyleFeedLink,
|
|
2780
3355
|
hyleMetadata,
|
|
2781
3356
|
hylePage,
|
|
2782
3357
|
hyleRootMetadata,
|