@tdacorp/hyle-sdk 0.8.1 → 0.11.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 +82 -4
- package/bin/hyle-sdk-engage-keygen.mjs +3 -0
- package/dist/check-routes-bin.js +6 -1
- package/dist/{chunk-EBNIKRQH.js → chunk-N7ZQUAGM.js} +46 -2
- package/dist/chunk-R5EMI4HQ.js +61 -0
- package/dist/{chunk-LGW2KP4X.js → chunk-S3LT6G4M.js} +601 -77
- package/dist/{chunk-N4QYPO7S.js → chunk-S7PCCEHP.js} +3 -2
- 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/docs-enhance.cjs +97 -0
- package/dist/docs-enhance.d.cts +16 -0
- package/dist/docs-enhance.d.ts +16 -0
- package/dist/docs-enhance.js +73 -0
- package/dist/{types-DnPzhrFx.d.cts → embed-BC8Tlc6A.d.cts} +44 -3
- package/dist/{types-BoyBWF2F.d.ts → embed-CwSzvBUO.d.ts} +44 -3
- package/dist/engage-keygen-bin.js +67 -0
- package/dist/index.cjs +27 -1
- package/dist/index.d.cts +13 -3
- package/dist/index.d.ts +13 -3
- package/dist/index.js +5 -1
- package/dist/mermaid-diagram.js +9 -54
- package/dist/next.cjs +988 -66
- package/dist/next.d.cts +149 -6
- package/dist/next.d.ts +149 -6
- package/dist/next.js +391 -12
- package/dist/react.cjs +403 -75
- package/dist/react.d.cts +141 -33
- package/dist/react.d.ts +141 -33
- package/dist/react.js +7 -1
- package/dist/{resolve-36-Ng1H0.d.cts → resolve-BYL8jMg0.d.ts} +2 -2
- package/dist/{resolve-1rQntRBh.d.ts → resolve-Ra8-y2U-.d.cts} +2 -2
- package/dist/styles.css +149 -21
- package/dist/{types-CwBCPh6K.d.cts → types-C72FwzOd.d.cts} +71 -1
- package/dist/{types-CwBCPh6K.d.ts → types-C72FwzOd.d.ts} +71 -1
- package/dist/use-cache.cjs +9 -4
- package/dist/use-cache.d.cts +2 -2
- package/dist/use-cache.d.ts +2 -2
- package/dist/use-cache.js +5 -5
- package/package.json +4 -3
package/dist/next.cjs
CHANGED
|
@@ -20,8 +20,14 @@ 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,
|
|
27
33
|
hyleMetadata: () => hyleMetadata,
|
|
@@ -149,11 +155,16 @@ function createHyleClient(options) {
|
|
|
149
155
|
const query = new URLSearchParams({ path: opts.path });
|
|
150
156
|
if (opts.locale !== void 0) query.set("locale", opts.locale);
|
|
151
157
|
if (opts.format !== void 0) query.set("format", opts.format);
|
|
158
|
+
if (opts.nav !== void 0) query.set("nav", opts.nav);
|
|
152
159
|
if (opts.cursor !== void 0) query.set("cursor", opts.cursor);
|
|
153
160
|
if (opts.limit !== void 0) query.set("limit", String(opts.limit));
|
|
154
161
|
const reply = await get("/cp1/read/resolve", query, opts.init);
|
|
155
162
|
const data = reply.parsed?.data;
|
|
156
|
-
if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind))
|
|
163
|
+
if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) {
|
|
164
|
+
const resolved = data;
|
|
165
|
+
if (resolved.kind === "article" && resolved.content.format === "html" && opts.format !== "html") throw failure(reply);
|
|
166
|
+
return resolved;
|
|
167
|
+
}
|
|
157
168
|
throw failure(reply);
|
|
158
169
|
}
|
|
159
170
|
async function mounts(opts = {}) {
|
|
@@ -368,6 +379,31 @@ async function listPublicationPaths(options) {
|
|
|
368
379
|
return { paths: [...found].map(([path, publishedAt]) => ({ path, publishedAt })), complete };
|
|
369
380
|
}
|
|
370
381
|
|
|
382
|
+
// src/engage-keys.ts
|
|
383
|
+
var import_node_crypto2 = require("crypto");
|
|
384
|
+
var KEY_B64URL = /^[A-Za-z0-9_-]{43}$/;
|
|
385
|
+
var PKCS8_ED25519 = Buffer.from("302e020100300506032b657004220420", "hex");
|
|
386
|
+
function engagementSigningKey(seed) {
|
|
387
|
+
const bytes = KEY_B64URL.test(seed) ? Buffer.from(seed, "base64url") : void 0;
|
|
388
|
+
if (bytes?.length !== 32) throw new TypeError("the engagement signing key must be a 32-byte Ed25519 seed, base64url (43 characters)");
|
|
389
|
+
return (0, import_node_crypto2.createPrivateKey)({ key: Buffer.concat([PKCS8_ED25519, bytes]), format: "der", type: "pkcs8" });
|
|
390
|
+
}
|
|
391
|
+
var ASSERTION_MAX_BYTES = 2048;
|
|
392
|
+
var ASSERTION_TTL_SECONDS = 30;
|
|
393
|
+
var b64 = (value) => Buffer.from(JSON.stringify(value)).toString("base64url");
|
|
394
|
+
function signReaderAssertion(key, claims, nowSeconds = Math.floor(Date.now() / 1e3), scope) {
|
|
395
|
+
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)() })}`;
|
|
396
|
+
const token = `${input}.${(0, import_node_crypto2.sign)(null, Buffer.from(input), key).toString("base64url")}`;
|
|
397
|
+
if (Buffer.byteLength(token) > ASSERTION_MAX_BYTES) throw new RangeError("the reader assertion would exceed 2 KiB");
|
|
398
|
+
return token;
|
|
399
|
+
}
|
|
400
|
+
var INVISIBLE = /[\u0000-\u001f\u007f-\u009f\p{Cf}\u115f\u1160\u17b4\u17b5\u3164\uffa0]/gu;
|
|
401
|
+
var DISPLAY_NAME_MAX = 80;
|
|
402
|
+
function cleanDisplayName(raw) {
|
|
403
|
+
const cleaned = [...raw.replace(/[\t\n\r\f\v]/gu, " ").replace(INVISIBLE, "").replace(/\s+/gu, " ").trim()].slice(0, DISPLAY_NAME_MAX).join("").trim();
|
|
404
|
+
return cleaned.length > 0 ? cleaned : void 0;
|
|
405
|
+
}
|
|
406
|
+
|
|
371
407
|
// src/react/content.tsx
|
|
372
408
|
var import_hast_util_to_jsx_runtime = require("hast-util-to-jsx-runtime");
|
|
373
409
|
var import_react = require("react");
|
|
@@ -403,7 +439,19 @@ var SHAPES = {
|
|
|
403
439
|
] }),
|
|
404
440
|
chev: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m6 3.5 4.5 4.5L6 12.5" }),
|
|
405
441
|
"chev-down": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3.5 6 4.5 4.5L12.5 6" }),
|
|
406
|
-
"chev-left": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 3.5 5.5 8 10 12.5" })
|
|
442
|
+
"chev-left": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 3.5 5.5 8 10 12.5" }),
|
|
443
|
+
x: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m4 4 8 8M12 4l-8 8" }),
|
|
444
|
+
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" }),
|
|
445
|
+
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" }),
|
|
446
|
+
clock: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
447
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
|
|
448
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 4.5V8l2.3 1.5" })
|
|
449
|
+
] }),
|
|
450
|
+
ban: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
451
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
|
|
452
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3.8 12.2 8.4-8.4" })
|
|
453
|
+
] }),
|
|
454
|
+
refresh: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M13 8a5 5 0 1 1-1.6-3.7M13 2.5v2.8h-2.8" })
|
|
407
455
|
};
|
|
408
456
|
function Icon({ name, className }) {
|
|
409
457
|
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] });
|
|
@@ -582,14 +630,205 @@ function clean(node, depth, ctx2, budget) {
|
|
|
582
630
|
const tagName = tag === "h1" ? "h2" : tag;
|
|
583
631
|
return [{ type: "element", tagName, properties, children: VOID.has(tag) ? [] : children }];
|
|
584
632
|
}
|
|
585
|
-
function sanitizeHast(tree, title) {
|
|
633
|
+
function sanitizeHast(tree, title, description) {
|
|
586
634
|
const raw = isObject(tree) && tree.type === "root" && Array.isArray(tree.children) ? tree.children : [];
|
|
587
|
-
const
|
|
635
|
+
const elements = raw.filter((n) => isObject(n) && n.type === "element");
|
|
636
|
+
const [first] = elements;
|
|
588
637
|
const skip = title !== void 0 && isObject(first) && first.tagName === "h1" && textOf(first).trim() === title.trim() ? first : void 0;
|
|
638
|
+
const lead = elements[skip ? 1 : 0];
|
|
639
|
+
const repeat = description && isObject(lead) && lead.tagName === "p" && textOf(lead).trim().startsWith(description.trim()) ? lead : void 0;
|
|
589
640
|
const budget = { nodes: 0, text: 0 };
|
|
590
|
-
return { type: "root", children: raw.filter((n) => n !== skip).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
|
|
641
|
+
return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
|
|
591
642
|
}
|
|
592
643
|
|
|
644
|
+
// src/react/comments-labels.ts
|
|
645
|
+
var COMMENT_LABELS_EN = {
|
|
646
|
+
heading: "Comments",
|
|
647
|
+
countLabel: "{n} comments",
|
|
648
|
+
likeArticle: "Like this article",
|
|
649
|
+
likedArticle: "Liked",
|
|
650
|
+
likeArticleSignIn: "(sign in), ",
|
|
651
|
+
likeComment: "Like this comment, ",
|
|
652
|
+
likeCommentSignIn: "Sign in to like this comment, ",
|
|
653
|
+
signInTitle: "Sign in to join the discussion",
|
|
654
|
+
signInBody: "Anyone can read. To comment or like, sign in.",
|
|
655
|
+
signIn: "Sign in",
|
|
656
|
+
commentingAs: "Commenting as {name}",
|
|
657
|
+
write: "Write a comment",
|
|
658
|
+
placeholder: "Add to the discussion",
|
|
659
|
+
help: "Markdown: links, emphasis, code and quotes.",
|
|
660
|
+
chars: "{n} / {max}",
|
|
661
|
+
post: "Post comment",
|
|
662
|
+
posting: "Posting",
|
|
663
|
+
reply: "Reply",
|
|
664
|
+
replyTo: "Reply to {name}",
|
|
665
|
+
replyPlaceholder: "Write a reply",
|
|
666
|
+
cancel: "Cancel",
|
|
667
|
+
edit: "Edit",
|
|
668
|
+
editLeft: "({n} min left)",
|
|
669
|
+
save: "Save",
|
|
670
|
+
delete: "Delete",
|
|
671
|
+
deleteConfirm: "Delete this comment?",
|
|
672
|
+
keep: "Keep",
|
|
673
|
+
you: "You",
|
|
674
|
+
edited: "edited",
|
|
675
|
+
removed: "This comment was removed.",
|
|
676
|
+
removedByModerator: "This comment was removed by a moderator.",
|
|
677
|
+
removedByAuthor: "This comment was deleted by its author.",
|
|
678
|
+
depthEnd: "Replies end at this depth",
|
|
679
|
+
held: "Awaiting approval.",
|
|
680
|
+
heldBanner: "Thanks, your comment is awaiting approval",
|
|
681
|
+
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.",
|
|
682
|
+
heldNote: "Only you can see this until a moderator approves it.",
|
|
683
|
+
heldLive: "Comment awaiting approval",
|
|
684
|
+
postedLive: "Comment posted",
|
|
685
|
+
deletedLive: "Comment deleted",
|
|
686
|
+
savedLive: "Comment saved",
|
|
687
|
+
empty: "No comments yet",
|
|
688
|
+
emptyBody: "Start the discussion. Comments may be reviewed before they appear.",
|
|
689
|
+
loading: "Loading comments",
|
|
690
|
+
loadError: "Comments could not be loaded",
|
|
691
|
+
loadErrorBody: "The article is fine. The comments service did not answer.",
|
|
692
|
+
retry: "Try again",
|
|
693
|
+
postError: "Your comment was not posted. We kept your text, so nothing is lost. Check your connection and try again.",
|
|
694
|
+
tooLong: "That comment is too long or empty. Comments are 1 to 4000 characters.",
|
|
695
|
+
editClosed: "Comments can be edited for ten minutes after posting. That time has passed.",
|
|
696
|
+
actionError: "That did not go through. Please try again.",
|
|
697
|
+
rateTitle: "You are commenting too quickly",
|
|
698
|
+
rateBody: "Please wait before posting again. Your draft is kept in the box below.",
|
|
699
|
+
rateWait: "You can post again in {n} seconds.",
|
|
700
|
+
bannedTitle: "You cannot comment right now",
|
|
701
|
+
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.",
|
|
702
|
+
expired: "Your session ended. Sign in again to post. Your text is kept.",
|
|
703
|
+
more: "Load more comments",
|
|
704
|
+
truncated: "Showing the first 500 comments.",
|
|
705
|
+
justNow: "just now"
|
|
706
|
+
};
|
|
707
|
+
var COMMENT_LABELS_FR = {
|
|
708
|
+
heading: "Commentaires",
|
|
709
|
+
countLabel: "{n} commentaires",
|
|
710
|
+
likeArticle: "Aimer cet article",
|
|
711
|
+
likedArticle: "Aim\xE9",
|
|
712
|
+
likeArticleSignIn: "(connexion requise), ",
|
|
713
|
+
likeComment: "Aimer ce commentaire, ",
|
|
714
|
+
likeCommentSignIn: "Connectez-vous pour aimer ce commentaire, ",
|
|
715
|
+
signInTitle: "Connectez-vous pour participer \xE0 la discussion",
|
|
716
|
+
signInBody: "Tout le monde peut lire. Pour commenter ou aimer, connectez-vous.",
|
|
717
|
+
signIn: "Se connecter",
|
|
718
|
+
commentingAs: "Vous commentez en tant que {name}",
|
|
719
|
+
write: "\xC9crire un commentaire",
|
|
720
|
+
placeholder: "Participez \xE0 la discussion",
|
|
721
|
+
help: "Markdown : liens, emphase, code et citations.",
|
|
722
|
+
chars: "{n} / {max}",
|
|
723
|
+
post: "Publier le commentaire",
|
|
724
|
+
posting: "Publication",
|
|
725
|
+
reply: "R\xE9pondre",
|
|
726
|
+
replyTo: "R\xE9pondre \xE0 {name}",
|
|
727
|
+
replyPlaceholder: "\xC9crire une r\xE9ponse",
|
|
728
|
+
cancel: "Annuler",
|
|
729
|
+
edit: "Modifier",
|
|
730
|
+
editLeft: "({n} min restantes)",
|
|
731
|
+
save: "Enregistrer",
|
|
732
|
+
delete: "Supprimer",
|
|
733
|
+
deleteConfirm: "Supprimer ce commentaire ?",
|
|
734
|
+
keep: "Conserver",
|
|
735
|
+
you: "Vous",
|
|
736
|
+
edited: "modifi\xE9",
|
|
737
|
+
removed: "Ce commentaire a \xE9t\xE9 retir\xE9.",
|
|
738
|
+
removedByModerator: "Ce commentaire a \xE9t\xE9 retir\xE9 par un mod\xE9rateur.",
|
|
739
|
+
removedByAuthor: "Ce commentaire a \xE9t\xE9 supprim\xE9 par son auteur.",
|
|
740
|
+
depthEnd: "Les r\xE9ponses s'arr\xEAtent \xE0 ce niveau",
|
|
741
|
+
held: "En attente d'approbation.",
|
|
742
|
+
heldBanner: "Merci, votre commentaire est en attente d'approbation",
|
|
743
|
+
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.",
|
|
744
|
+
heldNote: "Vous seul le voyez tant qu'un mod\xE9rateur ne l'a pas approuv\xE9.",
|
|
745
|
+
heldLive: "Commentaire en attente d'approbation",
|
|
746
|
+
postedLive: "Commentaire publi\xE9",
|
|
747
|
+
deletedLive: "Commentaire supprim\xE9",
|
|
748
|
+
savedLive: "Commentaire enregistr\xE9",
|
|
749
|
+
empty: "Aucun commentaire pour l'instant",
|
|
750
|
+
emptyBody: "Lancez la discussion. Les commentaires peuvent \xEAtre relus avant d'appara\xEEtre.",
|
|
751
|
+
loading: "Chargement des commentaires",
|
|
752
|
+
loadError: "Les commentaires n'ont pas pu \xEAtre charg\xE9s",
|
|
753
|
+
loadErrorBody: "L'article est intact. Le service de commentaires n'a pas r\xE9pondu.",
|
|
754
|
+
retry: "R\xE9essayer",
|
|
755
|
+
postError: "Votre commentaire n'a pas \xE9t\xE9 publi\xE9. Votre texte est conserv\xE9. V\xE9rifiez votre connexion et r\xE9essayez.",
|
|
756
|
+
tooLong: "Ce commentaire est trop long ou vide. Un commentaire compte de 1 \xE0 4000 caract\xE8res.",
|
|
757
|
+
editClosed: "Un commentaire peut \xEAtre modifi\xE9 pendant dix minutes apr\xE8s sa publication. Ce d\xE9lai est \xE9coul\xE9.",
|
|
758
|
+
actionError: "L'action a \xE9chou\xE9. R\xE9essayez.",
|
|
759
|
+
rateTitle: "Vous commentez trop vite",
|
|
760
|
+
rateBody: "Patientez avant de publier \xE0 nouveau. Votre brouillon est conserv\xE9 dans la zone ci-dessous.",
|
|
761
|
+
rateWait: "Vous pourrez publier \xE0 nouveau dans {n} secondes.",
|
|
762
|
+
bannedTitle: "Vous ne pouvez pas commenter pour le moment",
|
|
763
|
+
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.",
|
|
764
|
+
expired: "Votre session a expir\xE9. Reconnectez-vous pour publier. Votre texte est conserv\xE9.",
|
|
765
|
+
more: "Charger plus de commentaires",
|
|
766
|
+
truncated: "Affichage des 500 premiers commentaires.",
|
|
767
|
+
justNow: "\xE0 l'instant"
|
|
768
|
+
};
|
|
769
|
+
var COMMENT_LABELS_ES = {
|
|
770
|
+
heading: "Comentarios",
|
|
771
|
+
countLabel: "{n} comentarios",
|
|
772
|
+
likeArticle: "Me gusta este art\xEDculo",
|
|
773
|
+
likedArticle: "Te gusta",
|
|
774
|
+
likeArticleSignIn: "(inicia sesi\xF3n), ",
|
|
775
|
+
likeComment: "Me gusta este comentario, ",
|
|
776
|
+
likeCommentSignIn: "Inicia sesi\xF3n para dar me gusta a este comentario, ",
|
|
777
|
+
signInTitle: "Inicia sesi\xF3n para unirte a la conversaci\xF3n",
|
|
778
|
+
signInBody: "Todos pueden leer. Para comentar o dar me gusta, inicia sesi\xF3n.",
|
|
779
|
+
signIn: "Iniciar sesi\xF3n",
|
|
780
|
+
commentingAs: "Comentando como {name}",
|
|
781
|
+
write: "Escribe un comentario",
|
|
782
|
+
placeholder: "A\xF1ade a la conversaci\xF3n",
|
|
783
|
+
help: "Markdown: enlaces, \xE9nfasis, c\xF3digo y citas.",
|
|
784
|
+
chars: "{n} / {max}",
|
|
785
|
+
post: "Publicar comentario",
|
|
786
|
+
posting: "Publicando",
|
|
787
|
+
reply: "Responder",
|
|
788
|
+
replyTo: "Responder a {name}",
|
|
789
|
+
replyPlaceholder: "Escribe una respuesta",
|
|
790
|
+
cancel: "Cancelar",
|
|
791
|
+
edit: "Editar",
|
|
792
|
+
editLeft: "(quedan {n} min)",
|
|
793
|
+
save: "Guardar",
|
|
794
|
+
delete: "Eliminar",
|
|
795
|
+
deleteConfirm: "\xBFEliminar este comentario?",
|
|
796
|
+
keep: "Conservar",
|
|
797
|
+
you: "T\xFA",
|
|
798
|
+
edited: "editado",
|
|
799
|
+
removed: "Este comentario fue eliminado.",
|
|
800
|
+
removedByModerator: "Un moderador elimin\xF3 este comentario.",
|
|
801
|
+
removedByAuthor: "Su autor elimin\xF3 este comentario.",
|
|
802
|
+
depthEnd: "Las respuestas terminan en este nivel",
|
|
803
|
+
held: "Pendiente de aprobaci\xF3n.",
|
|
804
|
+
heldBanner: "Gracias, tu comentario est\xE1 pendiente de aprobaci\xF3n",
|
|
805
|
+
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.",
|
|
806
|
+
heldNote: "Solo t\xFA lo ves hasta que un moderador lo apruebe.",
|
|
807
|
+
heldLive: "Comentario pendiente de aprobaci\xF3n",
|
|
808
|
+
postedLive: "Comentario publicado",
|
|
809
|
+
deletedLive: "Comentario eliminado",
|
|
810
|
+
savedLive: "Comentario guardado",
|
|
811
|
+
empty: "A\xFAn no hay comentarios",
|
|
812
|
+
emptyBody: "Empieza la conversaci\xF3n. Los comentarios pueden revisarse antes de aparecer.",
|
|
813
|
+
loading: "Cargando comentarios",
|
|
814
|
+
loadError: "No se pudieron cargar los comentarios",
|
|
815
|
+
loadErrorBody: "El art\xEDculo est\xE1 bien. El servicio de comentarios no respondi\xF3.",
|
|
816
|
+
retry: "Reintentar",
|
|
817
|
+
postError: "Tu comentario no se public\xF3. Hemos conservado tu texto. Revisa tu conexi\xF3n e int\xE9ntalo de nuevo.",
|
|
818
|
+
tooLong: "Ese comentario es demasiado largo o est\xE1 vac\xEDo. Los comentarios tienen de 1 a 4000 caracteres.",
|
|
819
|
+
editClosed: "Un comentario puede editarse durante diez minutos tras publicarlo. Ese tiempo ya pas\xF3.",
|
|
820
|
+
actionError: "No se pudo completar. Int\xE9ntalo de nuevo.",
|
|
821
|
+
rateTitle: "Est\xE1s comentando demasiado r\xE1pido",
|
|
822
|
+
rateBody: "Espera antes de publicar de nuevo. Tu borrador se conserva en el cuadro de abajo.",
|
|
823
|
+
rateWait: "Podr\xE1s publicar de nuevo en {n} segundos.",
|
|
824
|
+
bannedTitle: "No puedes comentar por ahora",
|
|
825
|
+
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.",
|
|
826
|
+
expired: "Tu sesi\xF3n termin\xF3. Inicia sesi\xF3n de nuevo para publicar. Tu texto se conserva.",
|
|
827
|
+
more: "Cargar m\xE1s comentarios",
|
|
828
|
+
truncated: "Se muestran los primeros 500 comentarios.",
|
|
829
|
+
justNow: "ahora mismo"
|
|
830
|
+
};
|
|
831
|
+
|
|
593
832
|
// src/react/viewer/labels.ts
|
|
594
833
|
var VIEWER_LABELS_EN = {
|
|
595
834
|
expand: "Expand diagram",
|
|
@@ -707,10 +946,14 @@ var en = {
|
|
|
707
946
|
fallbackTitle: "Not translated into {language} yet.",
|
|
708
947
|
fallbackBody: "You are reading the original.",
|
|
709
948
|
older: "Older posts",
|
|
949
|
+
viewAll: "View all",
|
|
950
|
+
readAtSource: "Read at source",
|
|
710
951
|
emptyTitle: "Nothing published here yet",
|
|
711
952
|
emptyBody: "Documents published to this section will appear here, newest first.",
|
|
712
953
|
docs: "Documentation",
|
|
713
954
|
menu: "Menu",
|
|
955
|
+
closeMenu: "Close menu",
|
|
956
|
+
updated: "Last updated",
|
|
714
957
|
nfKind: "404 \xB7 Not found",
|
|
715
958
|
nfTitle: "This page does not exist",
|
|
716
959
|
nfBody: "The address may be mistyped, or the document may have been unpublished or moved.",
|
|
@@ -725,7 +968,8 @@ var en = {
|
|
|
725
968
|
unKind: "Unavailable",
|
|
726
969
|
unTitle: "This page is temporarily unavailable",
|
|
727
970
|
unBody: "The content could not be loaded. Please try again in a moment.",
|
|
728
|
-
viewer: VIEWER_LABELS_EN
|
|
971
|
+
viewer: VIEWER_LABELS_EN,
|
|
972
|
+
comments: COMMENT_LABELS_EN
|
|
729
973
|
};
|
|
730
974
|
var fr = {
|
|
731
975
|
toc: "Sur cette page",
|
|
@@ -748,10 +992,14 @@ var fr = {
|
|
|
748
992
|
fallbackTitle: "Pas encore traduit en {language}.",
|
|
749
993
|
fallbackBody: "Vous lisez l'original.",
|
|
750
994
|
older: "Articles plus anciens",
|
|
995
|
+
viewAll: "Tout voir",
|
|
996
|
+
readAtSource: "Lire \xE0 la source",
|
|
751
997
|
emptyTitle: "Rien n'est encore publi\xE9 ici",
|
|
752
998
|
emptyBody: "Les documents publi\xE9s dans cette section appara\xEEtront ici, du plus r\xE9cent au plus ancien.",
|
|
753
999
|
docs: "Documentation",
|
|
754
1000
|
menu: "Menu",
|
|
1001
|
+
closeMenu: "Fermer le menu",
|
|
1002
|
+
updated: "Derni\xE8re mise \xE0 jour",
|
|
755
1003
|
nfKind: "404 \xB7 Introuvable",
|
|
756
1004
|
nfTitle: "Cette page n'existe pas",
|
|
757
1005
|
nfBody: "L'adresse est peut-\xEAtre mal saisie, ou le document a \xE9t\xE9 d\xE9publi\xE9 ou d\xE9plac\xE9.",
|
|
@@ -766,7 +1014,8 @@ var fr = {
|
|
|
766
1014
|
unKind: "Indisponible",
|
|
767
1015
|
unTitle: "Cette page est momentan\xE9ment indisponible",
|
|
768
1016
|
unBody: "Le contenu n'a pas pu \xEAtre charg\xE9. R\xE9essayez dans un instant.",
|
|
769
|
-
viewer: VIEWER_LABELS_FR
|
|
1017
|
+
viewer: VIEWER_LABELS_FR,
|
|
1018
|
+
comments: COMMENT_LABELS_FR
|
|
770
1019
|
};
|
|
771
1020
|
var es = {
|
|
772
1021
|
toc: "En esta p\xE1gina",
|
|
@@ -789,10 +1038,14 @@ var es = {
|
|
|
789
1038
|
fallbackTitle: "A\xFAn no est\xE1 traducida al {language}.",
|
|
790
1039
|
fallbackBody: "Est\xE1s leyendo el original.",
|
|
791
1040
|
older: "Entradas anteriores",
|
|
1041
|
+
viewAll: "Ver todo",
|
|
1042
|
+
readAtSource: "Leer en la fuente",
|
|
792
1043
|
emptyTitle: "A\xFAn no hay nada publicado aqu\xED",
|
|
793
1044
|
emptyBody: "Los documentos publicados en esta secci\xF3n aparecer\xE1n aqu\xED, del m\xE1s reciente al m\xE1s antiguo.",
|
|
794
1045
|
docs: "Documentaci\xF3n",
|
|
795
1046
|
menu: "Men\xFA",
|
|
1047
|
+
closeMenu: "Cerrar el men\xFA",
|
|
1048
|
+
updated: "\xDAltima actualizaci\xF3n",
|
|
796
1049
|
nfKind: "404 \xB7 No encontrada",
|
|
797
1050
|
nfTitle: "Esta p\xE1gina no existe",
|
|
798
1051
|
nfBody: "Puede que la direcci\xF3n est\xE9 mal escrita, o que el documento se haya despublicado o movido.",
|
|
@@ -807,7 +1060,8 @@ var es = {
|
|
|
807
1060
|
unKind: "No disponible",
|
|
808
1061
|
unTitle: "Esta p\xE1gina no est\xE1 disponible por el momento",
|
|
809
1062
|
unBody: "No se pudo cargar el contenido. Int\xE9ntalo de nuevo en un momento.",
|
|
810
|
-
viewer: VIEWER_LABELS_ES
|
|
1063
|
+
viewer: VIEWER_LABELS_ES,
|
|
1064
|
+
comments: COMMENT_LABELS_ES
|
|
811
1065
|
};
|
|
812
1066
|
var TABLE = { en, fr, es };
|
|
813
1067
|
function stringsFor(locale) {
|
|
@@ -890,10 +1144,10 @@ function buildComponents(c, s) {
|
|
|
890
1144
|
for (const key of overrides) if (c[key]) defaults[key] = c[key];
|
|
891
1145
|
return defaults;
|
|
892
1146
|
}
|
|
893
|
-
function HastContent({ tree, title, components = {}, locale }) {
|
|
1147
|
+
function HastContent({ tree, title, description, components = {}, locale }) {
|
|
894
1148
|
let root;
|
|
895
1149
|
try {
|
|
896
|
-
root = sanitizeHast(tree, title);
|
|
1150
|
+
root = sanitizeHast(tree, title, description);
|
|
897
1151
|
} catch (error) {
|
|
898
1152
|
if (!(error instanceof HastLimitError)) throw error;
|
|
899
1153
|
const s = stringsFor(locale);
|
|
@@ -919,6 +1173,7 @@ function TrustedServerHtml({ html }) {
|
|
|
919
1173
|
var import_mermaid_diagram2 = require("./mermaid-diagram.cjs");
|
|
920
1174
|
|
|
921
1175
|
// src/react/pages.tsx
|
|
1176
|
+
var import_comments = require("./comments.cjs");
|
|
922
1177
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
923
1178
|
function Slot({ name, slots, tag: Tag = "div", className }) {
|
|
924
1179
|
const fill = slots?.[name];
|
|
@@ -987,7 +1242,7 @@ function Toc({ toc, c, aside }) {
|
|
|
987
1242
|
}
|
|
988
1243
|
function Body({ article, components, locale }) {
|
|
989
1244
|
const { content, publication } = article;
|
|
990
|
-
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 }) });
|
|
1245
|
+
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 }) });
|
|
991
1246
|
}
|
|
992
1247
|
function Languages({ alternates, current, c }) {
|
|
993
1248
|
if (alternates.length < 2) return null;
|
|
@@ -1000,7 +1255,32 @@ function Languages({ alternates, current, c }) {
|
|
|
1000
1255
|
}) })
|
|
1001
1256
|
] });
|
|
1002
1257
|
}
|
|
1003
|
-
|
|
1258
|
+
var BARE_HTTPS_ORIGIN = /^https:\/\/[^/]+$/;
|
|
1259
|
+
function articleJsonLd(article, origin, c, author) {
|
|
1260
|
+
const { publication: pub } = article;
|
|
1261
|
+
const url = (path) => origin + encodeURI(c.href(path, pub.locale));
|
|
1262
|
+
const graph = {
|
|
1263
|
+
"@context": "https://schema.org",
|
|
1264
|
+
"@graph": [
|
|
1265
|
+
{
|
|
1266
|
+
"@type": "BlogPosting",
|
|
1267
|
+
headline: pub.title,
|
|
1268
|
+
...pub.description ? { description: pub.description } : {},
|
|
1269
|
+
datePublished: pub.published_at,
|
|
1270
|
+
...pub.updated_at ? { dateModified: pub.updated_at } : {},
|
|
1271
|
+
...author ? { author: { "@type": "Person", name: author } } : {},
|
|
1272
|
+
inLanguage: pub.locale,
|
|
1273
|
+
mainEntityOfPage: url(pub.canonical_path)
|
|
1274
|
+
},
|
|
1275
|
+
{
|
|
1276
|
+
"@type": "BreadcrumbList",
|
|
1277
|
+
itemListElement: article.breadcrumbs.map((b, i) => ({ "@type": "ListItem", position: i + 1, name: b.title, item: url(b.canonical_path) }))
|
|
1278
|
+
}
|
|
1279
|
+
]
|
|
1280
|
+
};
|
|
1281
|
+
return JSON.stringify(graph).replace(/</g, "\\u003c");
|
|
1282
|
+
}
|
|
1283
|
+
function ArticlePage({ article, engagement, origin, ...base }) {
|
|
1004
1284
|
const { publication: pub } = article;
|
|
1005
1285
|
const c = ctx(base, pub.locale);
|
|
1006
1286
|
const { s } = c;
|
|
@@ -1045,9 +1325,11 @@ function ArticlePage({ article, ...base }) {
|
|
|
1045
1325
|
] }),
|
|
1046
1326
|
toc.narrow,
|
|
1047
1327
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
1328
|
+
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,
|
|
1048
1329
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Pager, { prev: article.prev, next: article.next, c }),
|
|
1049
1330
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.after", slots: base.slots, className: "hyle-after" }),
|
|
1050
|
-
toc.wide
|
|
1331
|
+
toc.wide,
|
|
1332
|
+
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
|
|
1051
1333
|
] }) });
|
|
1052
1334
|
}
|
|
1053
1335
|
function ListPage({ list, olderHref, description, ...base }) {
|
|
@@ -1095,65 +1377,337 @@ function ListPage({ list, olderHref, description, ...base }) {
|
|
|
1095
1377
|
] }) : null
|
|
1096
1378
|
] }) });
|
|
1097
1379
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1380
|
+
|
|
1381
|
+
// src/react/index.ts
|
|
1382
|
+
var import_comments2 = require("./comments.cjs");
|
|
1383
|
+
|
|
1384
|
+
// src/react/comments-api.ts
|
|
1385
|
+
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1386
|
+
var count = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.trunc(v) : 0;
|
|
1387
|
+
function toComment(raw) {
|
|
1388
|
+
if (!isObject2(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string") return void 0;
|
|
1389
|
+
const depth = typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1;
|
|
1390
|
+
const author = isObject2(raw.author) && typeof raw.author.name === "string" ? raw.author.name : void 0;
|
|
1391
|
+
const name = typeof raw.author_name === "string" ? raw.author_name : author;
|
|
1392
|
+
const body = isObject2(raw.body) && raw.body.format === "hast" ? { format: "hast", tree: raw.body.tree } : null;
|
|
1393
|
+
const removed = raw.removed === true || body === null;
|
|
1394
|
+
return {
|
|
1395
|
+
id: raw.id,
|
|
1396
|
+
parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
|
|
1397
|
+
depth,
|
|
1398
|
+
author_name: name ?? null,
|
|
1399
|
+
created_at: raw.created_at,
|
|
1400
|
+
edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
|
|
1401
|
+
like_count: count(raw.like_count),
|
|
1402
|
+
removed,
|
|
1403
|
+
...removed && (raw.removed_by === "moderator" || raw.removed_by === "author") ? { removed_by: raw.removed_by } : {},
|
|
1404
|
+
body,
|
|
1405
|
+
// Viewer members exist only on a live comment of a viewer-aware listing; a tombstone never carries them.
|
|
1406
|
+
...!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 } : {}
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
function toHeld(raw) {
|
|
1410
|
+
if (!isObject2(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string" || !isObject2(raw.body) || raw.body.format !== "hast") return void 0;
|
|
1411
|
+
const author = isObject2(raw.author) && typeof raw.author.name === "string" ? raw.author.name : null;
|
|
1412
|
+
return {
|
|
1413
|
+
id: raw.id,
|
|
1414
|
+
parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
|
|
1415
|
+
depth: typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1,
|
|
1416
|
+
author_name: author,
|
|
1417
|
+
created_at: raw.created_at,
|
|
1418
|
+
edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
|
|
1419
|
+
can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null,
|
|
1420
|
+
body: { format: "hast", tree: raw.body.tree }
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
function parseListing(data) {
|
|
1424
|
+
if (!isObject2(data) || data.kind !== "comments" || !Array.isArray(data.comments)) return void 0;
|
|
1425
|
+
const comments = data.comments.map(toComment).filter((c) => c !== void 0);
|
|
1426
|
+
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) } : {};
|
|
1427
|
+
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 };
|
|
1428
|
+
}
|
|
1429
|
+
var untilMs = (iso) => {
|
|
1430
|
+
const t = iso ? Date.parse(iso) : NaN;
|
|
1431
|
+
return Number.isFinite(t) ? t : void 0;
|
|
1432
|
+
};
|
|
1433
|
+
function buildThread(listing, localHeld) {
|
|
1434
|
+
const byId = /* @__PURE__ */ new Map();
|
|
1435
|
+
const roots = [];
|
|
1436
|
+
const place = (node, parentId) => {
|
|
1437
|
+
const parent = parentId ? byId.get(parentId) : void 0;
|
|
1438
|
+
(parent ? parent.kids : roots).push(node);
|
|
1439
|
+
};
|
|
1440
|
+
for (const c of listing.comments) {
|
|
1441
|
+
if (byId.has(c.id)) continue;
|
|
1442
|
+
const removed = c.removed;
|
|
1443
|
+
const node = {
|
|
1444
|
+
id: c.id,
|
|
1445
|
+
depth: c.depth,
|
|
1446
|
+
status: removed ? "removed" : "visible",
|
|
1447
|
+
removedBy: removed ? c.removed_by : void 0,
|
|
1448
|
+
mine: !removed && c.mine === true,
|
|
1449
|
+
canEditUntil: untilMs(c.can_edit_until),
|
|
1450
|
+
likedByMe: !removed && c.liked_by_me === true,
|
|
1451
|
+
name: removed ? null : c.author_name ?? null,
|
|
1452
|
+
createdAt: c.created_at,
|
|
1453
|
+
editedAt: c.edited_at,
|
|
1454
|
+
likes: c.like_count,
|
|
1455
|
+
tree: c.body?.tree,
|
|
1456
|
+
text: void 0,
|
|
1457
|
+
kids: []
|
|
1458
|
+
};
|
|
1459
|
+
place(node, c.parent_id === c.id ? null : c.parent_id);
|
|
1460
|
+
byId.set(c.id, node);
|
|
1461
|
+
}
|
|
1462
|
+
const mine = [];
|
|
1463
|
+
const addHeld = (node, parentId, oldestFirst) => {
|
|
1464
|
+
const parent = parentId ? byId.get(parentId) : void 0;
|
|
1465
|
+
if (parent) parent.kids.push(node);
|
|
1466
|
+
else if (oldestFirst) mine.unshift(node);
|
|
1467
|
+
else mine.push(node);
|
|
1468
|
+
};
|
|
1469
|
+
const heldIds = /* @__PURE__ */ new Set();
|
|
1470
|
+
for (const h of listing.mine_held ?? []) {
|
|
1471
|
+
heldIds.add(h.id);
|
|
1472
|
+
const parent = h.parent_id ? byId.get(h.parent_id) : void 0;
|
|
1473
|
+
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);
|
|
1474
|
+
}
|
|
1475
|
+
if (listing.mine_held === void 0) {
|
|
1476
|
+
for (const h of localHeld) {
|
|
1477
|
+
if (byId.has(h.id) || heldIds.has(h.id)) continue;
|
|
1478
|
+
const parent = h.parentId ? byId.get(h.parentId) : void 0;
|
|
1479
|
+
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);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
return [...mine, ...roots];
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// src/react/comments-body.tsx
|
|
1486
|
+
var import_hast_util_to_jsx_runtime2 = require("hast-util-to-jsx-runtime");
|
|
1487
|
+
var import_react2 = require("react");
|
|
1488
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1489
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1490
|
+
var ALLOWED = /* @__PURE__ */ new Set(["p", "a", "em", "strong", "del", "code", "pre", "blockquote", "ul", "ol", "li", "br"]);
|
|
1491
|
+
var LINK_REL = "nofollow ugc noopener noreferrer";
|
|
1492
|
+
function narrow(node) {
|
|
1493
|
+
if (node.type === "text") return [node];
|
|
1494
|
+
if (node.type !== "element") return [];
|
|
1495
|
+
const children = node.children.flatMap(narrow);
|
|
1496
|
+
if (!ALLOWED.has(node.tagName)) return children;
|
|
1497
|
+
if (node.tagName === "a") {
|
|
1498
|
+
const href = node.properties.href;
|
|
1499
|
+
if (!isSafeUrl(href, "href")) return children;
|
|
1500
|
+
return [{ type: "element", tagName: "a", properties: { href: String(href), rel: LINK_REL.split(" ") }, children }];
|
|
1501
|
+
}
|
|
1502
|
+
return [{ type: "element", tagName: node.tagName, properties: {}, children: node.tagName === "br" ? [] : children }];
|
|
1503
|
+
}
|
|
1504
|
+
function CommentBody({ tree }) {
|
|
1505
|
+
let children;
|
|
1506
|
+
try {
|
|
1507
|
+
children = sanitizeHast(tree).children.flatMap((n) => narrow(n));
|
|
1508
|
+
} catch (error) {
|
|
1509
|
+
if (error instanceof HastLimitError) return null;
|
|
1510
|
+
throw error;
|
|
1511
|
+
}
|
|
1512
|
+
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" }) });
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
// src/react/embed.tsx
|
|
1516
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1517
|
+
function HyleListView({ items, layout = "list", title, headingLevel = 2, moreHref, ...base }) {
|
|
1518
|
+
const c = ctx(base, "en");
|
|
1519
|
+
const { s, Link } = c;
|
|
1520
|
+
const Row = base.slots?.["list.item"];
|
|
1521
|
+
const Heading = `h${headingLevel}`;
|
|
1522
|
+
const safe = items.filter((item) => item.canonical_path.startsWith("/"));
|
|
1523
|
+
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;
|
|
1524
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle hyle-embed", "data-layout": layout, lang: c.locale, children: [
|
|
1525
|
+
title ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Heading, { className: "hyle-title", children: title }) : null,
|
|
1526
|
+
/* @__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: [
|
|
1527
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: item.published_at, title: item.published_at, children: formatDate(item.published_at, c.locale) }),
|
|
1528
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
1529
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "t", children: item.title }),
|
|
1530
|
+
item.description ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: item.description }) : null
|
|
1531
|
+
] })
|
|
1532
|
+
] }) }, item.canonical_path)) }),
|
|
1533
|
+
moreHref ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { className: "hyle-more", href: moreHref, children: s.viewAll }) : null
|
|
1103
1534
|
] });
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1535
|
+
}
|
|
1536
|
+
function HyleArticleView({ article, headingLevel = 2, ...base }) {
|
|
1537
|
+
const { publication: pub } = article;
|
|
1538
|
+
const c = ctx(base, pub.locale);
|
|
1539
|
+
const Heading = `h${headingLevel}`;
|
|
1540
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle hyle-embed", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("article", { lang: c.locale, children: [
|
|
1541
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("header", { className: "hyle-head", children: [
|
|
1542
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Heading, { className: "hyle-title", children: pub.title }),
|
|
1543
|
+
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
1544
|
+
/* @__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) }) }) })
|
|
1545
|
+
] }),
|
|
1546
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
1547
|
+
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: [
|
|
1548
|
+
c.s.readAtSource,
|
|
1549
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "hyle-sr", children: [
|
|
1550
|
+
": ",
|
|
1551
|
+
pub.title
|
|
1552
|
+
] })
|
|
1553
|
+
] }) : null
|
|
1554
|
+
] }) });
|
|
1555
|
+
}
|
|
1556
|
+
var initials = (name) => name.trim().split(/\s+/).slice(0, 2).map((w) => [...w][0] ?? "").join("").toUpperCase() || "?";
|
|
1557
|
+
function StaticThread({ nodes, locale, s, level = 1 }) {
|
|
1558
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ol", { className: "hyle-cm-list", role: "list", children: nodes.map((node) => {
|
|
1559
|
+
const kids = node.kids.length > 0 && level < 32 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StaticThread, { nodes: node.kids, locale, s, level: level + 1 }) : null;
|
|
1560
|
+
if (node.status === "removed") {
|
|
1561
|
+
const why = node.removedBy === "moderator" ? s.removedByModerator : node.removedBy === "author" ? s.removedByAuthor : s.removed;
|
|
1562
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { className: "hyle-cm", "data-depth": node.depth, "data-status": "removed", "data-removed-by": node.removedBy, children: [
|
|
1563
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("article", { "aria-label": why, children: [
|
|
1564
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "ban" }) }),
|
|
1565
|
+
/* @__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 }) }) })
|
|
1566
|
+
] }),
|
|
1567
|
+
kids
|
|
1568
|
+
] }, node.id);
|
|
1569
|
+
}
|
|
1570
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { className: "hyle-cm", "data-depth": node.depth, "data-status": "visible", children: [
|
|
1571
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("article", { children: [
|
|
1572
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: initials(node.name ?? "") }),
|
|
1573
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-main", children: [
|
|
1574
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-by", children: [
|
|
1575
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: node.name }),
|
|
1576
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
1577
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: node.createdAt, title: node.createdAt, children: formatDate(node.createdAt, locale) }),
|
|
1578
|
+
node.editedAt ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1579
|
+
" ",
|
|
1580
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { "aria-hidden": "true", children: "\xB7" }),
|
|
1581
|
+
" ",
|
|
1582
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: s.edited })
|
|
1583
|
+
] }) : null
|
|
1584
|
+
] })
|
|
1585
|
+
] }),
|
|
1586
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CommentBody, { tree: node.tree })
|
|
1587
|
+
] })
|
|
1588
|
+
] }),
|
|
1589
|
+
kids
|
|
1590
|
+
] }, node.id);
|
|
1591
|
+
}) });
|
|
1592
|
+
}
|
|
1593
|
+
function HyleCommentsView({ listing, locale }) {
|
|
1594
|
+
const thread = buildThread(listing, []);
|
|
1595
|
+
if (thread.length === 0) return null;
|
|
1596
|
+
const s = stringsFor(locale).comments;
|
|
1597
|
+
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: [
|
|
1598
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-cm-head", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("h2", { children: [
|
|
1599
|
+
s.heading,
|
|
1600
|
+
" ",
|
|
1601
|
+
/* @__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 })
|
|
1602
|
+
] }) }),
|
|
1603
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StaticThread, { nodes: thread, locale, s }),
|
|
1604
|
+
listing.truncated ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-cm-note", children: s.truncated }) : null
|
|
1605
|
+
] }) });
|
|
1606
|
+
}
|
|
1607
|
+
function HyleCommentsFallback({ locale }) {
|
|
1608
|
+
const s = stringsFor(locale).comments;
|
|
1609
|
+
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: [
|
|
1610
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sr", children: s.loading }),
|
|
1611
|
+
/* @__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: [
|
|
1612
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk c" }),
|
|
1613
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
1614
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: 120 } }),
|
|
1615
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: "100%" } }),
|
|
1616
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: "72%" } })
|
|
1617
|
+
] })
|
|
1618
|
+
] }, i)) })
|
|
1619
|
+
] }) }) });
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
// src/react/docs.tsx
|
|
1623
|
+
var import_docs_enhance = require("./docs-enhance.cjs");
|
|
1624
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1625
|
+
var ROOT_ID = "hyle-docs";
|
|
1626
|
+
var NAV_ID = "hyle-docs-nav";
|
|
1627
|
+
function navTreeOf(article) {
|
|
1628
|
+
if (article.nav && !article.nav.truncated && article.nav.items.length > 0) return article.nav.items;
|
|
1629
|
+
const { publication: pub } = article;
|
|
1630
|
+
const here = {
|
|
1631
|
+
slug: pub.slug,
|
|
1632
|
+
title: pub.title,
|
|
1633
|
+
canonical_path: pub.canonical_path,
|
|
1634
|
+
children: article.children.map((child) => ({ ...child, children: [] }))
|
|
1635
|
+
};
|
|
1636
|
+
return [article.ancestors.reduceRight((inner, a) => ({ ...a, children: [inner] }), here)];
|
|
1637
|
+
}
|
|
1638
|
+
function pathTo(nodes, path) {
|
|
1639
|
+
for (const node of nodes) {
|
|
1640
|
+
if (node.canonical_path === path) return [node.canonical_path];
|
|
1641
|
+
const below = pathTo(node.children, path);
|
|
1642
|
+
if (below.length > 0) return [node.canonical_path, ...below];
|
|
1643
|
+
}
|
|
1644
|
+
return [];
|
|
1645
|
+
}
|
|
1646
|
+
function Branch({ nodes, current, onPath, c }) {
|
|
1647
|
+
const { Link } = c;
|
|
1648
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { children: nodes.map((node) => {
|
|
1649
|
+
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 });
|
|
1650
|
+
if (node.children.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { children: link }, node.canonical_path);
|
|
1651
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("details", { ...onPath.has(node.canonical_path) ? { open: true } : {}, children: [
|
|
1652
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("summary", { children: [
|
|
1653
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "chev" }),
|
|
1654
|
+
link
|
|
1655
|
+
] }),
|
|
1656
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Branch, { nodes: node.children, current, onPath, c })
|
|
1657
|
+
] }) }, node.canonical_path);
|
|
1658
|
+
}) });
|
|
1112
1659
|
}
|
|
1113
1660
|
function DocsPage({ article, ...base }) {
|
|
1114
1661
|
const { publication: pub } = article;
|
|
1115
1662
|
const c = ctx(base, pub.locale);
|
|
1116
1663
|
const { Link, s } = c;
|
|
1117
1664
|
const toc = Toc({ toc: article.toc, c });
|
|
1665
|
+
const tree = navTreeOf(article);
|
|
1666
|
+
const onPath = new Set(pathTo(tree, pub.canonical_path));
|
|
1118
1667
|
const siteName = article.breadcrumbs[0]?.title ?? "";
|
|
1119
|
-
const
|
|
1120
|
-
const side = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1121
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-side-head", children: [
|
|
1122
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: siteName }),
|
|
1123
|
-
version
|
|
1124
|
-
] }),
|
|
1125
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "docs.sidebar-header", slots: base.slots, className: "hyle-side-slot" }),
|
|
1126
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(DocsTree, { article, c }),
|
|
1127
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "docs.sidebar-footer", slots: base.slots, className: "hyle-side-slot" })
|
|
1128
|
-
] });
|
|
1668
|
+
const headingIds = article.toc.filter((t) => t.depth === 2 || t.depth === 3).map((t) => scopeId(t.id));
|
|
1129
1669
|
const notTranslated = article.fallback ? s.fallbackTitle.replace("{language}", languageName(article.fallback.requested_locale, c.locale)) : void 0;
|
|
1130
|
-
return /* @__PURE__ */ (0,
|
|
1131
|
-
/* @__PURE__ */ (0,
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1670
|
+
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: [
|
|
1671
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_docs_enhance.DocsEnhance, { headingIds, rootId: ROOT_ID }),
|
|
1672
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("button", { type: "button", className: "hyle-nav-bar", popoverTarget: NAV_ID, children: [
|
|
1673
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "file" }),
|
|
1674
|
+
s.menu,
|
|
1675
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "cur", children: pub.title }),
|
|
1676
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "chev-down", className: "hyle-chev" })
|
|
1677
|
+
] }),
|
|
1678
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("aside", { className: "hyle-nav-d", id: NAV_ID, popover: "auto", "aria-label": s.docs, children: [
|
|
1679
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-side-head", children: [
|
|
1680
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("b", { children: siteName }),
|
|
1681
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "docs.version", slots: base.slots, tag: "span" }),
|
|
1682
|
+
/* @__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" }) })
|
|
1137
1683
|
] }),
|
|
1138
|
-
/* @__PURE__ */ (0,
|
|
1684
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "docs.sidebar-header", slots: base.slots, className: "hyle-side-slot" }),
|
|
1685
|
+
/* @__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 }) }),
|
|
1686
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "docs.sidebar-footer", slots: base.slots, className: "hyle-side-slot" })
|
|
1139
1687
|
] }),
|
|
1140
|
-
/* @__PURE__ */ (0,
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
/* @__PURE__ */ (0,
|
|
1144
|
-
|
|
1145
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: notTranslated }),
|
|
1688
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-docs-main", "data-hyle-page": "docs", children: [
|
|
1689
|
+
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1690
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "alert" }),
|
|
1691
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
|
|
1692
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("b", { children: notTranslated }),
|
|
1146
1693
|
" ",
|
|
1147
1694
|
s.fallbackBody
|
|
1148
1695
|
] })
|
|
1149
1696
|
] }) : null,
|
|
1150
|
-
/* @__PURE__ */ (0,
|
|
1151
|
-
/* @__PURE__ */ (0,
|
|
1152
|
-
pub.description ? /* @__PURE__ */ (0,
|
|
1697
|
+
/* @__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)) }) }),
|
|
1698
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h1", { className: "hyle-title", children: pub.title }),
|
|
1699
|
+
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
1700
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("p", { className: "hyle-updated", children: [
|
|
1701
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "calendar" }),
|
|
1702
|
+
s.updated,
|
|
1703
|
+
" ",
|
|
1704
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("time", { dateTime: pub.updated_at, title: pub.updated_at, children: formatDate(pub.updated_at, c.locale) })
|
|
1705
|
+
] }),
|
|
1153
1706
|
toc.narrow,
|
|
1154
|
-
/* @__PURE__ */ (0,
|
|
1155
|
-
/* @__PURE__ */ (0,
|
|
1156
|
-
/* @__PURE__ */ (0,
|
|
1707
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
1708
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Pager, { prev: article.prev, next: article.next, c }),
|
|
1709
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Slot, { name: "docs.after", slots: base.slots, className: "hyle-after" }),
|
|
1710
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "hyle-docs-end", "aria-hidden": "true" })
|
|
1157
1711
|
] }),
|
|
1158
1712
|
toc.wide
|
|
1159
1713
|
] }) });
|
|
@@ -1208,8 +1762,9 @@ function fetchResolver(options) {
|
|
|
1208
1762
|
const client = createHyleClient({ baseUrl: options.baseUrl, token: options.token });
|
|
1209
1763
|
const revalidate = options.revalidate ?? DEFAULT_REVALIDATE;
|
|
1210
1764
|
const tags = workspaceTags(options.workspaceId, options.sections);
|
|
1211
|
-
return (path, locale, limit, cursor) => client.resolve({
|
|
1765
|
+
return (path, locale, limit, cursor, nav) => client.resolve({
|
|
1212
1766
|
path,
|
|
1767
|
+
...nav !== void 0 ? { nav } : {},
|
|
1213
1768
|
...locale !== void 0 ? { locale } : {},
|
|
1214
1769
|
...limit !== void 0 ? { limit } : {},
|
|
1215
1770
|
...cursor !== void 0 ? { cursor } : {},
|
|
@@ -1241,7 +1796,7 @@ function isRejectedRequest(error) {
|
|
|
1241
1796
|
}
|
|
1242
1797
|
|
|
1243
1798
|
// src/next/page.tsx
|
|
1244
|
-
var
|
|
1799
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1245
1800
|
function hylePage(options) {
|
|
1246
1801
|
const resolve = resolverFor(options);
|
|
1247
1802
|
return async function HylePage({ params, searchParams }) {
|
|
@@ -1249,17 +1804,17 @@ function hylePage(options) {
|
|
|
1249
1804
|
if (path === void 0) (0, import_navigation2.notFound)();
|
|
1250
1805
|
try {
|
|
1251
1806
|
const cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
1252
|
-
const result = await resolve(path, locale, options.listLimit, cursor);
|
|
1807
|
+
const result = await resolve(path, locale, options.listLimit, cursor, options.layout === "docs" ? "tree" : void 0);
|
|
1253
1808
|
switch (result.kind) {
|
|
1254
1809
|
case "article": {
|
|
1255
1810
|
const props = { article: result, components: options.components, slots: options.slots, locale, toHref };
|
|
1256
|
-
return options.layout === "docs" ? /* @__PURE__ */ (0,
|
|
1811
|
+
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 } : {} });
|
|
1257
1812
|
}
|
|
1258
1813
|
case "list": {
|
|
1259
1814
|
const list = options.list?.title ? { ...result, section: { ...result.section, title: options.list.title } } : result;
|
|
1260
1815
|
const next = options.paginate === "searchParams" ? validCursor(result.next_cursor) : void 0;
|
|
1261
1816
|
const olderHref = next ? `${toHref(path)}?cursor=${next}` : void 0;
|
|
1262
|
-
return /* @__PURE__ */ (0,
|
|
1817
|
+
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 });
|
|
1263
1818
|
}
|
|
1264
1819
|
case "redirect": {
|
|
1265
1820
|
const to = safeRedirectTarget(result.to);
|
|
@@ -1315,15 +1870,21 @@ async function hyleSitemap(options) {
|
|
|
1315
1870
|
// src/next/metadata.ts
|
|
1316
1871
|
function hyleMetadata(options) {
|
|
1317
1872
|
const resolve = resolverFor(options);
|
|
1318
|
-
return async function generateMetadata({ params }) {
|
|
1873
|
+
return async function generateMetadata({ params, searchParams }) {
|
|
1319
1874
|
const { path, locale, toHref } = routeContext(options, await params ?? {});
|
|
1320
1875
|
if (path === void 0) return {};
|
|
1321
1876
|
try {
|
|
1322
|
-
const
|
|
1877
|
+
const cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
1878
|
+
const result = await resolve(path, locale, options.listLimit, cursor, options.layout === "docs" ? "tree" : void 0);
|
|
1323
1879
|
if (result.kind === "list") {
|
|
1324
|
-
const title = options.list?.title || result.section.title;
|
|
1880
|
+
const title = (options.list?.title || result.section.title) + (cursor ? ` - ${stringsFor(locale).older}` : "");
|
|
1325
1881
|
const description2 = options.list?.description;
|
|
1326
|
-
return {
|
|
1882
|
+
return {
|
|
1883
|
+
title,
|
|
1884
|
+
...description2 ? { description: description2 } : {},
|
|
1885
|
+
alternates: { canonical: toHref(path) + (cursor ? `?cursor=${cursor}` : "") },
|
|
1886
|
+
openGraph: { title, ...description2 ? { description: description2 } : {} }
|
|
1887
|
+
};
|
|
1327
1888
|
}
|
|
1328
1889
|
if (result.kind !== "article") return {};
|
|
1329
1890
|
const { publication: pub, alternates } = result;
|
|
@@ -1334,7 +1895,7 @@ function hyleMetadata(options) {
|
|
|
1334
1895
|
...description ? { description } : {},
|
|
1335
1896
|
alternates: {
|
|
1336
1897
|
canonical,
|
|
1337
|
-
...alternates.length > 1 ? { languages: Object.fromEntries(alternates.map((a) => [a.locale, toHref(a.canonical_path, a.locale)])) } : {}
|
|
1898
|
+
...alternates.length > 1 ? { languages: { ...Object.fromEntries(alternates.map((a) => [a.locale, toHref(a.canonical_path, a.locale)])), "x-default": canonical } } : {}
|
|
1338
1899
|
},
|
|
1339
1900
|
openGraph: {
|
|
1340
1901
|
type: "article",
|
|
@@ -1566,10 +2127,371 @@ function createAssetRoute(options) {
|
|
|
1566
2127
|
}
|
|
1567
2128
|
return { GET: (req, ctx2) => serve(req, ctx2, false), HEAD: (req, ctx2) => serve(req, ctx2, true) };
|
|
1568
2129
|
}
|
|
2130
|
+
|
|
2131
|
+
// src/next/embed.tsx
|
|
2132
|
+
var import_navigation4 = require("next/navigation");
|
|
2133
|
+
|
|
2134
|
+
// src/next/engage.ts
|
|
2135
|
+
var ENGAGE_CSRF_HEADER = "x-hyle-engage";
|
|
2136
|
+
var DEFAULT_TIMEOUT_MS3 = 1e4;
|
|
2137
|
+
var DEFAULT_SHARE_MS = 3e3;
|
|
2138
|
+
var MAX_SHARED = 100;
|
|
2139
|
+
var MAX_SHARED_BYTES = 8 * 1024 * 1024;
|
|
2140
|
+
var MAX_SHARED_ENTRY_BYTES = 256 * 1024;
|
|
2141
|
+
var MAX_BODY_BYTES2 = 20 * 1024;
|
|
2142
|
+
var MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
2143
|
+
var MAX_COMMENT_CHARACTERS = 4e3;
|
|
2144
|
+
var MAX_PATH_LENGTH2 = 1024;
|
|
2145
|
+
var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
2146
|
+
var CONTROL = /[\u0000-\u001f\u007f\\]/;
|
|
2147
|
+
var HEADERS = { "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" };
|
|
2148
|
+
var isSwitchedOff3 = (value) => {
|
|
2149
|
+
const v = value?.trim().toLowerCase() ?? "";
|
|
2150
|
+
return v !== "" && v !== "1" && v !== "true";
|
|
2151
|
+
};
|
|
2152
|
+
var json = (status, body, extra = {}) => new Response(JSON.stringify(body), { status, headers: { ...HEADERS, "Content-Type": "application/json; charset=utf-8", ...extra } });
|
|
2153
|
+
var refuse = (status, code, extra = {}) => json(status, { error: { code } }, extra);
|
|
2154
|
+
function isSitePath(value) {
|
|
2155
|
+
if (typeof value !== "string" || value.length > MAX_PATH_LENGTH2 || !value.startsWith("/") || value.startsWith("//")) return false;
|
|
2156
|
+
if (CONTROL.test(value) || /[?#]/.test(value)) return false;
|
|
2157
|
+
return !value.split("/").some((segment) => segment === "." || segment === "..");
|
|
2158
|
+
}
|
|
2159
|
+
function match(segments) {
|
|
2160
|
+
const [a, b, ...rest] = segments;
|
|
2161
|
+
if (a === "session" && b === void 0) return { local: "session", action: () => "session", methods: ["GET"], rebuild: () => void 0 };
|
|
2162
|
+
if (a === "comments" && b === void 0) {
|
|
2163
|
+
return {
|
|
2164
|
+
action: (m) => m === "GET" ? "comments.list" : "comments.create",
|
|
2165
|
+
methods: ["GET", "POST"],
|
|
2166
|
+
rebuild: (method, body, url) => {
|
|
2167
|
+
if (method === "GET") {
|
|
2168
|
+
const keys = [...url.searchParams.keys()];
|
|
2169
|
+
const path = url.searchParams.get("path");
|
|
2170
|
+
return keys.length === 1 && isSitePath(path) ? { upstream: "/comments", query: new URLSearchParams({ path }) } : void 0;
|
|
2171
|
+
}
|
|
2172
|
+
const clean2 = pick(body, ["path", "body", "parent_id"], ["path", "body"]);
|
|
2173
|
+
if (!clean2 || !isSitePath(clean2.path) || !isCommentText(clean2.body)) return void 0;
|
|
2174
|
+
if (clean2.parent_id === null) delete clean2.parent_id;
|
|
2175
|
+
if (clean2.parent_id !== void 0 && !(typeof clean2.parent_id === "string" && UUID2.test(clean2.parent_id))) return void 0;
|
|
2176
|
+
return { upstream: "/comments", body: clean2 };
|
|
2177
|
+
}
|
|
2178
|
+
};
|
|
2179
|
+
}
|
|
2180
|
+
if (a === "comments" && typeof b === "string" && UUID2.test(b) && rest.length === 0) {
|
|
2181
|
+
return {
|
|
2182
|
+
action: (m) => m === "PATCH" ? "comments.edit" : "comments.delete",
|
|
2183
|
+
methods: ["PATCH", "DELETE"],
|
|
2184
|
+
rebuild: (method, body) => {
|
|
2185
|
+
if (method === "DELETE") return body === void 0 ? { upstream: `/comments/${b}` } : void 0;
|
|
2186
|
+
const clean2 = pick(body, ["body"], ["body"]);
|
|
2187
|
+
return clean2 && isCommentText(clean2.body) ? { upstream: `/comments/${b}`, body: clean2 } : void 0;
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
2191
|
+
if (a === "reactions" && b === void 0) {
|
|
2192
|
+
return {
|
|
2193
|
+
action: (m) => m === "PUT" ? "reactions.add" : "reactions.remove",
|
|
2194
|
+
methods: ["PUT", "DELETE"],
|
|
2195
|
+
rebuild: (_method, body) => {
|
|
2196
|
+
const type = body?.subject_type;
|
|
2197
|
+
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;
|
|
2198
|
+
if (!clean2) return void 0;
|
|
2199
|
+
const valid = type === "article" ? isSitePath(clean2.path) : typeof clean2.comment_id === "string" && UUID2.test(clean2.comment_id);
|
|
2200
|
+
return valid ? { upstream: "/reactions", body: clean2 } : void 0;
|
|
2201
|
+
}
|
|
2202
|
+
};
|
|
2203
|
+
}
|
|
2204
|
+
return void 0;
|
|
2205
|
+
}
|
|
2206
|
+
function pick(body, allowed, required) {
|
|
2207
|
+
if (!body || Object.keys(body).some((k) => !allowed.includes(k)) || !required.every((k) => k in body)) return void 0;
|
|
2208
|
+
return Object.fromEntries(allowed.filter((k) => k in body).map((k) => [k, body[k]]));
|
|
2209
|
+
}
|
|
2210
|
+
function isCommentText(value) {
|
|
2211
|
+
return typeof value === "string" && value.trim().length > 0 && [...value].length <= MAX_COMMENT_CHARACTERS && !/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/.test(value);
|
|
2212
|
+
}
|
|
2213
|
+
function sameOriginProblem(req, write, allowedOrigins) {
|
|
2214
|
+
const site = req.headers.get("sec-fetch-site");
|
|
2215
|
+
if (site !== null && site !== "same-origin") return true;
|
|
2216
|
+
if (!write) return false;
|
|
2217
|
+
const origin = req.headers.get("origin");
|
|
2218
|
+
if (origin === null) return true;
|
|
2219
|
+
let parsed;
|
|
2220
|
+
try {
|
|
2221
|
+
parsed = new URL(origin);
|
|
2222
|
+
} catch {
|
|
2223
|
+
return true;
|
|
2224
|
+
}
|
|
2225
|
+
if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
|
|
2226
|
+
if (allowedOrigins) return !allowedOrigins.some((o) => safeOrigin(o) === parsed.origin);
|
|
2227
|
+
const host = req.headers.get("x-forwarded-host")?.split(",")[0]?.trim() || req.headers.get("host") || new URL(req.url).host;
|
|
2228
|
+
const proto = req.headers.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase();
|
|
2229
|
+
if (proto && proto !== parsed.protocol.slice(0, -1)) return true;
|
|
2230
|
+
return parsed.host !== host;
|
|
2231
|
+
}
|
|
2232
|
+
var safeOrigin = (value) => {
|
|
2233
|
+
try {
|
|
2234
|
+
return new URL(value).origin;
|
|
2235
|
+
} catch {
|
|
2236
|
+
return void 0;
|
|
2237
|
+
}
|
|
2238
|
+
};
|
|
2239
|
+
async function readBody(req, expected) {
|
|
2240
|
+
if (!expected) return { kind: "ok", body: void 0 };
|
|
2241
|
+
if (!/^application\/json(\s*;|$)/i.test(req.headers.get("content-type") ?? "")) return { kind: "refused", response: refuse(415, "UNSUPPORTED_MEDIA_TYPE") };
|
|
2242
|
+
if (Number(req.headers.get("content-length")) > MAX_BODY_BYTES2) return { kind: "refused", response: refuse(413, "PAYLOAD_TOO_LARGE") };
|
|
2243
|
+
if (!req.body) return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
2244
|
+
const reader = req.body.getReader();
|
|
2245
|
+
const chunks = [];
|
|
2246
|
+
let total = 0;
|
|
2247
|
+
for (; ; ) {
|
|
2248
|
+
const { done, value } = await reader.read();
|
|
2249
|
+
if (done) break;
|
|
2250
|
+
total += value.byteLength;
|
|
2251
|
+
if (total > MAX_BODY_BYTES2) {
|
|
2252
|
+
await reader.cancel().catch(() => {
|
|
2253
|
+
});
|
|
2254
|
+
return { kind: "refused", response: refuse(413, "PAYLOAD_TOO_LARGE") };
|
|
2255
|
+
}
|
|
2256
|
+
chunks.push(value);
|
|
2257
|
+
}
|
|
2258
|
+
try {
|
|
2259
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
2260
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return { kind: "ok", body: parsed };
|
|
2261
|
+
} catch {
|
|
2262
|
+
}
|
|
2263
|
+
return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
2264
|
+
}
|
|
2265
|
+
var SUB_CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
|
|
2266
|
+
function validReader(r) {
|
|
2267
|
+
if (!r || typeof r.sub !== "string" || typeof r.name !== "string") return null;
|
|
2268
|
+
if (r.sub.length < 1 || [...r.sub].length > 255 || SUB_CONTROL.test(r.sub)) return null;
|
|
2269
|
+
const name = cleanDisplayName(r.name);
|
|
2270
|
+
return name === void 0 ? null : { sub: r.sub, name };
|
|
2271
|
+
}
|
|
2272
|
+
function relayFailure(status, retryAfter) {
|
|
2273
|
+
if (status === 400) return refuse(400, "VALIDATION_ERROR");
|
|
2274
|
+
if (status === 404) return refuse(404, "NOT_FOUND");
|
|
2275
|
+
if (status === 409) return refuse(409, "INVALID_TRANSITION");
|
|
2276
|
+
if (status === 413) return refuse(413, "PAYLOAD_TOO_LARGE");
|
|
2277
|
+
if (status === 429) {
|
|
2278
|
+
const seconds = Math.min(3600, Math.max(1, Math.trunc(Number(retryAfter)) || 60));
|
|
2279
|
+
return refuse(429, "RATE_LIMITED", { "Retry-After": String(seconds) });
|
|
2280
|
+
}
|
|
2281
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2282
|
+
}
|
|
2283
|
+
function createEngagementRoute(options) {
|
|
2284
|
+
let ready;
|
|
2285
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
2286
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2287
|
+
let cacheBytes = 0;
|
|
2288
|
+
const clearCache = () => {
|
|
2289
|
+
cache.clear();
|
|
2290
|
+
cacheBytes = 0;
|
|
2291
|
+
};
|
|
2292
|
+
async function listing(viewer, call) {
|
|
2293
|
+
if (!viewer) return call(void 0);
|
|
2294
|
+
let out = await call(viewer.sign("read"));
|
|
2295
|
+
if (out.status === 401) out = await call(viewer.sign("read"));
|
|
2296
|
+
if (out.status !== 401 && out.status !== 404 && !(out.status === 429 && out.throttle === "viewer")) return out;
|
|
2297
|
+
return { ...await call(void 0), noShare: true };
|
|
2298
|
+
}
|
|
2299
|
+
function shared(key, call) {
|
|
2300
|
+
const ttl = options.cacheTtlMs ?? DEFAULT_SHARE_MS;
|
|
2301
|
+
if (ttl <= 0) return call();
|
|
2302
|
+
const hit = cache.get(key);
|
|
2303
|
+
if (hit && Date.now() - hit.at < ttl) {
|
|
2304
|
+
cache.delete(key);
|
|
2305
|
+
cache.set(key, hit);
|
|
2306
|
+
return hit.result;
|
|
2307
|
+
}
|
|
2308
|
+
if (hit) forget(key, hit);
|
|
2309
|
+
const entry = { at: Date.now(), result: call(), bytes: 0 };
|
|
2310
|
+
cache.set(key, entry);
|
|
2311
|
+
entry.result.then(
|
|
2312
|
+
(o) => {
|
|
2313
|
+
if (cache.get(key) !== entry) return;
|
|
2314
|
+
if (o.status !== 200 && o.status !== 404 || o.noShare || o.text.length > MAX_SHARED_ENTRY_BYTES) return forget(key, entry);
|
|
2315
|
+
entry.bytes = o.text.length;
|
|
2316
|
+
cacheBytes += entry.bytes;
|
|
2317
|
+
while ((cacheBytes > MAX_SHARED_BYTES || cache.size > MAX_SHARED) && cache.size > 0) {
|
|
2318
|
+
const oldest = cache.entries().next().value;
|
|
2319
|
+
forget(oldest[0], oldest[1]);
|
|
2320
|
+
}
|
|
2321
|
+
},
|
|
2322
|
+
() => forget(key, entry)
|
|
2323
|
+
);
|
|
2324
|
+
return entry.result;
|
|
2325
|
+
}
|
|
2326
|
+
function forget(key, entry) {
|
|
2327
|
+
if (cache.get(key) !== entry) return;
|
|
2328
|
+
cache.delete(key);
|
|
2329
|
+
cacheBytes -= entry.bytes;
|
|
2330
|
+
}
|
|
2331
|
+
function configured() {
|
|
2332
|
+
if (ready !== void 0) return ready;
|
|
2333
|
+
try {
|
|
2334
|
+
const baseUrl = options.baseUrl?.trim() ?? "";
|
|
2335
|
+
checkBaseUrl(baseUrl);
|
|
2336
|
+
if (!options.token?.trim() || !options.workspaceId?.trim() || !options.signingKey) throw new TypeError("not provisioned");
|
|
2337
|
+
ready = { base: baseUrl.replace(/\/+$/, ""), key: engagementSigningKey(options.signingKey.trim()) };
|
|
2338
|
+
} catch {
|
|
2339
|
+
ready = null;
|
|
2340
|
+
}
|
|
2341
|
+
return ready;
|
|
2342
|
+
}
|
|
2343
|
+
async function reader(req, config) {
|
|
2344
|
+
try {
|
|
2345
|
+
const found = validReader(await options.getReader(req));
|
|
2346
|
+
if (!found) return null;
|
|
2347
|
+
const claims = { sub: found.sub, name: found.name, workspace: options.workspaceId.trim() };
|
|
2348
|
+
const sign2 = (scope) => signReaderAssertion(config.key, claims, void 0, scope);
|
|
2349
|
+
return { reader: found, assertion: sign2(), sign: sign2 };
|
|
2350
|
+
} catch {
|
|
2351
|
+
return null;
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
async function handle(req, ctx2) {
|
|
2355
|
+
const env = options.env ?? process.env;
|
|
2356
|
+
if (isSwitchedOff3(env.HYLE_ENGAGE_ENABLED) || isSwitchedOff3(env.HYLE_CONTENT_ENABLED)) return refuse(404, "NOT_FOUND");
|
|
2357
|
+
const config = configured();
|
|
2358
|
+
const route = match((await ctx2.params).path ?? []);
|
|
2359
|
+
if (!config || !route) return refuse(404, "NOT_FOUND");
|
|
2360
|
+
if (!route.methods.includes(req.method)) return refuse(405, "METHOD_NOT_ALLOWED", { Allow: route.methods.join(", ") });
|
|
2361
|
+
const write = req.method !== "GET";
|
|
2362
|
+
if (sameOriginProblem(req, write, options.allowedOrigins)) return refuse(403, "FORBIDDEN");
|
|
2363
|
+
if (options.onRequest) {
|
|
2364
|
+
try {
|
|
2365
|
+
const early = await options.onRequest(req, { action: route.action(req.method) });
|
|
2366
|
+
if (early instanceof Response) {
|
|
2367
|
+
const headers = new Headers(early.headers);
|
|
2368
|
+
headers.set("cache-control", "no-store");
|
|
2369
|
+
return new Response(early.body, { status: early.status, headers });
|
|
2370
|
+
}
|
|
2371
|
+
} catch {
|
|
2372
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
if (route.local === "session") {
|
|
2376
|
+
const who = await reader(req, config);
|
|
2377
|
+
return json(200, { data: { reader: who ? { name: who.reader.name } : null } });
|
|
2378
|
+
}
|
|
2379
|
+
let assertion;
|
|
2380
|
+
let viewer = null;
|
|
2381
|
+
if (route.action(req.method) === "comments.list") viewer = await reader(req, config);
|
|
2382
|
+
if (write) {
|
|
2383
|
+
const who = await reader(req, config);
|
|
2384
|
+
if (!who) return refuse(401, "UNAUTHENTICATED");
|
|
2385
|
+
assertion = who.assertion;
|
|
2386
|
+
}
|
|
2387
|
+
const url = new URL(req.url);
|
|
2388
|
+
const hasBody = write && !(req.method === "DELETE" && (await ctx2.params).path?.[0] === "comments");
|
|
2389
|
+
const body = await readBody(req, hasBody);
|
|
2390
|
+
if (body.kind === "refused") return body.response;
|
|
2391
|
+
const built = route.rebuild(req.method, body.body, url);
|
|
2392
|
+
if (!built) return refuse(400, "VALIDATION_ERROR");
|
|
2393
|
+
const baseHeaders = new Headers({ authorization: `Bearer ${options.token.trim()}`, accept: "application/json" });
|
|
2394
|
+
if (built.body) baseHeaders.set("content-type", "application/json");
|
|
2395
|
+
const target = `${config.base}/cp1/engage${built.upstream}${built.query ? `?${built.query}` : ""}`;
|
|
2396
|
+
const call = async (withAssertion = assertion) => {
|
|
2397
|
+
const headers = new Headers(baseHeaders);
|
|
2398
|
+
if (withAssertion) headers.set("hyle-reader-assertion", withAssertion);
|
|
2399
|
+
const res = await fetchImpl(target, {
|
|
2400
|
+
method: req.method,
|
|
2401
|
+
headers,
|
|
2402
|
+
...built.body ? { body: JSON.stringify(built.body) } : {},
|
|
2403
|
+
redirect: "error",
|
|
2404
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS3)
|
|
2405
|
+
});
|
|
2406
|
+
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") };
|
|
2407
|
+
};
|
|
2408
|
+
try {
|
|
2409
|
+
const out = route.action(req.method) === "comments.list" ? await shared(`${viewer?.reader.sub ?? ""}
|
|
2410
|
+
${built.query.toString()}`, () => listing(viewer, call)) : await call();
|
|
2411
|
+
if (!out.ok) return relayFailure(out.status, out.retryAfter);
|
|
2412
|
+
if (write) clearCache();
|
|
2413
|
+
const data = JSON.parse(out.text).data;
|
|
2414
|
+
return typeof data === "object" && data !== null ? json(out.status === 201 ? 201 : 200, { data }) : refuse(502, "UPSTREAM_ERROR");
|
|
2415
|
+
} catch {
|
|
2416
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
return { GET: handle, POST: handle, PATCH: handle, PUT: handle, DELETE: handle };
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
// src/next/embed.tsx
|
|
2423
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
2424
|
+
async function resolveEmbed(options, run) {
|
|
2425
|
+
try {
|
|
2426
|
+
return { result: await run() };
|
|
2427
|
+
} catch (error) {
|
|
2428
|
+
if (isRejectedRequest(error)) return {};
|
|
2429
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2430
|
+
return { failure: options.onError ? options.onError(error) : null };
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
async function HyleList({ options, section, limit = 5, locale, layout, title, headingLevel, moreHref }) {
|
|
2434
|
+
const resolve = resolverFor(options);
|
|
2435
|
+
const route = routeContext(locale ? { ...options, locale } : options, {});
|
|
2436
|
+
const path = sitePathFrom(route.basePath, section && section !== "posts" ? [section] : void 0);
|
|
2437
|
+
if (path === void 0) return null;
|
|
2438
|
+
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale, limit));
|
|
2439
|
+
if (failure !== void 0) return failure;
|
|
2440
|
+
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 });
|
|
2441
|
+
}
|
|
2442
|
+
async function HyleArticle({ options, path, locale, headingLevel }) {
|
|
2443
|
+
if (!isSitePath(path)) return null;
|
|
2444
|
+
const resolve = resolverFor(options);
|
|
2445
|
+
const route = routeContext(locale ? { ...options, locale } : options, {});
|
|
2446
|
+
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale));
|
|
2447
|
+
if (failure !== void 0) return failure;
|
|
2448
|
+
if (result?.kind !== "article") return null;
|
|
2449
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HyleArticleView, { article: result, headingLevel, components: options.components, slots: options.slots, locale: route.locale, toHref: route.toHref });
|
|
2450
|
+
}
|
|
2451
|
+
var MAX_LISTING_BYTES = 4 * 1024 * 1024;
|
|
2452
|
+
var COMMENTS_TIMEOUT_MS = 1e4;
|
|
2453
|
+
async function HyleComments({ options, path, revalidate = 60, interactive }) {
|
|
2454
|
+
checkBaseUrl(options.baseUrl);
|
|
2455
|
+
if (!options.token) throw new TypeError("token is required");
|
|
2456
|
+
if (!isSitePath(path)) return null;
|
|
2457
|
+
const locale = options.locale ?? "en";
|
|
2458
|
+
let listing;
|
|
2459
|
+
let fetchedAt;
|
|
2460
|
+
try {
|
|
2461
|
+
const init = {
|
|
2462
|
+
headers: { authorization: `Bearer ${options.token}`, accept: "application/json" },
|
|
2463
|
+
redirect: "error",
|
|
2464
|
+
signal: AbortSignal.timeout(COMMENTS_TIMEOUT_MS),
|
|
2465
|
+
next: { revalidate }
|
|
2466
|
+
};
|
|
2467
|
+
const res = await fetch(`${options.baseUrl.replace(/\/+$/, "")}/cp1/engage/comments?${new URLSearchParams({ path })}`, init);
|
|
2468
|
+
if (!res.ok) {
|
|
2469
|
+
if (res.status !== 404) console.error(`hyle: comments answered HTTP ${res.status}`);
|
|
2470
|
+
return null;
|
|
2471
|
+
}
|
|
2472
|
+
listing = parseListing(JSON.parse(await readCapped(res, MAX_LISTING_BYTES)).data);
|
|
2473
|
+
const date = Date.parse(res.headers.get("date") ?? "");
|
|
2474
|
+
fetchedAt = Number.isFinite(date) ? date : void 0;
|
|
2475
|
+
} catch (error) {
|
|
2476
|
+
(0, import_navigation4.unstable_rethrow)(error);
|
|
2477
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2478
|
+
return null;
|
|
2479
|
+
}
|
|
2480
|
+
if (!listing) return null;
|
|
2481
|
+
if (!interactive) return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HyleCommentsView, { listing, locale });
|
|
2482
|
+
const config = interactive === true ? {} : interactive;
|
|
2483
|
+
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 }) });
|
|
2484
|
+
}
|
|
1569
2485
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1570
2486
|
0 && (module.exports = {
|
|
2487
|
+
ENGAGE_CSRF_HEADER,
|
|
2488
|
+
HyleArticle,
|
|
2489
|
+
HyleComments,
|
|
2490
|
+
HyleCommentsFallback,
|
|
2491
|
+
HyleList,
|
|
1571
2492
|
MOUNTS_MAX_STALE_MS,
|
|
1572
2493
|
createAssetRoute,
|
|
2494
|
+
createEngagementRoute,
|
|
1573
2495
|
createRevalidateRoute,
|
|
1574
2496
|
fetchResolver,
|
|
1575
2497
|
hyleMetadata,
|