@tdacorp/hyle-sdk 0.9.0 → 0.12.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 +111 -2
- package/bin/hyle-sdk-engage-keygen.mjs +3 -0
- package/dist/check-routes-bin.js +5 -1
- package/dist/{chunk-54JF4E53.js → chunk-N7ZQUAGM.js} +45 -2
- package/dist/chunk-R5EMI4HQ.js +61 -0
- package/dist/{chunk-XKR74Y5G.js → chunk-S7PCCEHP.js} +1 -1
- package/dist/{chunk-6LW33475.js → chunk-ZQFYH4FX.js} +538 -50
- package/dist/comments.cjs +1048 -0
- package/dist/comments.d.cts +152 -0
- package/dist/comments.d.ts +152 -0
- package/dist/comments.js +1025 -0
- package/dist/{types-BPPZrYOZ.d.cts → embed-DL5QIZRJ.d.ts} +44 -3
- package/dist/{types-C1eCQ2As.d.ts → embed-jCaSI31t.d.cts} +44 -3
- package/dist/engage-keygen-bin.js +67 -0
- package/dist/index.cjs +26 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +5 -1
- package/dist/mermaid-diagram.js +9 -54
- package/dist/next.cjs +1010 -78
- package/dist/next.d.cts +163 -6
- package/dist/next.d.ts +163 -6
- package/dist/next.js +442 -14
- package/dist/react.cjs +340 -49
- package/dist/react.d.cts +112 -7
- package/dist/react.d.ts +112 -7
- package/dist/react.js +7 -1
- package/dist/{resolve-Dpb6Orsj.d.ts → resolve-DvmuBlpO.d.ts} +1 -1
- package/dist/{resolve-D2rnnho9.d.cts → resolve-f6IJ6SL9.d.cts} +1 -1
- package/dist/styles.css +117 -0
- package/dist/{types-CHxH5E0S.d.cts → types-5D6ZD0Wi.d.cts} +59 -1
- package/dist/{types-CHxH5E0S.d.ts → types-5D6ZD0Wi.d.ts} +59 -1
- package/dist/use-cache.cjs +5 -1
- package/dist/use-cache.d.cts +2 -2
- package/dist/use-cache.d.ts +2 -2
- package/dist/use-cache.js +2 -2
- package/package.json +4 -3
package/dist/next.cjs
CHANGED
|
@@ -20,10 +20,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/next/index.ts
|
|
21
21
|
var next_exports = {};
|
|
22
22
|
__export(next_exports, {
|
|
23
|
+
ENGAGE_CSRF_HEADER: () => ENGAGE_CSRF_HEADER,
|
|
24
|
+
HyleArticle: () => HyleArticle,
|
|
25
|
+
HyleComments: () => HyleComments,
|
|
26
|
+
HyleCommentsFallback: () => HyleCommentsFallback,
|
|
27
|
+
HyleList: () => HyleList,
|
|
23
28
|
MOUNTS_MAX_STALE_MS: () => MOUNTS_MAX_STALE_MS,
|
|
24
29
|
createAssetRoute: () => createAssetRoute,
|
|
30
|
+
createEngagementRoute: () => createEngagementRoute,
|
|
25
31
|
createRevalidateRoute: () => createRevalidateRoute,
|
|
26
32
|
fetchResolver: () => fetchResolver,
|
|
33
|
+
hyleFeed: () => hyleFeed,
|
|
27
34
|
hyleMetadata: () => hyleMetadata,
|
|
28
35
|
hylePage: () => hylePage,
|
|
29
36
|
hyleRootMetadata: () => hyleRootMetadata,
|
|
@@ -154,7 +161,11 @@ function createHyleClient(options) {
|
|
|
154
161
|
if (opts.limit !== void 0) query.set("limit", String(opts.limit));
|
|
155
162
|
const reply = await get("/cp1/read/resolve", query, opts.init);
|
|
156
163
|
const data = reply.parsed?.data;
|
|
157
|
-
if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind))
|
|
164
|
+
if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) {
|
|
165
|
+
const resolved = data;
|
|
166
|
+
if (resolved.kind === "article" && resolved.content.format === "html" && opts.format !== "html") throw failure(reply);
|
|
167
|
+
return resolved;
|
|
168
|
+
}
|
|
158
169
|
throw failure(reply);
|
|
159
170
|
}
|
|
160
171
|
async function mounts(opts = {}) {
|
|
@@ -243,8 +254,8 @@ function verifyHyleSignature(params) {
|
|
|
243
254
|
|
|
244
255
|
// src/tag-validation.ts
|
|
245
256
|
var CACHE_TAG_PATTERN = /^hyle:1:(pub|doc|sec|link|ws):[0-9a-f-]{36}(:[\x21-\x7e]{1,200})?$/;
|
|
246
|
-
function isValidCacheTag(
|
|
247
|
-
return CACHE_TAG_PATTERN.test(
|
|
257
|
+
function isValidCacheTag(tag2) {
|
|
258
|
+
return CACHE_TAG_PATTERN.test(tag2);
|
|
248
259
|
}
|
|
249
260
|
|
|
250
261
|
// src/revalidation-callback.ts
|
|
@@ -290,9 +301,9 @@ function createRevalidationCallbackRoute(options) {
|
|
|
290
301
|
}
|
|
291
302
|
let purged = 0;
|
|
292
303
|
try {
|
|
293
|
-
for (const
|
|
294
|
-
if (!isValidCacheTag(
|
|
295
|
-
options.revalidateTag(
|
|
304
|
+
for (const tag2 of tags) {
|
|
305
|
+
if (!isValidCacheTag(tag2)) continue;
|
|
306
|
+
options.revalidateTag(tag2);
|
|
296
307
|
purged += 1;
|
|
297
308
|
}
|
|
298
309
|
} catch {
|
|
@@ -369,6 +380,31 @@ async function listPublicationPaths(options) {
|
|
|
369
380
|
return { paths: [...found].map(([path, publishedAt]) => ({ path, publishedAt })), complete };
|
|
370
381
|
}
|
|
371
382
|
|
|
383
|
+
// src/engage-keys.ts
|
|
384
|
+
var import_node_crypto2 = require("crypto");
|
|
385
|
+
var KEY_B64URL = /^[A-Za-z0-9_-]{43}$/;
|
|
386
|
+
var PKCS8_ED25519 = Buffer.from("302e020100300506032b657004220420", "hex");
|
|
387
|
+
function engagementSigningKey(seed) {
|
|
388
|
+
const bytes = KEY_B64URL.test(seed) ? Buffer.from(seed, "base64url") : void 0;
|
|
389
|
+
if (bytes?.length !== 32) throw new TypeError("the engagement signing key must be a 32-byte Ed25519 seed, base64url (43 characters)");
|
|
390
|
+
return (0, import_node_crypto2.createPrivateKey)({ key: Buffer.concat([PKCS8_ED25519, bytes]), format: "der", type: "pkcs8" });
|
|
391
|
+
}
|
|
392
|
+
var ASSERTION_MAX_BYTES = 2048;
|
|
393
|
+
var ASSERTION_TTL_SECONDS = 30;
|
|
394
|
+
var b64 = (value) => Buffer.from(JSON.stringify(value)).toString("base64url");
|
|
395
|
+
function signReaderAssertion(key, claims, nowSeconds = Math.floor(Date.now() / 1e3), scope) {
|
|
396
|
+
const input = `${b64({ alg: "EdDSA", typ: "JWT" })}.${b64({ ...claims, ...scope ? { scope } : {}, aud: "hyle", iat: nowSeconds, exp: nowSeconds + ASSERTION_TTL_SECONDS, jti: (0, import_node_crypto2.randomUUID)() })}`;
|
|
397
|
+
const token = `${input}.${(0, import_node_crypto2.sign)(null, Buffer.from(input), key).toString("base64url")}`;
|
|
398
|
+
if (Buffer.byteLength(token) > ASSERTION_MAX_BYTES) throw new RangeError("the reader assertion would exceed 2 KiB");
|
|
399
|
+
return token;
|
|
400
|
+
}
|
|
401
|
+
var INVISIBLE = /[\u0000-\u001f\u007f-\u009f\p{Cf}\u115f\u1160\u17b4\u17b5\u3164\uffa0]/gu;
|
|
402
|
+
var DISPLAY_NAME_MAX = 80;
|
|
403
|
+
function cleanDisplayName(raw) {
|
|
404
|
+
const cleaned = [...raw.replace(/[\t\n\r\f\v]/gu, " ").replace(INVISIBLE, "").replace(/\s+/gu, " ").trim()].slice(0, DISPLAY_NAME_MAX).join("").trim();
|
|
405
|
+
return cleaned.length > 0 ? cleaned : void 0;
|
|
406
|
+
}
|
|
407
|
+
|
|
372
408
|
// src/react/content.tsx
|
|
373
409
|
var import_hast_util_to_jsx_runtime = require("hast-util-to-jsx-runtime");
|
|
374
410
|
var import_react = require("react");
|
|
@@ -405,7 +441,18 @@ var SHAPES = {
|
|
|
405
441
|
chev: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m6 3.5 4.5 4.5L6 12.5" }),
|
|
406
442
|
"chev-down": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3.5 6 4.5 4.5L12.5 6" }),
|
|
407
443
|
"chev-left": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 3.5 5.5 8 10 12.5" }),
|
|
408
|
-
x: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m4 4 8 8M12 4l-8 8" })
|
|
444
|
+
x: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m4 4 8 8M12 4l-8 8" }),
|
|
445
|
+
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" }),
|
|
446
|
+
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" }),
|
|
447
|
+
clock: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
448
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
|
|
449
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 4.5V8l2.3 1.5" })
|
|
450
|
+
] }),
|
|
451
|
+
ban: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
452
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
|
|
453
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3.8 12.2 8.4-8.4" })
|
|
454
|
+
] }),
|
|
455
|
+
refresh: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M13 8a5 5 0 1 1-1.6-3.7M13 2.5v2.8h-2.8" })
|
|
409
456
|
};
|
|
410
457
|
function Icon({ name, className }) {
|
|
411
458
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: className ? `hyle-ic ${className}` : "hyle-ic", viewBox: "0 0 16 16", "aria-hidden": "true", children: SHAPES[name] });
|
|
@@ -554,10 +601,10 @@ function clean(node, depth, ctx2, budget) {
|
|
|
554
601
|
return [{ type: "text", value: node.value }];
|
|
555
602
|
}
|
|
556
603
|
if (node.type !== "element" || typeof node.tagName !== "string" || DROP.has(node.tagName)) return [];
|
|
557
|
-
const
|
|
558
|
-
const rules = ATTRS.get(
|
|
604
|
+
const tag2 = node.tagName;
|
|
605
|
+
const rules = ATTRS.get(tag2);
|
|
559
606
|
const own = isObject(node.properties) ? classTokens(node.properties.className) : void 0;
|
|
560
|
-
const inner =
|
|
607
|
+
const inner = tag2 === "span" && own?.some((t) => t === "katex" || t.startsWith("katex-")) ? { katex: true } : ctx2;
|
|
561
608
|
const children = Array.isArray(node.children) ? node.children.flatMap((c) => clean(c, depth + 1, inner, budget)) : [];
|
|
562
609
|
if (!rules) return children;
|
|
563
610
|
const properties = {};
|
|
@@ -566,32 +613,223 @@ function clean(node, depth, ctx2, budget) {
|
|
|
566
613
|
if (Object.hasOwn(rules, key) && rules[key](value, inner)) properties[key] = value;
|
|
567
614
|
}
|
|
568
615
|
}
|
|
569
|
-
if ((
|
|
570
|
-
if (
|
|
616
|
+
if ((tag2 === "img" || tag2 === "video" || tag2 === "audio") && typeof properties.src === "string") properties.src = hostAssetSrc(properties.src);
|
|
617
|
+
if (tag2 === "iframe") {
|
|
571
618
|
if (properties.sandbox === void 0 || properties.srcdoc === void 0) return [];
|
|
572
619
|
properties.sandbox = "allow-scripts";
|
|
573
620
|
}
|
|
574
|
-
if (
|
|
621
|
+
if (tag2 === "input") {
|
|
575
622
|
if (properties.type !== "checkbox") return [];
|
|
576
623
|
properties.disabled = true;
|
|
577
624
|
}
|
|
578
625
|
for (const key of ["id", "ariaDescribedBy"]) if (typeof properties[key] === "string") properties[key] = scopeId(properties[key]);
|
|
579
|
-
if (
|
|
580
|
-
if (
|
|
626
|
+
if (tag2 === "a" && typeof properties.href === "string" && properties.href.trim().startsWith("#")) properties.href = `#${scopeId(properties.href.trim().slice(1))}`;
|
|
627
|
+
if (tag2 === "blockquote") {
|
|
581
628
|
const callout = toCallout(children);
|
|
582
629
|
if (callout) return [callout];
|
|
583
630
|
}
|
|
584
|
-
const tagName =
|
|
585
|
-
return [{ type: "element", tagName, properties, children: VOID.has(
|
|
631
|
+
const tagName = tag2 === "h1" ? "h2" : tag2;
|
|
632
|
+
return [{ type: "element", tagName, properties, children: VOID.has(tag2) ? [] : children }];
|
|
586
633
|
}
|
|
587
|
-
function sanitizeHast(tree, title) {
|
|
634
|
+
function sanitizeHast(tree, title, description) {
|
|
588
635
|
const raw = isObject(tree) && tree.type === "root" && Array.isArray(tree.children) ? tree.children : [];
|
|
589
|
-
const
|
|
636
|
+
const elements = raw.filter((n) => isObject(n) && n.type === "element");
|
|
637
|
+
const [first] = elements;
|
|
590
638
|
const skip = title !== void 0 && isObject(first) && first.tagName === "h1" && textOf(first).trim() === title.trim() ? first : void 0;
|
|
639
|
+
const lead = elements[skip ? 1 : 0];
|
|
640
|
+
const repeat = description && isObject(lead) && lead.tagName === "p" && textOf(lead).trim().startsWith(description.trim()) ? lead : void 0;
|
|
591
641
|
const budget = { nodes: 0, text: 0 };
|
|
592
|
-
return { type: "root", children: raw.filter((n) => n !== skip).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
|
|
642
|
+
return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
|
|
593
643
|
}
|
|
594
644
|
|
|
645
|
+
// src/react/comments-labels.ts
|
|
646
|
+
var COMMENT_LABELS_EN = {
|
|
647
|
+
heading: "Comments",
|
|
648
|
+
countLabel: "{n} comments",
|
|
649
|
+
likeArticle: "Like this article",
|
|
650
|
+
likedArticle: "Liked",
|
|
651
|
+
likeArticleSignIn: "(sign in), ",
|
|
652
|
+
likeComment: "Like this comment, ",
|
|
653
|
+
likeCommentSignIn: "Sign in to like this comment, ",
|
|
654
|
+
signInTitle: "Sign in to join the discussion",
|
|
655
|
+
signInBody: "Anyone can read. To comment or like, sign in.",
|
|
656
|
+
signIn: "Sign in",
|
|
657
|
+
commentingAs: "Commenting as {name}",
|
|
658
|
+
write: "Write a comment",
|
|
659
|
+
placeholder: "Add to the discussion",
|
|
660
|
+
help: "Markdown: links, emphasis, code and quotes.",
|
|
661
|
+
chars: "{n} / {max}",
|
|
662
|
+
post: "Post comment",
|
|
663
|
+
posting: "Posting",
|
|
664
|
+
reply: "Reply",
|
|
665
|
+
replyTo: "Reply to {name}",
|
|
666
|
+
replyPlaceholder: "Write a reply",
|
|
667
|
+
cancel: "Cancel",
|
|
668
|
+
edit: "Edit",
|
|
669
|
+
editLeft: "({n} min left)",
|
|
670
|
+
save: "Save",
|
|
671
|
+
delete: "Delete",
|
|
672
|
+
deleteConfirm: "Delete this comment?",
|
|
673
|
+
keep: "Keep",
|
|
674
|
+
you: "You",
|
|
675
|
+
edited: "edited",
|
|
676
|
+
removed: "This comment was removed.",
|
|
677
|
+
removedByModerator: "This comment was removed by a moderator.",
|
|
678
|
+
removedByAuthor: "This comment was deleted by its author.",
|
|
679
|
+
depthEnd: "Replies end at this depth",
|
|
680
|
+
held: "Awaiting approval.",
|
|
681
|
+
heldBanner: "Thanks, your comment is awaiting approval",
|
|
682
|
+
heldBannerBody: "New commenters may be reviewed first. You will see it here, marked as pending, until a moderator approves it. Nobody else can see it yet.",
|
|
683
|
+
heldNote: "Only you can see this until a moderator approves it.",
|
|
684
|
+
heldLive: "Comment awaiting approval",
|
|
685
|
+
postedLive: "Comment posted",
|
|
686
|
+
deletedLive: "Comment deleted",
|
|
687
|
+
savedLive: "Comment saved",
|
|
688
|
+
empty: "No comments yet",
|
|
689
|
+
emptyBody: "Start the discussion. Comments may be reviewed before they appear.",
|
|
690
|
+
loading: "Loading comments",
|
|
691
|
+
loadError: "Comments could not be loaded",
|
|
692
|
+
loadErrorBody: "The article is fine. The comments service did not answer.",
|
|
693
|
+
retry: "Try again",
|
|
694
|
+
postError: "Your comment was not posted. We kept your text, so nothing is lost. Check your connection and try again.",
|
|
695
|
+
tooLong: "That comment is too long or empty. Comments are 1 to 4000 characters.",
|
|
696
|
+
editClosed: "Comments can be edited for ten minutes after posting. That time has passed.",
|
|
697
|
+
actionError: "That did not go through. Please try again.",
|
|
698
|
+
rateTitle: "You are commenting too quickly",
|
|
699
|
+
rateBody: "Please wait before posting again. Your draft is kept in the box below.",
|
|
700
|
+
rateWait: "You can post again in {n} seconds.",
|
|
701
|
+
bannedTitle: "You cannot comment right now",
|
|
702
|
+
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.",
|
|
703
|
+
expired: "Your session ended. Sign in again to post. Your text is kept.",
|
|
704
|
+
more: "Load more comments",
|
|
705
|
+
truncated: "Showing the first 500 comments.",
|
|
706
|
+
justNow: "just now"
|
|
707
|
+
};
|
|
708
|
+
var COMMENT_LABELS_FR = {
|
|
709
|
+
heading: "Commentaires",
|
|
710
|
+
countLabel: "{n} commentaires",
|
|
711
|
+
likeArticle: "Aimer cet article",
|
|
712
|
+
likedArticle: "Aim\xE9",
|
|
713
|
+
likeArticleSignIn: "(connexion requise), ",
|
|
714
|
+
likeComment: "Aimer ce commentaire, ",
|
|
715
|
+
likeCommentSignIn: "Connectez-vous pour aimer ce commentaire, ",
|
|
716
|
+
signInTitle: "Connectez-vous pour participer \xE0 la discussion",
|
|
717
|
+
signInBody: "Tout le monde peut lire. Pour commenter ou aimer, connectez-vous.",
|
|
718
|
+
signIn: "Se connecter",
|
|
719
|
+
commentingAs: "Vous commentez en tant que {name}",
|
|
720
|
+
write: "\xC9crire un commentaire",
|
|
721
|
+
placeholder: "Participez \xE0 la discussion",
|
|
722
|
+
help: "Markdown : liens, emphase, code et citations.",
|
|
723
|
+
chars: "{n} / {max}",
|
|
724
|
+
post: "Publier le commentaire",
|
|
725
|
+
posting: "Publication",
|
|
726
|
+
reply: "R\xE9pondre",
|
|
727
|
+
replyTo: "R\xE9pondre \xE0 {name}",
|
|
728
|
+
replyPlaceholder: "\xC9crire une r\xE9ponse",
|
|
729
|
+
cancel: "Annuler",
|
|
730
|
+
edit: "Modifier",
|
|
731
|
+
editLeft: "({n} min restantes)",
|
|
732
|
+
save: "Enregistrer",
|
|
733
|
+
delete: "Supprimer",
|
|
734
|
+
deleteConfirm: "Supprimer ce commentaire ?",
|
|
735
|
+
keep: "Conserver",
|
|
736
|
+
you: "Vous",
|
|
737
|
+
edited: "modifi\xE9",
|
|
738
|
+
removed: "Ce commentaire a \xE9t\xE9 retir\xE9.",
|
|
739
|
+
removedByModerator: "Ce commentaire a \xE9t\xE9 retir\xE9 par un mod\xE9rateur.",
|
|
740
|
+
removedByAuthor: "Ce commentaire a \xE9t\xE9 supprim\xE9 par son auteur.",
|
|
741
|
+
depthEnd: "Les r\xE9ponses s'arr\xEAtent \xE0 ce niveau",
|
|
742
|
+
held: "En attente d'approbation.",
|
|
743
|
+
heldBanner: "Merci, votre commentaire est en attente d'approbation",
|
|
744
|
+
heldBannerBody: "Les nouveaux commentaires peuvent \xEAtre relus d'abord. Vous le voyez ici, marqu\xE9 en attente, jusqu'\xE0 son approbation par un mod\xE9rateur. Personne d'autre ne peut le voir.",
|
|
745
|
+
heldNote: "Vous seul le voyez tant qu'un mod\xE9rateur ne l'a pas approuv\xE9.",
|
|
746
|
+
heldLive: "Commentaire en attente d'approbation",
|
|
747
|
+
postedLive: "Commentaire publi\xE9",
|
|
748
|
+
deletedLive: "Commentaire supprim\xE9",
|
|
749
|
+
savedLive: "Commentaire enregistr\xE9",
|
|
750
|
+
empty: "Aucun commentaire pour l'instant",
|
|
751
|
+
emptyBody: "Lancez la discussion. Les commentaires peuvent \xEAtre relus avant d'appara\xEEtre.",
|
|
752
|
+
loading: "Chargement des commentaires",
|
|
753
|
+
loadError: "Les commentaires n'ont pas pu \xEAtre charg\xE9s",
|
|
754
|
+
loadErrorBody: "L'article est intact. Le service de commentaires n'a pas r\xE9pondu.",
|
|
755
|
+
retry: "R\xE9essayer",
|
|
756
|
+
postError: "Votre commentaire n'a pas \xE9t\xE9 publi\xE9. Votre texte est conserv\xE9. V\xE9rifiez votre connexion et r\xE9essayez.",
|
|
757
|
+
tooLong: "Ce commentaire est trop long ou vide. Un commentaire compte de 1 \xE0 4000 caract\xE8res.",
|
|
758
|
+
editClosed: "Un commentaire peut \xEAtre modifi\xE9 pendant dix minutes apr\xE8s sa publication. Ce d\xE9lai est \xE9coul\xE9.",
|
|
759
|
+
actionError: "L'action a \xE9chou\xE9. R\xE9essayez.",
|
|
760
|
+
rateTitle: "Vous commentez trop vite",
|
|
761
|
+
rateBody: "Patientez avant de publier \xE0 nouveau. Votre brouillon est conserv\xE9 dans la zone ci-dessous.",
|
|
762
|
+
rateWait: "Vous pourrez publier \xE0 nouveau dans {n} secondes.",
|
|
763
|
+
bannedTitle: "Vous ne pouvez pas commenter pour le moment",
|
|
764
|
+
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.",
|
|
765
|
+
expired: "Votre session a expir\xE9. Reconnectez-vous pour publier. Votre texte est conserv\xE9.",
|
|
766
|
+
more: "Charger plus de commentaires",
|
|
767
|
+
truncated: "Affichage des 500 premiers commentaires.",
|
|
768
|
+
justNow: "\xE0 l'instant"
|
|
769
|
+
};
|
|
770
|
+
var COMMENT_LABELS_ES = {
|
|
771
|
+
heading: "Comentarios",
|
|
772
|
+
countLabel: "{n} comentarios",
|
|
773
|
+
likeArticle: "Me gusta este art\xEDculo",
|
|
774
|
+
likedArticle: "Te gusta",
|
|
775
|
+
likeArticleSignIn: "(inicia sesi\xF3n), ",
|
|
776
|
+
likeComment: "Me gusta este comentario, ",
|
|
777
|
+
likeCommentSignIn: "Inicia sesi\xF3n para dar me gusta a este comentario, ",
|
|
778
|
+
signInTitle: "Inicia sesi\xF3n para unirte a la conversaci\xF3n",
|
|
779
|
+
signInBody: "Todos pueden leer. Para comentar o dar me gusta, inicia sesi\xF3n.",
|
|
780
|
+
signIn: "Iniciar sesi\xF3n",
|
|
781
|
+
commentingAs: "Comentando como {name}",
|
|
782
|
+
write: "Escribe un comentario",
|
|
783
|
+
placeholder: "A\xF1ade a la conversaci\xF3n",
|
|
784
|
+
help: "Markdown: enlaces, \xE9nfasis, c\xF3digo y citas.",
|
|
785
|
+
chars: "{n} / {max}",
|
|
786
|
+
post: "Publicar comentario",
|
|
787
|
+
posting: "Publicando",
|
|
788
|
+
reply: "Responder",
|
|
789
|
+
replyTo: "Responder a {name}",
|
|
790
|
+
replyPlaceholder: "Escribe una respuesta",
|
|
791
|
+
cancel: "Cancelar",
|
|
792
|
+
edit: "Editar",
|
|
793
|
+
editLeft: "(quedan {n} min)",
|
|
794
|
+
save: "Guardar",
|
|
795
|
+
delete: "Eliminar",
|
|
796
|
+
deleteConfirm: "\xBFEliminar este comentario?",
|
|
797
|
+
keep: "Conservar",
|
|
798
|
+
you: "T\xFA",
|
|
799
|
+
edited: "editado",
|
|
800
|
+
removed: "Este comentario fue eliminado.",
|
|
801
|
+
removedByModerator: "Un moderador elimin\xF3 este comentario.",
|
|
802
|
+
removedByAuthor: "Su autor elimin\xF3 este comentario.",
|
|
803
|
+
depthEnd: "Las respuestas terminan en este nivel",
|
|
804
|
+
held: "Pendiente de aprobaci\xF3n.",
|
|
805
|
+
heldBanner: "Gracias, tu comentario est\xE1 pendiente de aprobaci\xF3n",
|
|
806
|
+
heldBannerBody: "Los comentarios nuevos pueden revisarse primero. Lo ves aqu\xED, marcado como pendiente, hasta que un moderador lo apruebe. Nadie m\xE1s puede verlo todav\xEDa.",
|
|
807
|
+
heldNote: "Solo t\xFA lo ves hasta que un moderador lo apruebe.",
|
|
808
|
+
heldLive: "Comentario pendiente de aprobaci\xF3n",
|
|
809
|
+
postedLive: "Comentario publicado",
|
|
810
|
+
deletedLive: "Comentario eliminado",
|
|
811
|
+
savedLive: "Comentario guardado",
|
|
812
|
+
empty: "A\xFAn no hay comentarios",
|
|
813
|
+
emptyBody: "Empieza la conversaci\xF3n. Los comentarios pueden revisarse antes de aparecer.",
|
|
814
|
+
loading: "Cargando comentarios",
|
|
815
|
+
loadError: "No se pudieron cargar los comentarios",
|
|
816
|
+
loadErrorBody: "El art\xEDculo est\xE1 bien. El servicio de comentarios no respondi\xF3.",
|
|
817
|
+
retry: "Reintentar",
|
|
818
|
+
postError: "Tu comentario no se public\xF3. Hemos conservado tu texto. Revisa tu conexi\xF3n e int\xE9ntalo de nuevo.",
|
|
819
|
+
tooLong: "Ese comentario es demasiado largo o est\xE1 vac\xEDo. Los comentarios tienen de 1 a 4000 caracteres.",
|
|
820
|
+
editClosed: "Un comentario puede editarse durante diez minutos tras publicarlo. Ese tiempo ya pas\xF3.",
|
|
821
|
+
actionError: "No se pudo completar. Int\xE9ntalo de nuevo.",
|
|
822
|
+
rateTitle: "Est\xE1s comentando demasiado r\xE1pido",
|
|
823
|
+
rateBody: "Espera antes de publicar de nuevo. Tu borrador se conserva en el cuadro de abajo.",
|
|
824
|
+
rateWait: "Podr\xE1s publicar de nuevo en {n} segundos.",
|
|
825
|
+
bannedTitle: "No puedes comentar por ahora",
|
|
826
|
+
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.",
|
|
827
|
+
expired: "Tu sesi\xF3n termin\xF3. Inicia sesi\xF3n de nuevo para publicar. Tu texto se conserva.",
|
|
828
|
+
more: "Cargar m\xE1s comentarios",
|
|
829
|
+
truncated: "Se muestran los primeros 500 comentarios.",
|
|
830
|
+
justNow: "ahora mismo"
|
|
831
|
+
};
|
|
832
|
+
|
|
595
833
|
// src/react/viewer/labels.ts
|
|
596
834
|
var VIEWER_LABELS_EN = {
|
|
597
835
|
expand: "Expand diagram",
|
|
@@ -709,6 +947,8 @@ var en = {
|
|
|
709
947
|
fallbackTitle: "Not translated into {language} yet.",
|
|
710
948
|
fallbackBody: "You are reading the original.",
|
|
711
949
|
older: "Older posts",
|
|
950
|
+
viewAll: "View all",
|
|
951
|
+
readAtSource: "Read at source",
|
|
712
952
|
emptyTitle: "Nothing published here yet",
|
|
713
953
|
emptyBody: "Documents published to this section will appear here, newest first.",
|
|
714
954
|
docs: "Documentation",
|
|
@@ -729,7 +969,8 @@ var en = {
|
|
|
729
969
|
unKind: "Unavailable",
|
|
730
970
|
unTitle: "This page is temporarily unavailable",
|
|
731
971
|
unBody: "The content could not be loaded. Please try again in a moment.",
|
|
732
|
-
viewer: VIEWER_LABELS_EN
|
|
972
|
+
viewer: VIEWER_LABELS_EN,
|
|
973
|
+
comments: COMMENT_LABELS_EN
|
|
733
974
|
};
|
|
734
975
|
var fr = {
|
|
735
976
|
toc: "Sur cette page",
|
|
@@ -752,6 +993,8 @@ var fr = {
|
|
|
752
993
|
fallbackTitle: "Pas encore traduit en {language}.",
|
|
753
994
|
fallbackBody: "Vous lisez l'original.",
|
|
754
995
|
older: "Articles plus anciens",
|
|
996
|
+
viewAll: "Tout voir",
|
|
997
|
+
readAtSource: "Lire \xE0 la source",
|
|
755
998
|
emptyTitle: "Rien n'est encore publi\xE9 ici",
|
|
756
999
|
emptyBody: "Les documents publi\xE9s dans cette section appara\xEEtront ici, du plus r\xE9cent au plus ancien.",
|
|
757
1000
|
docs: "Documentation",
|
|
@@ -772,7 +1015,8 @@ var fr = {
|
|
|
772
1015
|
unKind: "Indisponible",
|
|
773
1016
|
unTitle: "Cette page est momentan\xE9ment indisponible",
|
|
774
1017
|
unBody: "Le contenu n'a pas pu \xEAtre charg\xE9. R\xE9essayez dans un instant.",
|
|
775
|
-
viewer: VIEWER_LABELS_FR
|
|
1018
|
+
viewer: VIEWER_LABELS_FR,
|
|
1019
|
+
comments: COMMENT_LABELS_FR
|
|
776
1020
|
};
|
|
777
1021
|
var es = {
|
|
778
1022
|
toc: "En esta p\xE1gina",
|
|
@@ -795,6 +1039,8 @@ var es = {
|
|
|
795
1039
|
fallbackTitle: "A\xFAn no est\xE1 traducida al {language}.",
|
|
796
1040
|
fallbackBody: "Est\xE1s leyendo el original.",
|
|
797
1041
|
older: "Entradas anteriores",
|
|
1042
|
+
viewAll: "Ver todo",
|
|
1043
|
+
readAtSource: "Leer en la fuente",
|
|
798
1044
|
emptyTitle: "A\xFAn no hay nada publicado aqu\xED",
|
|
799
1045
|
emptyBody: "Los documentos publicados en esta secci\xF3n aparecer\xE1n aqu\xED, del m\xE1s reciente al m\xE1s antiguo.",
|
|
800
1046
|
docs: "Documentaci\xF3n",
|
|
@@ -815,7 +1061,8 @@ var es = {
|
|
|
815
1061
|
unKind: "No disponible",
|
|
816
1062
|
unTitle: "Esta p\xE1gina no est\xE1 disponible por el momento",
|
|
817
1063
|
unBody: "No se pudo cargar el contenido. Int\xE9ntalo de nuevo en un momento.",
|
|
818
|
-
viewer: VIEWER_LABELS_ES
|
|
1064
|
+
viewer: VIEWER_LABELS_ES,
|
|
1065
|
+
comments: COMMENT_LABELS_ES
|
|
819
1066
|
};
|
|
820
1067
|
var TABLE = { en, fr, es };
|
|
821
1068
|
function stringsFor(locale) {
|
|
@@ -898,10 +1145,10 @@ function buildComponents(c, s) {
|
|
|
898
1145
|
for (const key of overrides) if (c[key]) defaults[key] = c[key];
|
|
899
1146
|
return defaults;
|
|
900
1147
|
}
|
|
901
|
-
function HastContent({ tree, title, components = {}, locale }) {
|
|
1148
|
+
function HastContent({ tree, title, description, components = {}, locale }) {
|
|
902
1149
|
let root;
|
|
903
1150
|
try {
|
|
904
|
-
root = sanitizeHast(tree, title);
|
|
1151
|
+
root = sanitizeHast(tree, title, description);
|
|
905
1152
|
} catch (error) {
|
|
906
1153
|
if (!(error instanceof HastLimitError)) throw error;
|
|
907
1154
|
const s = stringsFor(locale);
|
|
@@ -927,6 +1174,7 @@ function TrustedServerHtml({ html }) {
|
|
|
927
1174
|
var import_mermaid_diagram2 = require("./mermaid-diagram.cjs");
|
|
928
1175
|
|
|
929
1176
|
// src/react/pages.tsx
|
|
1177
|
+
var import_comments = require("./comments.cjs");
|
|
930
1178
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
931
1179
|
function Slot({ name, slots, tag: Tag = "div", className }) {
|
|
932
1180
|
const fill = slots?.[name];
|
|
@@ -995,7 +1243,7 @@ function Toc({ toc, c, aside }) {
|
|
|
995
1243
|
}
|
|
996
1244
|
function Body({ article, components, locale }) {
|
|
997
1245
|
const { content, publication } = article;
|
|
998
|
-
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, components: components ?? {}, locale }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TrustedServerHtml, { html: content.html }) });
|
|
1246
|
+
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 }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TrustedServerHtml, { html: content.html }) });
|
|
999
1247
|
}
|
|
1000
1248
|
function Languages({ alternates, current, c }) {
|
|
1001
1249
|
if (alternates.length < 2) return null;
|
|
@@ -1008,7 +1256,33 @@ function Languages({ alternates, current, c }) {
|
|
|
1008
1256
|
}) })
|
|
1009
1257
|
] });
|
|
1010
1258
|
}
|
|
1011
|
-
|
|
1259
|
+
var BARE_HTTPS_ORIGIN = /^https:\/\/[^/]+$/;
|
|
1260
|
+
function articleJsonLd(article, origin, c, author) {
|
|
1261
|
+
const { publication: pub } = article;
|
|
1262
|
+
const url = (path) => origin + encodeURI(c.href(path, pub.locale));
|
|
1263
|
+
const graph = {
|
|
1264
|
+
"@context": "https://schema.org",
|
|
1265
|
+
"@graph": [
|
|
1266
|
+
{
|
|
1267
|
+
"@type": "BlogPosting",
|
|
1268
|
+
headline: pub.title,
|
|
1269
|
+
...pub.description ? { description: pub.description } : {},
|
|
1270
|
+
datePublished: pub.published_at,
|
|
1271
|
+
// a save before the publish leaves updated_at earlier than published_at; dateModified before datePublished is invalid
|
|
1272
|
+
...pub.updated_at && !(Date.parse(pub.updated_at) < Date.parse(pub.published_at)) ? { dateModified: pub.updated_at } : {},
|
|
1273
|
+
...author ? { author: { "@type": "Person", name: author } } : {},
|
|
1274
|
+
inLanguage: pub.locale,
|
|
1275
|
+
mainEntityOfPage: url(pub.canonical_path)
|
|
1276
|
+
},
|
|
1277
|
+
{
|
|
1278
|
+
"@type": "BreadcrumbList",
|
|
1279
|
+
itemListElement: article.breadcrumbs.map((b, i) => ({ "@type": "ListItem", position: i + 1, name: b.title, item: url(b.canonical_path) }))
|
|
1280
|
+
}
|
|
1281
|
+
]
|
|
1282
|
+
};
|
|
1283
|
+
return JSON.stringify(graph).replace(/</g, "\\u003c");
|
|
1284
|
+
}
|
|
1285
|
+
function ArticlePage({ article, engagement, origin, ...base }) {
|
|
1012
1286
|
const { publication: pub } = article;
|
|
1013
1287
|
const c = ctx(base, pub.locale);
|
|
1014
1288
|
const { s } = c;
|
|
@@ -1053,9 +1327,11 @@ function ArticlePage({ article, ...base }) {
|
|
|
1053
1327
|
] }),
|
|
1054
1328
|
toc.narrow,
|
|
1055
1329
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
1330
|
+
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,
|
|
1056
1331
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Pager, { prev: article.prev, next: article.next, c }),
|
|
1057
1332
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.after", slots: base.slots, className: "hyle-after" }),
|
|
1058
|
-
toc.wide
|
|
1333
|
+
toc.wide,
|
|
1334
|
+
origin && BARE_HTTPS_ORIGIN.test(origin) ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("script", { type: "application/ld+json", dangerouslySetInnerHTML: { __html: articleJsonLd(article, origin, c, author) } }) : null
|
|
1059
1335
|
] }) });
|
|
1060
1336
|
}
|
|
1061
1337
|
function ListPage({ list, olderHref, description, ...base }) {
|
|
@@ -1104,9 +1380,250 @@ function ListPage({ list, olderHref, description, ...base }) {
|
|
|
1104
1380
|
] }) });
|
|
1105
1381
|
}
|
|
1106
1382
|
|
|
1383
|
+
// src/react/index.ts
|
|
1384
|
+
var import_comments2 = require("./comments.cjs");
|
|
1385
|
+
|
|
1386
|
+
// src/react/comments-api.ts
|
|
1387
|
+
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1388
|
+
var count = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.trunc(v) : 0;
|
|
1389
|
+
function toComment(raw) {
|
|
1390
|
+
if (!isObject2(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string") return void 0;
|
|
1391
|
+
const depth = typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1;
|
|
1392
|
+
const author = isObject2(raw.author) && typeof raw.author.name === "string" ? raw.author.name : void 0;
|
|
1393
|
+
const name = typeof raw.author_name === "string" ? raw.author_name : author;
|
|
1394
|
+
const body = isObject2(raw.body) && raw.body.format === "hast" ? { format: "hast", tree: raw.body.tree } : null;
|
|
1395
|
+
const removed = raw.removed === true || body === null;
|
|
1396
|
+
return {
|
|
1397
|
+
id: raw.id,
|
|
1398
|
+
parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
|
|
1399
|
+
depth,
|
|
1400
|
+
author_name: name ?? null,
|
|
1401
|
+
created_at: raw.created_at,
|
|
1402
|
+
edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
|
|
1403
|
+
like_count: count(raw.like_count),
|
|
1404
|
+
removed,
|
|
1405
|
+
...removed && (raw.removed_by === "moderator" || raw.removed_by === "author") ? { removed_by: raw.removed_by } : {},
|
|
1406
|
+
body,
|
|
1407
|
+
// Viewer members exist only on a live comment of a viewer-aware listing; a tombstone never carries them.
|
|
1408
|
+
...!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 } : {}
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
function toHeld(raw) {
|
|
1412
|
+
if (!isObject2(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string" || !isObject2(raw.body) || raw.body.format !== "hast") return void 0;
|
|
1413
|
+
const author = isObject2(raw.author) && typeof raw.author.name === "string" ? raw.author.name : null;
|
|
1414
|
+
return {
|
|
1415
|
+
id: raw.id,
|
|
1416
|
+
parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
|
|
1417
|
+
depth: typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1,
|
|
1418
|
+
author_name: author,
|
|
1419
|
+
created_at: raw.created_at,
|
|
1420
|
+
edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
|
|
1421
|
+
can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null,
|
|
1422
|
+
body: { format: "hast", tree: raw.body.tree }
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
function parseListing(data) {
|
|
1426
|
+
if (!isObject2(data) || data.kind !== "comments" || !Array.isArray(data.comments)) return void 0;
|
|
1427
|
+
const comments = data.comments.map(toComment).filter((c) => c !== void 0);
|
|
1428
|
+
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) } : {};
|
|
1429
|
+
return { cp: 1, kind: "comments", publication_id: String(data.publication_id ?? ""), comment_count: count(data.comment_count), like_count: count(data.like_count), truncated: data.truncated === true, comments, ...viewer };
|
|
1430
|
+
}
|
|
1431
|
+
var untilMs = (iso) => {
|
|
1432
|
+
const t = iso ? Date.parse(iso) : NaN;
|
|
1433
|
+
return Number.isFinite(t) ? t : void 0;
|
|
1434
|
+
};
|
|
1435
|
+
function buildThread(listing, localHeld) {
|
|
1436
|
+
const byId = /* @__PURE__ */ new Map();
|
|
1437
|
+
const roots = [];
|
|
1438
|
+
const place = (node, parentId) => {
|
|
1439
|
+
const parent = parentId ? byId.get(parentId) : void 0;
|
|
1440
|
+
(parent ? parent.kids : roots).push(node);
|
|
1441
|
+
};
|
|
1442
|
+
for (const c of listing.comments) {
|
|
1443
|
+
if (byId.has(c.id)) continue;
|
|
1444
|
+
const removed = c.removed;
|
|
1445
|
+
const node = {
|
|
1446
|
+
id: c.id,
|
|
1447
|
+
depth: c.depth,
|
|
1448
|
+
status: removed ? "removed" : "visible",
|
|
1449
|
+
removedBy: removed ? c.removed_by : void 0,
|
|
1450
|
+
mine: !removed && c.mine === true,
|
|
1451
|
+
canEditUntil: untilMs(c.can_edit_until),
|
|
1452
|
+
likedByMe: !removed && c.liked_by_me === true,
|
|
1453
|
+
name: removed ? null : c.author_name ?? null,
|
|
1454
|
+
createdAt: c.created_at,
|
|
1455
|
+
editedAt: c.edited_at,
|
|
1456
|
+
likes: c.like_count,
|
|
1457
|
+
tree: c.body?.tree,
|
|
1458
|
+
text: void 0,
|
|
1459
|
+
kids: []
|
|
1460
|
+
};
|
|
1461
|
+
place(node, c.parent_id === c.id ? null : c.parent_id);
|
|
1462
|
+
byId.set(c.id, node);
|
|
1463
|
+
}
|
|
1464
|
+
const mine = [];
|
|
1465
|
+
const addHeld = (node, parentId, oldestFirst) => {
|
|
1466
|
+
const parent = parentId ? byId.get(parentId) : void 0;
|
|
1467
|
+
if (parent) parent.kids.push(node);
|
|
1468
|
+
else if (oldestFirst) mine.unshift(node);
|
|
1469
|
+
else mine.push(node);
|
|
1470
|
+
};
|
|
1471
|
+
const heldIds = /* @__PURE__ */ new Set();
|
|
1472
|
+
for (const h of listing.mine_held ?? []) {
|
|
1473
|
+
heldIds.add(h.id);
|
|
1474
|
+
const parent = h.parent_id ? byId.get(h.parent_id) : void 0;
|
|
1475
|
+
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);
|
|
1476
|
+
}
|
|
1477
|
+
if (listing.mine_held === void 0) {
|
|
1478
|
+
for (const h of localHeld) {
|
|
1479
|
+
if (byId.has(h.id) || heldIds.has(h.id)) continue;
|
|
1480
|
+
const parent = h.parentId ? byId.get(h.parentId) : void 0;
|
|
1481
|
+
addHeld({ id: h.id, depth: Math.min(4, (parent?.depth ?? 0) + 1), status: "held", removedBy: void 0, mine: true, canEditUntil: void 0, likedByMe: false, name: h.name, createdAt: h.createdAt, editedAt: null, likes: 0, tree: void 0, text: h.text, kids: [] }, h.parentId, false);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
return [...mine, ...roots];
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
// src/react/comments-body.tsx
|
|
1488
|
+
var import_hast_util_to_jsx_runtime2 = require("hast-util-to-jsx-runtime");
|
|
1489
|
+
var import_react2 = require("react");
|
|
1490
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1491
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1492
|
+
var ALLOWED = /* @__PURE__ */ new Set(["p", "a", "em", "strong", "del", "code", "pre", "blockquote", "ul", "ol", "li", "br"]);
|
|
1493
|
+
var LINK_REL = "nofollow ugc noopener noreferrer";
|
|
1494
|
+
function narrow(node) {
|
|
1495
|
+
if (node.type === "text") return [node];
|
|
1496
|
+
if (node.type !== "element") return [];
|
|
1497
|
+
const children = node.children.flatMap(narrow);
|
|
1498
|
+
if (!ALLOWED.has(node.tagName)) return children;
|
|
1499
|
+
if (node.tagName === "a") {
|
|
1500
|
+
const href = node.properties.href;
|
|
1501
|
+
if (!isSafeUrl(href, "href")) return children;
|
|
1502
|
+
return [{ type: "element", tagName: "a", properties: { href: String(href), rel: LINK_REL.split(" ") }, children }];
|
|
1503
|
+
}
|
|
1504
|
+
return [{ type: "element", tagName: node.tagName, properties: {}, children: node.tagName === "br" ? [] : children }];
|
|
1505
|
+
}
|
|
1506
|
+
function CommentBody({ tree }) {
|
|
1507
|
+
let children;
|
|
1508
|
+
try {
|
|
1509
|
+
children = sanitizeHast(tree).children.flatMap((n) => narrow(n));
|
|
1510
|
+
} catch (error) {
|
|
1511
|
+
if (error instanceof HastLimitError) return null;
|
|
1512
|
+
throw error;
|
|
1513
|
+
}
|
|
1514
|
+
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_react2.Fragment, jsx: import_jsx_runtime5.jsx, jsxs: import_jsx_runtime5.jsxs, elementAttributeNameCase: "react", stylePropertyNameCase: "dom" }) });
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
// src/react/embed.tsx
|
|
1518
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1519
|
+
function HyleListView({ items, layout = "list", title, headingLevel = 2, moreHref, ...base }) {
|
|
1520
|
+
const c = ctx(base, "en");
|
|
1521
|
+
const { s, Link } = c;
|
|
1522
|
+
const Row = base.slots?.["list.item"];
|
|
1523
|
+
const Heading = `h${headingLevel}`;
|
|
1524
|
+
const safe = items.filter((item) => item.canonical_path.startsWith("/"));
|
|
1525
|
+
if (safe.length === 0) return base.slots?.["list.empty"] ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle hyle-embed", "data-layout": layout, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Slot, { name: "list.empty", slots: base.slots }) }) : null;
|
|
1526
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle hyle-embed", "data-layout": layout, lang: c.locale, children: [
|
|
1527
|
+
title ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Heading, { className: "hyle-title", children: title }) : null,
|
|
1528
|
+
/* @__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: [
|
|
1529
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: item.published_at, title: item.published_at, children: formatDate(item.published_at, c.locale) }),
|
|
1530
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
1531
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "t", children: item.title }),
|
|
1532
|
+
item.description ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: item.description }) : null
|
|
1533
|
+
] })
|
|
1534
|
+
] }) }, item.canonical_path)) }),
|
|
1535
|
+
moreHref ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { className: "hyle-more", href: moreHref, children: s.viewAll }) : null
|
|
1536
|
+
] });
|
|
1537
|
+
}
|
|
1538
|
+
function HyleArticleView({ article, headingLevel = 2, ...base }) {
|
|
1539
|
+
const { publication: pub } = article;
|
|
1540
|
+
const c = ctx(base, pub.locale);
|
|
1541
|
+
const Heading = `h${headingLevel}`;
|
|
1542
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle hyle-embed", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("article", { lang: c.locale, children: [
|
|
1543
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("header", { className: "hyle-head", children: [
|
|
1544
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Heading, { className: "hyle-title", children: pub.title }),
|
|
1545
|
+
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
1546
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-meta", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: pub.published_at, title: pub.published_at, children: formatDate(pub.published_at, c.locale) }) }) })
|
|
1547
|
+
] }),
|
|
1548
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
1549
|
+
pub.canonical_path.startsWith("/") ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("a", { className: "hyle-more", href: c.href(pub.canonical_path, pub.locale), rel: "bookmark", children: [
|
|
1550
|
+
c.s.readAtSource,
|
|
1551
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "hyle-sr", children: [
|
|
1552
|
+
": ",
|
|
1553
|
+
pub.title
|
|
1554
|
+
] })
|
|
1555
|
+
] }) : null
|
|
1556
|
+
] }) });
|
|
1557
|
+
}
|
|
1558
|
+
var initials = (name) => name.trim().split(/\s+/).slice(0, 2).map((w) => [...w][0] ?? "").join("").toUpperCase() || "?";
|
|
1559
|
+
function StaticThread({ nodes, locale, s, level = 1 }) {
|
|
1560
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ol", { className: "hyle-cm-list", role: "list", children: nodes.map((node) => {
|
|
1561
|
+
const kids = node.kids.length > 0 && level < 32 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StaticThread, { nodes: node.kids, locale, s, level: level + 1 }) : null;
|
|
1562
|
+
if (node.status === "removed") {
|
|
1563
|
+
const why = node.removedBy === "moderator" ? s.removedByModerator : node.removedBy === "author" ? s.removedByAuthor : s.removed;
|
|
1564
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { className: "hyle-cm", "data-depth": node.depth, "data-status": "removed", "data-removed-by": node.removedBy, children: [
|
|
1565
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("article", { "aria-label": why, children: [
|
|
1566
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "ban" }) }),
|
|
1567
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-cm-main", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-cm-body", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: why }) }) })
|
|
1568
|
+
] }),
|
|
1569
|
+
kids
|
|
1570
|
+
] }, node.id);
|
|
1571
|
+
}
|
|
1572
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { className: "hyle-cm", "data-depth": node.depth, "data-status": "visible", children: [
|
|
1573
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("article", { children: [
|
|
1574
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: initials(node.name ?? "") }),
|
|
1575
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-main", children: [
|
|
1576
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-by", children: [
|
|
1577
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: node.name }),
|
|
1578
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
1579
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: node.createdAt, title: node.createdAt, children: formatDate(node.createdAt, locale) }),
|
|
1580
|
+
node.editedAt ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1581
|
+
" ",
|
|
1582
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { "aria-hidden": "true", children: "\xB7" }),
|
|
1583
|
+
" ",
|
|
1584
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: s.edited })
|
|
1585
|
+
] }) : null
|
|
1586
|
+
] })
|
|
1587
|
+
] }),
|
|
1588
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CommentBody, { tree: node.tree })
|
|
1589
|
+
] })
|
|
1590
|
+
] }),
|
|
1591
|
+
kids
|
|
1592
|
+
] }, node.id);
|
|
1593
|
+
}) });
|
|
1594
|
+
}
|
|
1595
|
+
function HyleCommentsView({ listing, locale }) {
|
|
1596
|
+
const thread = buildThread(listing, []);
|
|
1597
|
+
if (thread.length === 0) return null;
|
|
1598
|
+
const s = stringsFor(locale).comments;
|
|
1599
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle hyle-embed", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: "hyle-comments", "aria-label": s.heading, "data-slot-component": "Comments", lang: locale, children: [
|
|
1600
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-cm-head", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("h2", { children: [
|
|
1601
|
+
s.heading,
|
|
1602
|
+
" ",
|
|
1603
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-cm-count", "aria-label": s.countLabel.replace("{n}", String(listing.comment_count)), children: listing.comment_count })
|
|
1604
|
+
] }) }),
|
|
1605
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StaticThread, { nodes: thread, locale, s }),
|
|
1606
|
+
listing.truncated ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-cm-note", children: s.truncated }) : null
|
|
1607
|
+
] }) });
|
|
1608
|
+
}
|
|
1609
|
+
function HyleCommentsFallback({ locale }) {
|
|
1610
|
+
const s = stringsFor(locale).comments;
|
|
1611
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle hyle-embed", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("section", { className: "hyle-comments", "aria-label": s.heading, "data-slot-component": "Comments", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { role: "status", "aria-live": "polite", "aria-busy": "true", children: [
|
|
1612
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sr", children: s.loading }),
|
|
1613
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { "aria-hidden": "true", children: [0, 1, 2].map((i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-sk", children: [
|
|
1614
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk c" }),
|
|
1615
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
1616
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: 120 } }),
|
|
1617
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: "100%" } }),
|
|
1618
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: "72%" } })
|
|
1619
|
+
] })
|
|
1620
|
+
] }, i)) })
|
|
1621
|
+
] }) }) });
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1107
1624
|
// src/react/docs.tsx
|
|
1108
1625
|
var import_docs_enhance = require("./docs-enhance.cjs");
|
|
1109
|
-
var
|
|
1626
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1110
1627
|
var ROOT_ID = "hyle-docs";
|
|
1111
1628
|
var NAV_ID = "hyle-docs-nav";
|
|
1112
1629
|
function navTreeOf(article) {
|
|
@@ -1130,15 +1647,15 @@ function pathTo(nodes, path) {
|
|
|
1130
1647
|
}
|
|
1131
1648
|
function Branch({ nodes, current, onPath, c }) {
|
|
1132
1649
|
const { Link } = c;
|
|
1133
|
-
return /* @__PURE__ */ (0,
|
|
1134
|
-
const link = /* @__PURE__ */ (0,
|
|
1135
|
-
if (node.children.length === 0) return /* @__PURE__ */ (0,
|
|
1136
|
-
return /* @__PURE__ */ (0,
|
|
1137
|
-
/* @__PURE__ */ (0,
|
|
1138
|
-
/* @__PURE__ */ (0,
|
|
1650
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { children: nodes.map((node) => {
|
|
1651
|
+
const link = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Link, { href: c.href(node.canonical_path), ...node.canonical_path === current ? { "aria-current": "page" } : {}, children: node.title });
|
|
1652
|
+
if (node.children.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { children: link }, node.canonical_path);
|
|
1653
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("details", { ...onPath.has(node.canonical_path) ? { open: true } : {}, children: [
|
|
1654
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("summary", { children: [
|
|
1655
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "chev" }),
|
|
1139
1656
|
link
|
|
1140
1657
|
] }),
|
|
1141
|
-
/* @__PURE__ */ (0,
|
|
1658
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Branch, { nodes: node.children, current, onPath, c })
|
|
1142
1659
|
] }) }, node.canonical_path);
|
|
1143
1660
|
}) });
|
|
1144
1661
|
}
|
|
@@ -1152,47 +1669,47 @@ function DocsPage({ article, ...base }) {
|
|
|
1152
1669
|
const siteName = article.breadcrumbs[0]?.title ?? "";
|
|
1153
1670
|
const headingIds = article.toc.filter((t) => t.depth === 2 || t.depth === 3).map((t) => scopeId(t.id));
|
|
1154
1671
|
const notTranslated = article.fallback ? s.fallbackTitle.replace("{language}", languageName(article.fallback.requested_locale, c.locale)) : void 0;
|
|
1155
|
-
return /* @__PURE__ */ (0,
|
|
1156
|
-
/* @__PURE__ */ (0,
|
|
1157
|
-
/* @__PURE__ */ (0,
|
|
1158
|
-
/* @__PURE__ */ (0,
|
|
1672
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-docs", id: ROOT_ID, lang: c.locale, children: [
|
|
1673
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_docs_enhance.DocsEnhance, { headingIds, rootId: ROOT_ID }),
|
|
1674
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("button", { type: "button", className: "hyle-nav-bar", popoverTarget: NAV_ID, children: [
|
|
1675
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "file" }),
|
|
1159
1676
|
s.menu,
|
|
1160
|
-
/* @__PURE__ */ (0,
|
|
1161
|
-
/* @__PURE__ */ (0,
|
|
1677
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "cur", children: pub.title }),
|
|
1678
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "chev-down", className: "hyle-chev" })
|
|
1162
1679
|
] }),
|
|
1163
|
-
/* @__PURE__ */ (0,
|
|
1164
|
-
/* @__PURE__ */ (0,
|
|
1165
|
-
/* @__PURE__ */ (0,
|
|
1166
|
-
/* @__PURE__ */ (0,
|
|
1167
|
-
/* @__PURE__ */ (0,
|
|
1680
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("aside", { className: "hyle-nav-d", id: NAV_ID, popover: "auto", "aria-label": s.docs, children: [
|
|
1681
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-side-head", children: [
|
|
1682
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("b", { children: siteName }),
|
|
1683
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "docs.version", slots: base.slots, tag: "span" }),
|
|
1684
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "hyle-nav-x", popoverTarget: NAV_ID, popoverTargetAction: "hide", "aria-label": s.closeMenu, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "x" }) })
|
|
1168
1685
|
] }),
|
|
1169
|
-
/* @__PURE__ */ (0,
|
|
1170
|
-
/* @__PURE__ */ (0,
|
|
1171
|
-
/* @__PURE__ */ (0,
|
|
1686
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "docs.sidebar-header", slots: base.slots, className: "hyle-side-slot" }),
|
|
1687
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("nav", { className: "hyle-tree", "aria-label": s.docs, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Branch, { nodes: tree, current: pub.canonical_path, onPath, c }) }),
|
|
1688
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "docs.sidebar-footer", slots: base.slots, className: "hyle-side-slot" })
|
|
1172
1689
|
] }),
|
|
1173
|
-
/* @__PURE__ */ (0,
|
|
1174
|
-
notTranslated ? /* @__PURE__ */ (0,
|
|
1175
|
-
/* @__PURE__ */ (0,
|
|
1176
|
-
/* @__PURE__ */ (0,
|
|
1177
|
-
/* @__PURE__ */ (0,
|
|
1690
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-docs-main", "data-hyle-page": "docs", children: [
|
|
1691
|
+
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1692
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "alert" }),
|
|
1693
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
|
|
1694
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("b", { children: notTranslated }),
|
|
1178
1695
|
" ",
|
|
1179
1696
|
s.fallbackBody
|
|
1180
1697
|
] })
|
|
1181
1698
|
] }) : null,
|
|
1182
|
-
/* @__PURE__ */ (0,
|
|
1183
|
-
/* @__PURE__ */ (0,
|
|
1184
|
-
pub.description ? /* @__PURE__ */ (0,
|
|
1185
|
-
/* @__PURE__ */ (0,
|
|
1186
|
-
/* @__PURE__ */ (0,
|
|
1699
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("nav", { className: "hyle-crumbs", "aria-label": s.crumbs, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ol", { children: article.breadcrumbs.map((b, i) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { "aria-current": i === article.breadcrumbs.length - 1 ? "page" : void 0, children: i === article.breadcrumbs.length - 1 ? b.title : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Link, { href: c.href(b.canonical_path), children: b.title }) }, b.canonical_path)) }) }),
|
|
1700
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h1", { className: "hyle-title", children: pub.title }),
|
|
1701
|
+
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
1702
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("p", { className: "hyle-updated", children: [
|
|
1703
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "calendar" }),
|
|
1187
1704
|
s.updated,
|
|
1188
1705
|
" ",
|
|
1189
|
-
/* @__PURE__ */ (0,
|
|
1706
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("time", { dateTime: pub.updated_at, title: pub.updated_at, children: formatDate(pub.updated_at, c.locale) })
|
|
1190
1707
|
] }),
|
|
1191
1708
|
toc.narrow,
|
|
1192
|
-
/* @__PURE__ */ (0,
|
|
1193
|
-
/* @__PURE__ */ (0,
|
|
1194
|
-
/* @__PURE__ */ (0,
|
|
1195
|
-
/* @__PURE__ */ (0,
|
|
1709
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
1710
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Pager, { prev: article.prev, next: article.next, c }),
|
|
1711
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "docs.after", slots: base.slots, className: "hyle-after" }),
|
|
1712
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "hyle-docs-end", "aria-hidden": "true" })
|
|
1196
1713
|
] }),
|
|
1197
1714
|
toc.wide
|
|
1198
1715
|
] }) });
|
|
@@ -1281,7 +1798,7 @@ function isRejectedRequest(error) {
|
|
|
1281
1798
|
}
|
|
1282
1799
|
|
|
1283
1800
|
// src/next/page.tsx
|
|
1284
|
-
var
|
|
1801
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1285
1802
|
function hylePage(options) {
|
|
1286
1803
|
const resolve = resolverFor(options);
|
|
1287
1804
|
return async function HylePage({ params, searchParams }) {
|
|
@@ -1293,13 +1810,13 @@ function hylePage(options) {
|
|
|
1293
1810
|
switch (result.kind) {
|
|
1294
1811
|
case "article": {
|
|
1295
1812
|
const props = { article: result, components: options.components, slots: options.slots, locale, toHref };
|
|
1296
|
-
return options.layout === "docs" ? /* @__PURE__ */ (0,
|
|
1813
|
+
return options.layout === "docs" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DocsPage, { ...props }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ArticlePage, { ...props, origin: options.siteOrigin, ...options.engagement ? { engagement: options.engagement } : {} });
|
|
1297
1814
|
}
|
|
1298
1815
|
case "list": {
|
|
1299
1816
|
const list = options.list?.title ? { ...result, section: { ...result.section, title: options.list.title } } : result;
|
|
1300
1817
|
const next = options.paginate === "searchParams" ? validCursor(result.next_cursor) : void 0;
|
|
1301
1818
|
const olderHref = next ? `${toHref(path)}?cursor=${next}` : void 0;
|
|
1302
|
-
return /* @__PURE__ */ (0,
|
|
1819
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ListPage, { list, ...olderHref ? { olderHref } : {}, ...options.list?.description ? { description: options.list.description } : {}, components: options.components, slots: options.slots, locale, toHref });
|
|
1303
1820
|
}
|
|
1304
1821
|
case "redirect": {
|
|
1305
1822
|
const to = safeRedirectTarget(result.to);
|
|
@@ -1355,26 +1872,36 @@ async function hyleSitemap(options) {
|
|
|
1355
1872
|
// src/next/metadata.ts
|
|
1356
1873
|
function hyleMetadata(options) {
|
|
1357
1874
|
const resolve = resolverFor(options);
|
|
1358
|
-
return async function generateMetadata({ params }) {
|
|
1875
|
+
return async function generateMetadata({ params, searchParams }) {
|
|
1359
1876
|
const { path, locale, toHref } = routeContext(options, await params ?? {});
|
|
1360
1877
|
if (path === void 0) return {};
|
|
1361
1878
|
try {
|
|
1362
|
-
const
|
|
1879
|
+
const cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
1880
|
+
const result = await resolve(path, locale, options.listLimit, cursor, options.layout === "docs" ? "tree" : void 0);
|
|
1363
1881
|
if (result.kind === "list") {
|
|
1364
|
-
const title = options.list?.title || result.section.title;
|
|
1882
|
+
const title = (options.list?.title || result.section.title) + (cursor ? ` - ${stringsFor(locale).older}` : "");
|
|
1365
1883
|
const description2 = options.list?.description;
|
|
1366
|
-
return {
|
|
1884
|
+
return {
|
|
1885
|
+
title,
|
|
1886
|
+
...description2 ? { description: description2 } : {},
|
|
1887
|
+
alternates: { canonical: toHref(path) + (cursor ? `?cursor=${cursor}` : "") },
|
|
1888
|
+
openGraph: { title, ...description2 ? { description: description2 } : {} }
|
|
1889
|
+
};
|
|
1367
1890
|
}
|
|
1368
1891
|
if (result.kind !== "article") return {};
|
|
1369
|
-
const { publication: pub, alternates } = result;
|
|
1892
|
+
const { publication: pub, alternates, default_locale } = result;
|
|
1370
1893
|
const canonical = toHref(pub.canonical_path, pub.locale);
|
|
1894
|
+
const defaultAlternate = alternates.find((a) => a.locale === default_locale);
|
|
1895
|
+
const xDefault = defaultAlternate ? toHref(defaultAlternate.canonical_path, defaultAlternate.locale) : canonical;
|
|
1371
1896
|
const description = pub.description ?? void 0;
|
|
1897
|
+
const author = typeof result.frontmatter.author === "string" ? result.frontmatter.author : void 0;
|
|
1898
|
+
const modified = pub.updated_at && !(Date.parse(pub.updated_at) < Date.parse(pub.published_at)) ? pub.updated_at : void 0;
|
|
1372
1899
|
return {
|
|
1373
1900
|
title: pub.title,
|
|
1374
1901
|
...description ? { description } : {},
|
|
1375
1902
|
alternates: {
|
|
1376
1903
|
canonical,
|
|
1377
|
-
...alternates.length > 1 ? { languages: Object.fromEntries(alternates.map((a) => [a.locale, toHref(a.canonical_path, a.locale)])) } : {}
|
|
1904
|
+
...alternates.length > 1 ? { languages: { ...Object.fromEntries(alternates.map((a) => [a.locale, toHref(a.canonical_path, a.locale)])), "x-default": xDefault } } : {}
|
|
1378
1905
|
},
|
|
1379
1906
|
openGraph: {
|
|
1380
1907
|
type: "article",
|
|
@@ -1383,7 +1910,8 @@ function hyleMetadata(options) {
|
|
|
1383
1910
|
url: canonical,
|
|
1384
1911
|
locale: pub.locale,
|
|
1385
1912
|
publishedTime: pub.published_at,
|
|
1386
|
-
modifiedTime:
|
|
1913
|
+
...modified ? { modifiedTime: modified } : {},
|
|
1914
|
+
...author ? { authors: [author] } : {}
|
|
1387
1915
|
}
|
|
1388
1916
|
};
|
|
1389
1917
|
} catch (error) {
|
|
@@ -1393,6 +1921,48 @@ function hyleMetadata(options) {
|
|
|
1393
1921
|
};
|
|
1394
1922
|
}
|
|
1395
1923
|
|
|
1924
|
+
// src/next/feed.ts
|
|
1925
|
+
var import_navigation3 = require("next/navigation");
|
|
1926
|
+
var xml = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
1927
|
+
var tag = (name, value) => `<${name}>${xml(value)}</${name}>`;
|
|
1928
|
+
var response = (body, status, headers) => new Response(body, { status, ...headers ? { headers } : {} });
|
|
1929
|
+
async function hyleFeed(options) {
|
|
1930
|
+
const origin = options.siteOrigin;
|
|
1931
|
+
if (!origin || !BARE_HTTPS_ORIGIN.test(origin)) {
|
|
1932
|
+
console.error("hyle: hyleFeed needs `siteOrigin`, a bare https origin such as https://example.com");
|
|
1933
|
+
return response(null, 404);
|
|
1934
|
+
}
|
|
1935
|
+
const { path, locale, toHref } = routeContext(options, {});
|
|
1936
|
+
if (path === void 0) return response(null, 404);
|
|
1937
|
+
const url = (sitePath) => origin + encodeURI(toHref(sitePath));
|
|
1938
|
+
try {
|
|
1939
|
+
const result = await resolverFor(options)(path, locale, options.limit ?? 50);
|
|
1940
|
+
if (result.kind !== "list") return response(null, 503);
|
|
1941
|
+
const items = result.items.filter((item) => item.canonical_path.startsWith("/")).map((item) => {
|
|
1942
|
+
const link = url(item.canonical_path);
|
|
1943
|
+
const published = new Date(item.published_at);
|
|
1944
|
+
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>`;
|
|
1945
|
+
});
|
|
1946
|
+
const channel = [
|
|
1947
|
+
tag("title", options.list?.title || result.section.title),
|
|
1948
|
+
tag("link", url(path)),
|
|
1949
|
+
tag("description", options.list?.description ?? ""),
|
|
1950
|
+
locale ? tag("language", locale) : "",
|
|
1951
|
+
`<atom:link href="${xml(origin + encodeURI(options.feedPath ?? "/feed.xml"))}" rel="self" type="application/rss+xml"/>`,
|
|
1952
|
+
...items
|
|
1953
|
+
].join("");
|
|
1954
|
+
return response(
|
|
1955
|
+
`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel>${channel}</channel></rss>`,
|
|
1956
|
+
200,
|
|
1957
|
+
{ "content-type": "application/rss+xml; charset=utf-8" }
|
|
1958
|
+
);
|
|
1959
|
+
} catch (error) {
|
|
1960
|
+
(0, import_navigation3.unstable_rethrow)(error);
|
|
1961
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
1962
|
+
return response(null, 503);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1396
1966
|
// src/next/revalidate.ts
|
|
1397
1967
|
var import_cache = require("next/cache");
|
|
1398
1968
|
var isSwitchedOff = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
@@ -1407,7 +1977,7 @@ function createRevalidateRoute(options) {
|
|
|
1407
1977
|
if (!workspaceId || secrets.length === 0) return new Response(null, { status: 503 });
|
|
1408
1978
|
const key = `${workspaceId}\0${secrets.join("\0")}`;
|
|
1409
1979
|
if (cached?.key !== key) {
|
|
1410
|
-
cached = { key, route: createRevalidationCallbackRoute({ workspaceId, secrets, revalidateTag: (
|
|
1980
|
+
cached = { key, route: createRevalidationCallbackRoute({ workspaceId, secrets, revalidateTag: (tag2) => (0, import_cache.revalidateTag)(tag2, { expire: 0 }) }) };
|
|
1411
1981
|
}
|
|
1412
1982
|
return cached.route.POST(req);
|
|
1413
1983
|
}
|
|
@@ -1415,7 +1985,7 @@ function createRevalidateRoute(options) {
|
|
|
1415
1985
|
}
|
|
1416
1986
|
|
|
1417
1987
|
// src/next/root.ts
|
|
1418
|
-
var
|
|
1988
|
+
var import_navigation4 = require("next/navigation");
|
|
1419
1989
|
|
|
1420
1990
|
// src/next/mount-match.ts
|
|
1421
1991
|
function activeMounts(mounts) {
|
|
@@ -1509,7 +2079,7 @@ function hyleRootPage(options) {
|
|
|
1509
2079
|
const route = createRouter(options, hylePage);
|
|
1510
2080
|
return async function HyleRootPage({ params, searchParams }) {
|
|
1511
2081
|
const hit = await route(await params ?? {});
|
|
1512
|
-
if (!hit) (0,
|
|
2082
|
+
if (!hit) (0, import_navigation4.notFound)();
|
|
1513
2083
|
return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
|
|
1514
2084
|
};
|
|
1515
2085
|
}
|
|
@@ -1606,12 +2176,374 @@ function createAssetRoute(options) {
|
|
|
1606
2176
|
}
|
|
1607
2177
|
return { GET: (req, ctx2) => serve(req, ctx2, false), HEAD: (req, ctx2) => serve(req, ctx2, true) };
|
|
1608
2178
|
}
|
|
2179
|
+
|
|
2180
|
+
// src/next/embed.tsx
|
|
2181
|
+
var import_navigation5 = require("next/navigation");
|
|
2182
|
+
|
|
2183
|
+
// src/next/engage.ts
|
|
2184
|
+
var ENGAGE_CSRF_HEADER = "x-hyle-engage";
|
|
2185
|
+
var DEFAULT_TIMEOUT_MS3 = 1e4;
|
|
2186
|
+
var DEFAULT_SHARE_MS = 3e3;
|
|
2187
|
+
var MAX_SHARED = 100;
|
|
2188
|
+
var MAX_SHARED_BYTES = 8 * 1024 * 1024;
|
|
2189
|
+
var MAX_SHARED_ENTRY_BYTES = 256 * 1024;
|
|
2190
|
+
var MAX_BODY_BYTES2 = 20 * 1024;
|
|
2191
|
+
var MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
2192
|
+
var MAX_COMMENT_CHARACTERS = 4e3;
|
|
2193
|
+
var MAX_PATH_LENGTH2 = 1024;
|
|
2194
|
+
var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
2195
|
+
var CONTROL = /[\u0000-\u001f\u007f\\]/;
|
|
2196
|
+
var HEADERS = { "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" };
|
|
2197
|
+
var isSwitchedOff3 = (value) => {
|
|
2198
|
+
const v = value?.trim().toLowerCase() ?? "";
|
|
2199
|
+
return v !== "" && v !== "1" && v !== "true";
|
|
2200
|
+
};
|
|
2201
|
+
var json = (status, body, extra = {}) => new Response(JSON.stringify(body), { status, headers: { ...HEADERS, "Content-Type": "application/json; charset=utf-8", ...extra } });
|
|
2202
|
+
var refuse = (status, code, extra = {}) => json(status, { error: { code } }, extra);
|
|
2203
|
+
function isSitePath(value) {
|
|
2204
|
+
if (typeof value !== "string" || value.length > MAX_PATH_LENGTH2 || !value.startsWith("/") || value.startsWith("//")) return false;
|
|
2205
|
+
if (CONTROL.test(value) || /[?#]/.test(value)) return false;
|
|
2206
|
+
return !value.split("/").some((segment) => segment === "." || segment === "..");
|
|
2207
|
+
}
|
|
2208
|
+
function match(segments) {
|
|
2209
|
+
const [a, b, ...rest] = segments;
|
|
2210
|
+
if (a === "session" && b === void 0) return { local: "session", action: () => "session", methods: ["GET"], rebuild: () => void 0 };
|
|
2211
|
+
if (a === "comments" && b === void 0) {
|
|
2212
|
+
return {
|
|
2213
|
+
action: (m) => m === "GET" ? "comments.list" : "comments.create",
|
|
2214
|
+
methods: ["GET", "POST"],
|
|
2215
|
+
rebuild: (method, body, url) => {
|
|
2216
|
+
if (method === "GET") {
|
|
2217
|
+
const keys = [...url.searchParams.keys()];
|
|
2218
|
+
const path = url.searchParams.get("path");
|
|
2219
|
+
return keys.length === 1 && isSitePath(path) ? { upstream: "/comments", query: new URLSearchParams({ path }) } : void 0;
|
|
2220
|
+
}
|
|
2221
|
+
const clean2 = pick(body, ["path", "body", "parent_id"], ["path", "body"]);
|
|
2222
|
+
if (!clean2 || !isSitePath(clean2.path) || !isCommentText(clean2.body)) return void 0;
|
|
2223
|
+
if (clean2.parent_id === null) delete clean2.parent_id;
|
|
2224
|
+
if (clean2.parent_id !== void 0 && !(typeof clean2.parent_id === "string" && UUID2.test(clean2.parent_id))) return void 0;
|
|
2225
|
+
return { upstream: "/comments", body: clean2 };
|
|
2226
|
+
}
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
if (a === "comments" && typeof b === "string" && UUID2.test(b) && rest.length === 0) {
|
|
2230
|
+
return {
|
|
2231
|
+
action: (m) => m === "PATCH" ? "comments.edit" : "comments.delete",
|
|
2232
|
+
methods: ["PATCH", "DELETE"],
|
|
2233
|
+
rebuild: (method, body) => {
|
|
2234
|
+
if (method === "DELETE") return body === void 0 ? { upstream: `/comments/${b}` } : void 0;
|
|
2235
|
+
const clean2 = pick(body, ["body"], ["body"]);
|
|
2236
|
+
return clean2 && isCommentText(clean2.body) ? { upstream: `/comments/${b}`, body: clean2 } : void 0;
|
|
2237
|
+
}
|
|
2238
|
+
};
|
|
2239
|
+
}
|
|
2240
|
+
if (a === "reactions" && b === void 0) {
|
|
2241
|
+
return {
|
|
2242
|
+
action: (m) => m === "PUT" ? "reactions.add" : "reactions.remove",
|
|
2243
|
+
methods: ["PUT", "DELETE"],
|
|
2244
|
+
rebuild: (_method, body) => {
|
|
2245
|
+
const type = body?.subject_type;
|
|
2246
|
+
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;
|
|
2247
|
+
if (!clean2) return void 0;
|
|
2248
|
+
const valid = type === "article" ? isSitePath(clean2.path) : typeof clean2.comment_id === "string" && UUID2.test(clean2.comment_id);
|
|
2249
|
+
return valid ? { upstream: "/reactions", body: clean2 } : void 0;
|
|
2250
|
+
}
|
|
2251
|
+
};
|
|
2252
|
+
}
|
|
2253
|
+
return void 0;
|
|
2254
|
+
}
|
|
2255
|
+
function pick(body, allowed, required) {
|
|
2256
|
+
if (!body || Object.keys(body).some((k) => !allowed.includes(k)) || !required.every((k) => k in body)) return void 0;
|
|
2257
|
+
return Object.fromEntries(allowed.filter((k) => k in body).map((k) => [k, body[k]]));
|
|
2258
|
+
}
|
|
2259
|
+
function isCommentText(value) {
|
|
2260
|
+
return typeof value === "string" && value.trim().length > 0 && [...value].length <= MAX_COMMENT_CHARACTERS && !/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/.test(value);
|
|
2261
|
+
}
|
|
2262
|
+
function sameOriginProblem(req, write, allowedOrigins) {
|
|
2263
|
+
const site = req.headers.get("sec-fetch-site");
|
|
2264
|
+
if (site !== null && site !== "same-origin") return true;
|
|
2265
|
+
if (!write) return false;
|
|
2266
|
+
const origin = req.headers.get("origin");
|
|
2267
|
+
if (origin === null) return true;
|
|
2268
|
+
let parsed;
|
|
2269
|
+
try {
|
|
2270
|
+
parsed = new URL(origin);
|
|
2271
|
+
} catch {
|
|
2272
|
+
return true;
|
|
2273
|
+
}
|
|
2274
|
+
if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
|
|
2275
|
+
if (allowedOrigins) return !allowedOrigins.some((o) => safeOrigin(o) === parsed.origin);
|
|
2276
|
+
const host = req.headers.get("x-forwarded-host")?.split(",")[0]?.trim() || req.headers.get("host") || new URL(req.url).host;
|
|
2277
|
+
const proto = req.headers.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase();
|
|
2278
|
+
if (proto && proto !== parsed.protocol.slice(0, -1)) return true;
|
|
2279
|
+
return parsed.host !== host;
|
|
2280
|
+
}
|
|
2281
|
+
var safeOrigin = (value) => {
|
|
2282
|
+
try {
|
|
2283
|
+
return new URL(value).origin;
|
|
2284
|
+
} catch {
|
|
2285
|
+
return void 0;
|
|
2286
|
+
}
|
|
2287
|
+
};
|
|
2288
|
+
async function readBody(req, expected) {
|
|
2289
|
+
if (!expected) return { kind: "ok", body: void 0 };
|
|
2290
|
+
if (!/^application\/json(\s*;|$)/i.test(req.headers.get("content-type") ?? "")) return { kind: "refused", response: refuse(415, "UNSUPPORTED_MEDIA_TYPE") };
|
|
2291
|
+
if (Number(req.headers.get("content-length")) > MAX_BODY_BYTES2) return { kind: "refused", response: refuse(413, "PAYLOAD_TOO_LARGE") };
|
|
2292
|
+
if (!req.body) return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
2293
|
+
const reader = req.body.getReader();
|
|
2294
|
+
const chunks = [];
|
|
2295
|
+
let total = 0;
|
|
2296
|
+
for (; ; ) {
|
|
2297
|
+
const { done, value } = await reader.read();
|
|
2298
|
+
if (done) break;
|
|
2299
|
+
total += value.byteLength;
|
|
2300
|
+
if (total > MAX_BODY_BYTES2) {
|
|
2301
|
+
await reader.cancel().catch(() => {
|
|
2302
|
+
});
|
|
2303
|
+
return { kind: "refused", response: refuse(413, "PAYLOAD_TOO_LARGE") };
|
|
2304
|
+
}
|
|
2305
|
+
chunks.push(value);
|
|
2306
|
+
}
|
|
2307
|
+
try {
|
|
2308
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
2309
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return { kind: "ok", body: parsed };
|
|
2310
|
+
} catch {
|
|
2311
|
+
}
|
|
2312
|
+
return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
2313
|
+
}
|
|
2314
|
+
var SUB_CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
|
|
2315
|
+
function validReader(r) {
|
|
2316
|
+
if (!r || typeof r.sub !== "string" || typeof r.name !== "string") return null;
|
|
2317
|
+
if (r.sub.length < 1 || [...r.sub].length > 255 || SUB_CONTROL.test(r.sub)) return null;
|
|
2318
|
+
const name = cleanDisplayName(r.name);
|
|
2319
|
+
return name === void 0 ? null : { sub: r.sub, name };
|
|
2320
|
+
}
|
|
2321
|
+
function relayFailure(status, retryAfter) {
|
|
2322
|
+
if (status === 400) return refuse(400, "VALIDATION_ERROR");
|
|
2323
|
+
if (status === 404) return refuse(404, "NOT_FOUND");
|
|
2324
|
+
if (status === 409) return refuse(409, "INVALID_TRANSITION");
|
|
2325
|
+
if (status === 413) return refuse(413, "PAYLOAD_TOO_LARGE");
|
|
2326
|
+
if (status === 429) {
|
|
2327
|
+
const seconds = Math.min(3600, Math.max(1, Math.trunc(Number(retryAfter)) || 60));
|
|
2328
|
+
return refuse(429, "RATE_LIMITED", { "Retry-After": String(seconds) });
|
|
2329
|
+
}
|
|
2330
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2331
|
+
}
|
|
2332
|
+
function createEngagementRoute(options) {
|
|
2333
|
+
let ready;
|
|
2334
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
2335
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2336
|
+
let cacheBytes = 0;
|
|
2337
|
+
const clearCache = () => {
|
|
2338
|
+
cache.clear();
|
|
2339
|
+
cacheBytes = 0;
|
|
2340
|
+
};
|
|
2341
|
+
async function listing(viewer, call) {
|
|
2342
|
+
if (!viewer) return call(void 0);
|
|
2343
|
+
let out = await call(viewer.sign("read"));
|
|
2344
|
+
if (out.status === 401) out = await call(viewer.sign("read"));
|
|
2345
|
+
if (out.status !== 401 && out.status !== 404 && !(out.status === 429 && out.throttle === "viewer")) return out;
|
|
2346
|
+
return { ...await call(void 0), noShare: true };
|
|
2347
|
+
}
|
|
2348
|
+
function shared(key, call) {
|
|
2349
|
+
const ttl = options.cacheTtlMs ?? DEFAULT_SHARE_MS;
|
|
2350
|
+
if (ttl <= 0) return call();
|
|
2351
|
+
const hit = cache.get(key);
|
|
2352
|
+
if (hit && Date.now() - hit.at < ttl) {
|
|
2353
|
+
cache.delete(key);
|
|
2354
|
+
cache.set(key, hit);
|
|
2355
|
+
return hit.result;
|
|
2356
|
+
}
|
|
2357
|
+
if (hit) forget(key, hit);
|
|
2358
|
+
const entry = { at: Date.now(), result: call(), bytes: 0 };
|
|
2359
|
+
cache.set(key, entry);
|
|
2360
|
+
entry.result.then(
|
|
2361
|
+
(o) => {
|
|
2362
|
+
if (cache.get(key) !== entry) return;
|
|
2363
|
+
if (o.status !== 200 && o.status !== 404 || o.noShare || o.text.length > MAX_SHARED_ENTRY_BYTES) return forget(key, entry);
|
|
2364
|
+
entry.bytes = o.text.length;
|
|
2365
|
+
cacheBytes += entry.bytes;
|
|
2366
|
+
while ((cacheBytes > MAX_SHARED_BYTES || cache.size > MAX_SHARED) && cache.size > 0) {
|
|
2367
|
+
const oldest = cache.entries().next().value;
|
|
2368
|
+
forget(oldest[0], oldest[1]);
|
|
2369
|
+
}
|
|
2370
|
+
},
|
|
2371
|
+
() => forget(key, entry)
|
|
2372
|
+
);
|
|
2373
|
+
return entry.result;
|
|
2374
|
+
}
|
|
2375
|
+
function forget(key, entry) {
|
|
2376
|
+
if (cache.get(key) !== entry) return;
|
|
2377
|
+
cache.delete(key);
|
|
2378
|
+
cacheBytes -= entry.bytes;
|
|
2379
|
+
}
|
|
2380
|
+
function configured() {
|
|
2381
|
+
if (ready !== void 0) return ready;
|
|
2382
|
+
try {
|
|
2383
|
+
const baseUrl = options.baseUrl?.trim() ?? "";
|
|
2384
|
+
checkBaseUrl(baseUrl);
|
|
2385
|
+
if (!options.token?.trim() || !options.workspaceId?.trim() || !options.signingKey) throw new TypeError("not provisioned");
|
|
2386
|
+
ready = { base: baseUrl.replace(/\/+$/, ""), key: engagementSigningKey(options.signingKey.trim()) };
|
|
2387
|
+
} catch {
|
|
2388
|
+
ready = null;
|
|
2389
|
+
}
|
|
2390
|
+
return ready;
|
|
2391
|
+
}
|
|
2392
|
+
async function reader(req, config) {
|
|
2393
|
+
try {
|
|
2394
|
+
const found = validReader(await options.getReader(req));
|
|
2395
|
+
if (!found) return null;
|
|
2396
|
+
const claims = { sub: found.sub, name: found.name, workspace: options.workspaceId.trim() };
|
|
2397
|
+
const sign2 = (scope) => signReaderAssertion(config.key, claims, void 0, scope);
|
|
2398
|
+
return { reader: found, assertion: sign2(), sign: sign2 };
|
|
2399
|
+
} catch {
|
|
2400
|
+
return null;
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
async function handle(req, ctx2) {
|
|
2404
|
+
const env = options.env ?? process.env;
|
|
2405
|
+
if (isSwitchedOff3(env.HYLE_ENGAGE_ENABLED) || isSwitchedOff3(env.HYLE_CONTENT_ENABLED)) return refuse(404, "NOT_FOUND");
|
|
2406
|
+
const config = configured();
|
|
2407
|
+
const route = match((await ctx2.params).path ?? []);
|
|
2408
|
+
if (!config || !route) return refuse(404, "NOT_FOUND");
|
|
2409
|
+
if (!route.methods.includes(req.method)) return refuse(405, "METHOD_NOT_ALLOWED", { Allow: route.methods.join(", ") });
|
|
2410
|
+
const write = req.method !== "GET";
|
|
2411
|
+
if (sameOriginProblem(req, write, options.allowedOrigins)) return refuse(403, "FORBIDDEN");
|
|
2412
|
+
if (options.onRequest) {
|
|
2413
|
+
try {
|
|
2414
|
+
const early = await options.onRequest(req, { action: route.action(req.method) });
|
|
2415
|
+
if (early instanceof Response) {
|
|
2416
|
+
const headers = new Headers(early.headers);
|
|
2417
|
+
headers.set("cache-control", "no-store");
|
|
2418
|
+
return new Response(early.body, { status: early.status, headers });
|
|
2419
|
+
}
|
|
2420
|
+
} catch {
|
|
2421
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
if (route.local === "session") {
|
|
2425
|
+
const who = await reader(req, config);
|
|
2426
|
+
return json(200, { data: { reader: who ? { name: who.reader.name } : null } });
|
|
2427
|
+
}
|
|
2428
|
+
let assertion;
|
|
2429
|
+
let viewer = null;
|
|
2430
|
+
if (route.action(req.method) === "comments.list") viewer = await reader(req, config);
|
|
2431
|
+
if (write) {
|
|
2432
|
+
const who = await reader(req, config);
|
|
2433
|
+
if (!who) return refuse(401, "UNAUTHENTICATED");
|
|
2434
|
+
assertion = who.assertion;
|
|
2435
|
+
}
|
|
2436
|
+
const url = new URL(req.url);
|
|
2437
|
+
const hasBody = write && !(req.method === "DELETE" && (await ctx2.params).path?.[0] === "comments");
|
|
2438
|
+
const body = await readBody(req, hasBody);
|
|
2439
|
+
if (body.kind === "refused") return body.response;
|
|
2440
|
+
const built = route.rebuild(req.method, body.body, url);
|
|
2441
|
+
if (!built) return refuse(400, "VALIDATION_ERROR");
|
|
2442
|
+
const baseHeaders = new Headers({ authorization: `Bearer ${options.token.trim()}`, accept: "application/json" });
|
|
2443
|
+
if (built.body) baseHeaders.set("content-type", "application/json");
|
|
2444
|
+
const target = `${config.base}/cp1/engage${built.upstream}${built.query ? `?${built.query}` : ""}`;
|
|
2445
|
+
const call = async (withAssertion = assertion) => {
|
|
2446
|
+
const headers = new Headers(baseHeaders);
|
|
2447
|
+
if (withAssertion) headers.set("hyle-reader-assertion", withAssertion);
|
|
2448
|
+
const res = await fetchImpl(target, {
|
|
2449
|
+
method: req.method,
|
|
2450
|
+
headers,
|
|
2451
|
+
...built.body ? { body: JSON.stringify(built.body) } : {},
|
|
2452
|
+
redirect: "error",
|
|
2453
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS3)
|
|
2454
|
+
});
|
|
2455
|
+
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") };
|
|
2456
|
+
};
|
|
2457
|
+
try {
|
|
2458
|
+
const out = route.action(req.method) === "comments.list" ? await shared(`${viewer?.reader.sub ?? ""}
|
|
2459
|
+
${built.query.toString()}`, () => listing(viewer, call)) : await call();
|
|
2460
|
+
if (!out.ok) return relayFailure(out.status, out.retryAfter);
|
|
2461
|
+
if (write) clearCache();
|
|
2462
|
+
const data = JSON.parse(out.text).data;
|
|
2463
|
+
return typeof data === "object" && data !== null ? json(out.status === 201 ? 201 : 200, { data }) : refuse(502, "UPSTREAM_ERROR");
|
|
2464
|
+
} catch {
|
|
2465
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
return { GET: handle, POST: handle, PATCH: handle, PUT: handle, DELETE: handle };
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
// src/next/embed.tsx
|
|
2472
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
2473
|
+
async function resolveEmbed(options, run) {
|
|
2474
|
+
try {
|
|
2475
|
+
return { result: await run() };
|
|
2476
|
+
} catch (error) {
|
|
2477
|
+
if (isRejectedRequest(error)) return {};
|
|
2478
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2479
|
+
return { failure: options.onError ? options.onError(error) : null };
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
async function HyleList({ options, section, limit = 5, locale, layout, title, headingLevel, moreHref }) {
|
|
2483
|
+
const resolve = resolverFor(options);
|
|
2484
|
+
const route = routeContext(locale ? { ...options, locale } : options, {});
|
|
2485
|
+
const path = sitePathFrom(route.basePath, section && section !== "posts" ? [section] : void 0);
|
|
2486
|
+
if (path === void 0) return null;
|
|
2487
|
+
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale, limit));
|
|
2488
|
+
if (failure !== void 0) return failure;
|
|
2489
|
+
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 });
|
|
2490
|
+
}
|
|
2491
|
+
async function HyleArticle({ options, path, locale, headingLevel }) {
|
|
2492
|
+
if (!isSitePath(path)) return null;
|
|
2493
|
+
const resolve = resolverFor(options);
|
|
2494
|
+
const route = routeContext(locale ? { ...options, locale } : options, {});
|
|
2495
|
+
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale));
|
|
2496
|
+
if (failure !== void 0) return failure;
|
|
2497
|
+
if (result?.kind !== "article") return null;
|
|
2498
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HyleArticleView, { article: result, headingLevel, components: options.components, slots: options.slots, locale: route.locale, toHref: route.toHref });
|
|
2499
|
+
}
|
|
2500
|
+
var MAX_LISTING_BYTES = 4 * 1024 * 1024;
|
|
2501
|
+
var COMMENTS_TIMEOUT_MS = 1e4;
|
|
2502
|
+
async function HyleComments({ options, path, revalidate = 60, interactive }) {
|
|
2503
|
+
checkBaseUrl(options.baseUrl);
|
|
2504
|
+
if (!options.token) throw new TypeError("token is required");
|
|
2505
|
+
if (!isSitePath(path)) return null;
|
|
2506
|
+
const locale = options.locale ?? "en";
|
|
2507
|
+
let listing;
|
|
2508
|
+
let fetchedAt;
|
|
2509
|
+
try {
|
|
2510
|
+
const init = {
|
|
2511
|
+
headers: { authorization: `Bearer ${options.token}`, accept: "application/json" },
|
|
2512
|
+
redirect: "error",
|
|
2513
|
+
signal: AbortSignal.timeout(COMMENTS_TIMEOUT_MS),
|
|
2514
|
+
next: { revalidate }
|
|
2515
|
+
};
|
|
2516
|
+
const res = await fetch(`${options.baseUrl.replace(/\/+$/, "")}/cp1/engage/comments?${new URLSearchParams({ path })}`, init);
|
|
2517
|
+
if (!res.ok) {
|
|
2518
|
+
if (res.status !== 404) console.error(`hyle: comments answered HTTP ${res.status}`);
|
|
2519
|
+
return null;
|
|
2520
|
+
}
|
|
2521
|
+
listing = parseListing(JSON.parse(await readCapped(res, MAX_LISTING_BYTES)).data);
|
|
2522
|
+
const date = Date.parse(res.headers.get("date") ?? "");
|
|
2523
|
+
fetchedAt = Number.isFinite(date) ? date : void 0;
|
|
2524
|
+
} catch (error) {
|
|
2525
|
+
(0, import_navigation5.unstable_rethrow)(error);
|
|
2526
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2527
|
+
return null;
|
|
2528
|
+
}
|
|
2529
|
+
if (!listing) return null;
|
|
2530
|
+
if (!interactive) return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HyleCommentsView, { listing, locale });
|
|
2531
|
+
const config = interactive === true ? {} : interactive;
|
|
2532
|
+
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 }) });
|
|
2533
|
+
}
|
|
1609
2534
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1610
2535
|
0 && (module.exports = {
|
|
2536
|
+
ENGAGE_CSRF_HEADER,
|
|
2537
|
+
HyleArticle,
|
|
2538
|
+
HyleComments,
|
|
2539
|
+
HyleCommentsFallback,
|
|
2540
|
+
HyleList,
|
|
1611
2541
|
MOUNTS_MAX_STALE_MS,
|
|
1612
2542
|
createAssetRoute,
|
|
2543
|
+
createEngagementRoute,
|
|
1613
2544
|
createRevalidateRoute,
|
|
1614
2545
|
fetchResolver,
|
|
2546
|
+
hyleFeed,
|
|
1615
2547
|
hyleMetadata,
|
|
1616
2548
|
hylePage,
|
|
1617
2549
|
hyleRootMetadata,
|