@tdacorp/hyle-sdk 0.12.0 → 0.17.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 +46 -12
- package/dist/check-routes-bin.js +31 -18
- package/dist/{chunk-S7PCCEHP.js → chunk-6VOHFFA5.js} +4 -3
- package/dist/{chunk-ZQFYH4FX.js → chunk-DMK4XQLU.js} +497 -327
- package/dist/{chunk-N7ZQUAGM.js → chunk-MGSUQBDW.js} +19 -7
- package/dist/{chunk-R5EMI4HQ.js → chunk-PJMJMP66.js} +3 -1
- package/dist/comments.cjs +6 -4
- package/dist/comments.js +6 -5
- package/dist/{diagram-viewer-DYX6R63Y.js → diagram-viewer-FJPED4SN.js} +46 -26
- package/dist/{embed-jCaSI31t.d.cts → embed-BmdwA2G9.d.cts} +51 -5
- package/dist/{embed-DL5QIZRJ.d.ts → embed-DNTZ2UXv.d.ts} +51 -5
- package/dist/index.cjs +19 -7
- package/dist/index.d.cts +15 -8
- package/dist/index.d.ts +15 -8
- package/dist/index.js +1 -1
- package/dist/labels-nmukKYgL.d.cts +37 -0
- package/dist/labels-nmukKYgL.d.ts +37 -0
- package/dist/mermaid-diagram.cjs +59 -30
- package/dist/mermaid-diagram.d.cts +4 -37
- package/dist/mermaid-diagram.d.ts +4 -37
- package/dist/mermaid-diagram.js +7 -5
- package/dist/mermaid-image.cjs +1382 -0
- package/dist/mermaid-image.d.cts +29 -0
- package/dist/mermaid-image.d.ts +29 -0
- package/dist/mermaid-image.js +94 -0
- package/dist/next.cjs +1235 -789
- package/dist/next.d.cts +149 -24
- package/dist/next.d.ts +149 -24
- package/dist/next.js +887 -612
- package/dist/react.cjs +336 -196
- package/dist/react.d.cts +39 -7
- package/dist/react.d.ts +39 -7
- package/dist/react.js +1 -1
- package/dist/{resolve-DvmuBlpO.d.ts → resolve-Ae7UFjsQ.d.ts} +5 -5
- package/dist/{resolve-f6IJ6SL9.d.cts → resolve-euZ4-aC9.d.cts} +5 -5
- package/dist/styles.css +11 -22
- package/dist/{types-5D6ZD0Wi.d.cts → types-Czt887Iv.d.cts} +32 -3
- package/dist/{types-5D6ZD0Wi.d.ts → types-Czt887Iv.d.ts} +32 -3
- package/dist/use-cache.cjs +1 -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 +1 -1
package/dist/next.cjs
CHANGED
|
@@ -28,21 +28,26 @@ __export(next_exports, {
|
|
|
28
28
|
MOUNTS_MAX_STALE_MS: () => MOUNTS_MAX_STALE_MS,
|
|
29
29
|
createAssetRoute: () => createAssetRoute,
|
|
30
30
|
createEngagementRoute: () => createEngagementRoute,
|
|
31
|
+
createLlmsTxtRoute: () => createLlmsTxtRoute,
|
|
32
|
+
createMarkdownRoute: () => createMarkdownRoute,
|
|
33
|
+
createOgImageRoute: () => createOgImageRoute,
|
|
31
34
|
createRevalidateRoute: () => createRevalidateRoute,
|
|
32
35
|
fetchResolver: () => fetchResolver,
|
|
33
36
|
hyleFeed: () => hyleFeed,
|
|
37
|
+
hyleFeedLink: () => hyleFeedLink,
|
|
34
38
|
hyleMetadata: () => hyleMetadata,
|
|
35
39
|
hylePage: () => hylePage,
|
|
36
40
|
hyleRootMetadata: () => hyleRootMetadata,
|
|
37
41
|
hyleRootPage: () => hyleRootPage,
|
|
38
42
|
hyleRootSitemap: () => hyleRootSitemap,
|
|
39
43
|
hyleSitemap: () => hyleSitemap,
|
|
44
|
+
markdownRewritePath: () => markdownRewritePath,
|
|
40
45
|
workspaceTags: () => workspaceTags
|
|
41
46
|
});
|
|
42
47
|
module.exports = __toCommonJS(next_exports);
|
|
43
48
|
|
|
44
49
|
// src/next/page.tsx
|
|
45
|
-
var
|
|
50
|
+
var import_navigation3 = require("next/navigation");
|
|
46
51
|
|
|
47
52
|
// src/asset-path.ts
|
|
48
53
|
var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
|
|
@@ -159,21 +164,21 @@ function createHyleClient(options) {
|
|
|
159
164
|
if (opts.nav !== void 0) query.set("nav", opts.nav);
|
|
160
165
|
if (opts.cursor !== void 0) query.set("cursor", opts.cursor);
|
|
161
166
|
if (opts.limit !== void 0) query.set("limit", String(opts.limit));
|
|
162
|
-
const
|
|
163
|
-
const data =
|
|
167
|
+
const reply2 = await get("/cp1/read/resolve", query, opts.init);
|
|
168
|
+
const data = reply2.parsed?.data;
|
|
164
169
|
if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) {
|
|
165
170
|
const resolved = data;
|
|
166
|
-
if (resolved.kind === "article" && resolved.content.format
|
|
171
|
+
if (resolved.kind === "article" && resolved.content.format !== "hast" && resolved.content.format !== opts.format) throw failure(reply2);
|
|
167
172
|
return resolved;
|
|
168
173
|
}
|
|
169
|
-
throw failure(
|
|
174
|
+
throw failure(reply2);
|
|
170
175
|
}
|
|
171
176
|
async function mounts(opts = {}) {
|
|
172
|
-
const
|
|
173
|
-
const data =
|
|
177
|
+
const reply2 = await get("/cp1/read/mounts", new URLSearchParams(), opts.init);
|
|
178
|
+
const data = reply2.parsed?.data;
|
|
174
179
|
if (data?.cp === 1 && data.kind === "disabled") return data;
|
|
175
180
|
if (data?.cp === 1 && data.kind === "mounts" && isMounts(data)) return data;
|
|
176
|
-
throw failure(
|
|
181
|
+
throw failure(reply2);
|
|
177
182
|
}
|
|
178
183
|
async function asset(file, opts = {}) {
|
|
179
184
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
@@ -343,17 +348,20 @@ function okResponse(purged) {
|
|
|
343
348
|
// src/sitemap.ts
|
|
344
349
|
var PAGE_LIMIT = 100;
|
|
345
350
|
var DEFAULT_MAX_PAGES = 20;
|
|
346
|
-
var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
347
351
|
var UNSAFE_PATH = /[\\?#<>&"'\u0000- \u007f]/;
|
|
352
|
+
var LOCALE_TAG = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
|
|
353
|
+
var isSitePath = (path) => typeof path === "string" && path.startsWith("/") && !path.startsWith("//") && !UNSAFE_PATH.test(path);
|
|
354
|
+
function safeAlternates(raw) {
|
|
355
|
+
const kept = (raw ?? []).filter((a) => typeof a.locale === "string" && LOCALE_TAG.test(a.locale) && isSitePath(a.canonical_path));
|
|
356
|
+
return kept.length > 0 ? kept.map((a) => ({ locale: a.locale, path: a.canonical_path })) : void 0;
|
|
357
|
+
}
|
|
348
358
|
async function listPublicationPaths(options) {
|
|
349
359
|
const maxPages = options.maxPages ?? DEFAULT_MAX_PAGES;
|
|
350
360
|
const prefix = `${options.basePath}/`;
|
|
351
|
-
const indexes = [options.basePath || "/"];
|
|
352
|
-
for (const slug of options.sections ?? []) if (slug !== "posts" && SECTION_SLUG.test(slug)) indexes.push(`${options.basePath}/${slug}`);
|
|
353
361
|
const found = /* @__PURE__ */ new Map();
|
|
354
362
|
let complete = true;
|
|
355
363
|
try {
|
|
356
|
-
for (const index of
|
|
364
|
+
for (const index of [options.basePath || "/"]) {
|
|
357
365
|
let cursor;
|
|
358
366
|
for (let page = 0; page < maxPages; page++) {
|
|
359
367
|
const result = await options.client.resolve({
|
|
@@ -367,7 +375,16 @@ async function listPublicationPaths(options) {
|
|
|
367
375
|
break;
|
|
368
376
|
}
|
|
369
377
|
for (const item of result.items) {
|
|
370
|
-
if (item.canonical_path.startsWith(prefix)
|
|
378
|
+
if (!item.canonical_path.startsWith(prefix) || UNSAFE_PATH.test(item.canonical_path)) continue;
|
|
379
|
+
const alternates = safeAlternates(item.alternates);
|
|
380
|
+
found.set(item.canonical_path, {
|
|
381
|
+
path: item.canonical_path,
|
|
382
|
+
publishedAt: item.published_at,
|
|
383
|
+
...typeof item.updated_at === "string" ? { updatedAt: item.updated_at } : {},
|
|
384
|
+
...alternates ? { alternates } : {},
|
|
385
|
+
title: item.title,
|
|
386
|
+
description: item.description
|
|
387
|
+
});
|
|
371
388
|
}
|
|
372
389
|
if (!result.next_cursor) break;
|
|
373
390
|
if (page === maxPages - 1) complete = false;
|
|
@@ -377,7 +394,7 @@ async function listPublicationPaths(options) {
|
|
|
377
394
|
} catch {
|
|
378
395
|
complete = false;
|
|
379
396
|
}
|
|
380
|
-
return { paths: [...found
|
|
397
|
+
return { paths: [...found.values()], complete };
|
|
381
398
|
}
|
|
382
399
|
|
|
383
400
|
// src/engage-keys.ts
|
|
@@ -460,9 +477,7 @@ function Icon({ name, className }) {
|
|
|
460
477
|
|
|
461
478
|
// src/react/content.tsx
|
|
462
479
|
var import_mermaid_diagram = require("./mermaid-diagram.cjs");
|
|
463
|
-
|
|
464
|
-
// src/react/mermaid-config.ts
|
|
465
|
-
var MAX_MERMAID_SOURCE = 2e4;
|
|
480
|
+
var import_mermaid_image = require("./mermaid-image.cjs");
|
|
466
481
|
|
|
467
482
|
// src/react/sanitize.ts
|
|
468
483
|
var HastLimitError = class extends Error {
|
|
@@ -474,7 +489,7 @@ var HastLimitError = class extends Error {
|
|
|
474
489
|
var MAX_NODES = 2e4;
|
|
475
490
|
var MAX_TEXT = 512 * 1024;
|
|
476
491
|
var MAX_DEPTH = 128;
|
|
477
|
-
var MAX_SRCDOC =
|
|
492
|
+
var MAX_SRCDOC = 1024 * 1024;
|
|
478
493
|
var DROP = /* @__PURE__ */ new Set(["script", "style", "template", "noscript"]);
|
|
479
494
|
var VOID = /* @__PURE__ */ new Set(["br", "hr", "img", "input", "path"]);
|
|
480
495
|
var isString = (v) => typeof v === "string";
|
|
@@ -491,6 +506,7 @@ var classTokens = (v) => {
|
|
|
491
506
|
};
|
|
492
507
|
var isClass = (v) => classTokens(v) !== void 0;
|
|
493
508
|
var isAlign = matches(/^(left|right|center)$/);
|
|
509
|
+
var isPixels = (v) => typeof v === "number" ? Number.isInteger(v) && v > 0 : typeof v === "string" && /^[1-9]\d*$/.test(v);
|
|
494
510
|
var isLength = matches(/^[\d.]+(em|px|%)?$/);
|
|
495
511
|
var STYLE_PROPS = /* @__PURE__ */ new Set(["height", "vertical-align", "margin-left", "margin-right", "margin-top", "margin-bottom", "top", "width", "min-width", "border-bottom-width", "padding-left"]);
|
|
496
512
|
var STYLE_LENGTH = /^(-?\d+(?:\.\d+)?)(em|px|%)?$/;
|
|
@@ -527,10 +543,14 @@ var MERMAID_SRCDOC = new RegExp(
|
|
|
527
543
|
var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
|
|
528
544
|
var ENTITIES = { "<": "<", "&": "&", "<": "<", ">": ">", "&": "&", """: '"', "'": "'" };
|
|
529
545
|
function mermaidSource(srcDoc) {
|
|
530
|
-
|
|
531
|
-
|
|
546
|
+
return MERMAID_SRCDOC.exec(srcDoc)?.[1]?.replace(/&(?:#x3c|#x26|#x27|lt|gt|amp|quot);/gi, (e) => ENTITIES[e.toLowerCase()]);
|
|
547
|
+
}
|
|
548
|
+
var RENDER_REF = /^(\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.svg) ([1-9]\d{0,5}) ([1-9]\d{0,5})$/;
|
|
549
|
+
var isRenderRef = matches(RENDER_REF);
|
|
550
|
+
function diagramRender(value) {
|
|
551
|
+
const m = typeof value === "string" ? RENDER_REF.exec(value) : null;
|
|
552
|
+
return m ? { src: hostAssetSrc(m[1]), width: Number(m[2]), height: Number(m[3]) } : void 0;
|
|
532
553
|
}
|
|
533
|
-
var MERMAID_FRAME_CSP = `default-src 'none'; script-src ${MERMAID_SCRIPT_URL} 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:`;
|
|
534
554
|
var heading = { id: isIdValue, className: isClass };
|
|
535
555
|
var ATTRS = new Map(
|
|
536
556
|
Object.entries({
|
|
@@ -555,7 +575,7 @@ var ATTRS = new Map(
|
|
|
555
575
|
h5: heading,
|
|
556
576
|
h6: heading,
|
|
557
577
|
a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, className: isClass },
|
|
558
|
-
img: { src: isSrc, alt: isString },
|
|
578
|
+
img: { src: isSrc, alt: isString, width: isPixels, height: isPixels },
|
|
559
579
|
table: {},
|
|
560
580
|
th: { scope: matches(/^(row|col|rowgroup|colgroup)$/), align: isAlign },
|
|
561
581
|
td: { align: isAlign },
|
|
@@ -569,7 +589,7 @@ var ATTRS = new Map(
|
|
|
569
589
|
video: { src: isSrc, controls: isScalar },
|
|
570
590
|
audio: { src: isSrc, controls: isScalar },
|
|
571
591
|
// hyle's sandboxed Mermaid frame (ADR 0001). The renderer emits `sandbox` as ["allow-scripts"]; it is normalized below.
|
|
572
|
-
iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc }
|
|
592
|
+
iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc, dataLight: isRenderRef, dataDark: isRenderRef }
|
|
573
593
|
})
|
|
574
594
|
);
|
|
575
595
|
var isObject = (v) => typeof v === "object" && v !== null;
|
|
@@ -943,11 +963,17 @@ var en = {
|
|
|
943
963
|
caution: "Caution",
|
|
944
964
|
diagram: "Diagram",
|
|
945
965
|
diagramError: "This diagram could not be rendered.",
|
|
966
|
+
diagramLoading: "Loading the diagram",
|
|
967
|
+
diagramSource: "Diagram source",
|
|
946
968
|
contentError: "This content cannot be displayed.",
|
|
947
969
|
fallbackTitle: "Not translated into {language} yet.",
|
|
948
970
|
fallbackBody: "You are reading the original.",
|
|
971
|
+
readingTime: "{n} min read",
|
|
972
|
+
readingTimeLabel: "Reading time",
|
|
949
973
|
older: "Older posts",
|
|
950
974
|
viewAll: "View all",
|
|
975
|
+
moreInSection: "More in this section",
|
|
976
|
+
subPages: "In this section",
|
|
951
977
|
readAtSource: "Read at source",
|
|
952
978
|
emptyTitle: "Nothing published here yet",
|
|
953
979
|
emptyBody: "Documents published to this section will appear here, newest first.",
|
|
@@ -989,11 +1015,17 @@ var fr = {
|
|
|
989
1015
|
caution: "Danger",
|
|
990
1016
|
diagram: "Sch\xE9ma",
|
|
991
1017
|
diagramError: "Ce sch\xE9ma n'a pas pu \xEAtre affich\xE9.",
|
|
1018
|
+
diagramLoading: "Chargement du sch\xE9ma",
|
|
1019
|
+
diagramSource: "Source du sch\xE9ma",
|
|
992
1020
|
contentError: "Ce contenu ne peut pas \xEAtre affich\xE9.",
|
|
993
1021
|
fallbackTitle: "Pas encore traduit en {language}.",
|
|
994
1022
|
fallbackBody: "Vous lisez l'original.",
|
|
1023
|
+
readingTime: "{n} min de lecture",
|
|
1024
|
+
readingTimeLabel: "Temps de lecture",
|
|
995
1025
|
older: "Articles plus anciens",
|
|
996
1026
|
viewAll: "Tout voir",
|
|
1027
|
+
moreInSection: "Plus dans cette section",
|
|
1028
|
+
subPages: "Dans cette section",
|
|
997
1029
|
readAtSource: "Lire \xE0 la source",
|
|
998
1030
|
emptyTitle: "Rien n'est encore publi\xE9 ici",
|
|
999
1031
|
emptyBody: "Les documents publi\xE9s dans cette section appara\xEEtront ici, du plus r\xE9cent au plus ancien.",
|
|
@@ -1035,11 +1067,17 @@ var es = {
|
|
|
1035
1067
|
caution: "Peligro",
|
|
1036
1068
|
diagram: "Diagrama",
|
|
1037
1069
|
diagramError: "No se pudo mostrar este diagrama.",
|
|
1070
|
+
diagramLoading: "Cargando el diagrama",
|
|
1071
|
+
diagramSource: "C\xF3digo del diagrama",
|
|
1038
1072
|
contentError: "No se puede mostrar este contenido.",
|
|
1039
1073
|
fallbackTitle: "A\xFAn no est\xE1 traducida al {language}.",
|
|
1040
1074
|
fallbackBody: "Est\xE1s leyendo el original.",
|
|
1075
|
+
readingTime: "{n} min de lectura",
|
|
1076
|
+
readingTimeLabel: "Tiempo de lectura",
|
|
1041
1077
|
older: "Entradas anteriores",
|
|
1042
1078
|
viewAll: "Ver todo",
|
|
1079
|
+
moreInSection: "M\xE1s en esta secci\xF3n",
|
|
1080
|
+
subPages: "En esta secci\xF3n",
|
|
1043
1081
|
readAtSource: "Leer en la fuente",
|
|
1044
1082
|
emptyTitle: "A\xFAn no hay nada publicado aqu\xED",
|
|
1045
1083
|
emptyBody: "Los documentos publicados en esta secci\xF3n aparecer\xE1n aqu\xED, del m\xE1s reciente al m\xE1s antiguo.",
|
|
@@ -1102,7 +1140,12 @@ function buildComponents(c, s) {
|
|
|
1102
1140
|
}
|
|
1103
1141
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { href: url, rel: "noopener noreferrer", ...rest, children });
|
|
1104
1142
|
};
|
|
1105
|
-
|
|
1143
|
+
let images = 0;
|
|
1144
|
+
const Image = (props) => {
|
|
1145
|
+
if (typeof props.src !== "string") return null;
|
|
1146
|
+
const first = images++ === 0;
|
|
1147
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Img, { loading: first ? "eager" : "lazy", ...first ? { fetchPriority: "high" } : {}, decoding: "async", ...props });
|
|
1148
|
+
};
|
|
1106
1149
|
const Pre = ({ children, ...rest }) => {
|
|
1107
1150
|
const code = import_react.Children.toArray(children).find(import_react.isValidElement);
|
|
1108
1151
|
const language = /(?:^|\s)language-([\w-]+)/.exec(code?.props.className ?? "")?.[1];
|
|
@@ -1126,12 +1169,18 @@ function buildComponents(c, s) {
|
|
|
1126
1169
|
] })
|
|
1127
1170
|
] });
|
|
1128
1171
|
};
|
|
1129
|
-
const Frame = (
|
|
1172
|
+
const Frame = (props) => {
|
|
1173
|
+
const { srcDoc } = props;
|
|
1130
1174
|
if (typeof srcDoc !== "string") return null;
|
|
1131
1175
|
const source = mermaidSource(srcDoc);
|
|
1132
1176
|
if (c.Mermaid) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(c.Mermaid, { srcDoc, source, title: s.diagram });
|
|
1133
|
-
if (source
|
|
1134
|
-
|
|
1177
|
+
if (source === void 0) return null;
|
|
1178
|
+
const light = diagramRender(props["data-light"]);
|
|
1179
|
+
const dark = diagramRender(props["data-dark"]);
|
|
1180
|
+
if (light && dark) {
|
|
1181
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mermaid_image.MermaidImage, { source, title: s.diagram, errorText: s.diagramError, loadingText: s.diagramLoading, sourceLabel: s.diagramSource, light, dark, labels: s.viewer });
|
|
1182
|
+
}
|
|
1183
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mermaid_diagram.MermaidDiagram, { source, title: s.diagram, errorText: s.diagramError, loadingText: s.diagramLoading, labels: s.viewer });
|
|
1135
1184
|
};
|
|
1136
1185
|
const Heading = (level) => function HyleHeading({ id, children, ...rest }) {
|
|
1137
1186
|
const Tag = `h${level}`;
|
|
@@ -1175,213 +1224,6 @@ var import_mermaid_diagram2 = require("./mermaid-diagram.cjs");
|
|
|
1175
1224
|
|
|
1176
1225
|
// src/react/pages.tsx
|
|
1177
1226
|
var import_comments = require("./comments.cjs");
|
|
1178
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1179
|
-
function Slot({ name, slots, tag: Tag = "div", className }) {
|
|
1180
|
-
const fill = slots?.[name];
|
|
1181
|
-
return fill ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Tag, { "data-slot": name, className, children: fill }) : null;
|
|
1182
|
-
}
|
|
1183
|
-
function Shell({ children }) {
|
|
1184
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "hyle", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "hyle-page", children }) });
|
|
1185
|
-
}
|
|
1186
|
-
function ctx(p, fallbackLocale) {
|
|
1187
|
-
const locale = p.locale ?? fallbackLocale;
|
|
1188
|
-
return { s: stringsFor(locale), locale, href: (path, linkLocale) => p.toHref ? p.toHref(path, linkLocale ?? locale) : path, Link: p.components?.Link ?? "a" };
|
|
1189
|
-
}
|
|
1190
|
-
function Pager({ prev, next, c }) {
|
|
1191
|
-
if (!prev && !next) return null;
|
|
1192
|
-
const { Link, s } = c;
|
|
1193
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("nav", { className: "hyle-pager", "aria-label": s.pager, children: [
|
|
1194
|
-
prev ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { href: c.href(prev.canonical_path), rel: "prev", children: [
|
|
1195
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dir", children: [
|
|
1196
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev-left" }),
|
|
1197
|
-
s.prev
|
|
1198
|
-
] }),
|
|
1199
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "ttl", children: prev.title })
|
|
1200
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "none", "aria-hidden": "true" }),
|
|
1201
|
-
next ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { href: c.href(next.canonical_path), rel: "next", className: "next", children: [
|
|
1202
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dir", children: [
|
|
1203
|
-
s.next,
|
|
1204
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev" })
|
|
1205
|
-
] }),
|
|
1206
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "ttl", children: next.title })
|
|
1207
|
-
] }) : null
|
|
1208
|
-
] });
|
|
1209
|
-
}
|
|
1210
|
-
function TocList({ toc }) {
|
|
1211
|
-
const groups = [];
|
|
1212
|
-
for (const entry of toc) {
|
|
1213
|
-
const last = groups.at(-1);
|
|
1214
|
-
if (entry.depth === 3 && last) last.subs.push(entry);
|
|
1215
|
-
else groups.push({ entry, subs: [] });
|
|
1216
|
-
}
|
|
1217
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { children: groups.map(({ entry, subs }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { children: [
|
|
1218
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: `#${scopeId(entry.id)}`, children: entry.text }),
|
|
1219
|
-
subs.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { children: subs.map((sub) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: `#${scopeId(sub.id)}`, children: sub.text }) }, sub.id)) }) : null
|
|
1220
|
-
] }, entry.id)) });
|
|
1221
|
-
}
|
|
1222
|
-
function Toc({ toc, c, aside }) {
|
|
1223
|
-
const entries = toc.filter((t) => t.depth === 2 || t.depth === 3);
|
|
1224
|
-
if (entries.length === 0 && !aside) return { narrow: null, wide: null };
|
|
1225
|
-
const { s } = c;
|
|
1226
|
-
return {
|
|
1227
|
-
narrow: entries.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("details", { className: "hyle-toc-m", children: [
|
|
1228
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("summary", { children: [
|
|
1229
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "file" }),
|
|
1230
|
-
s.toc,
|
|
1231
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev-down", className: "hyle-chev" })
|
|
1232
|
-
] }),
|
|
1233
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("nav", { className: "hyle-toc-list", "aria-label": s.toc, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TocList, { toc: entries }) })
|
|
1234
|
-
] }),
|
|
1235
|
-
wide: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("aside", { className: "hyle-toc-d", "aria-label": s.toc, children: [
|
|
1236
|
-
entries.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1237
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "hyle-toc-title", children: s.toc }),
|
|
1238
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("nav", { className: "hyle-toc-list", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TocList, { toc: entries }) })
|
|
1239
|
-
] }),
|
|
1240
|
-
aside
|
|
1241
|
-
] })
|
|
1242
|
-
};
|
|
1243
|
-
}
|
|
1244
|
-
function Body({ article, components, locale }) {
|
|
1245
|
-
const { content, publication } = article;
|
|
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 }) });
|
|
1247
|
-
}
|
|
1248
|
-
function Languages({ alternates, current, c }) {
|
|
1249
|
-
if (alternates.length < 2) return null;
|
|
1250
|
-
const { Link, s } = c;
|
|
1251
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("nav", { className: "hyle-langs", "aria-label": s.languages, children: [
|
|
1252
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: s.readIn }),
|
|
1253
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { children: alternates.map((a) => {
|
|
1254
|
-
const label = languageName(a.locale, a.locale);
|
|
1255
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: a.locale === current ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: c.href(a.canonical_path, a.locale), hrefLang: a.locale, lang: a.locale, "aria-current": "true", children: label }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Link, { href: c.href(a.canonical_path, a.locale), hrefLang: a.locale, lang: a.locale, children: label }) }, a.locale);
|
|
1256
|
-
}) })
|
|
1257
|
-
] });
|
|
1258
|
-
}
|
|
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 }) {
|
|
1286
|
-
const { publication: pub } = article;
|
|
1287
|
-
const c = ctx(base, pub.locale);
|
|
1288
|
-
const { s } = c;
|
|
1289
|
-
const author = typeof article.frontmatter.author === "string" ? article.frontmatter.author : void 0;
|
|
1290
|
-
const toc = Toc({ toc: article.toc, c, aside: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.aside", slots: base.slots, className: "hyle-slot-wrap" }) });
|
|
1291
|
-
const notTranslated = article.fallback ? s.fallbackTitle.replace("{language}", languageName(article.fallback.requested_locale, c.locale)) : void 0;
|
|
1292
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("article", { className: "hyle-article", "data-hyle-page": "article", lang: c.locale, children: [
|
|
1293
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "hyle-head", children: [
|
|
1294
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.before", slots: base.slots, className: "hyle-eyebrow" }),
|
|
1295
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h1", { className: "hyle-title", children: pub.title }),
|
|
1296
|
-
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
1297
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-meta", children: [
|
|
1298
|
-
author ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1299
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: author.slice(0, 2).toUpperCase() }),
|
|
1300
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1301
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "hyle-sr", children: [
|
|
1302
|
-
s.by,
|
|
1303
|
-
" "
|
|
1304
|
-
] }),
|
|
1305
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "by", children: author })
|
|
1306
|
-
] })
|
|
1307
|
-
] }) : null,
|
|
1308
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1309
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "calendar" }),
|
|
1310
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("time", { dateTime: pub.published_at, title: pub.published_at, children: formatDate(pub.published_at, c.locale) })
|
|
1311
|
-
] }),
|
|
1312
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1313
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "globe" }),
|
|
1314
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { lang: pub.locale, children: languageName(pub.locale, c.locale) })
|
|
1315
|
-
] }),
|
|
1316
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.meta", slots: base.slots, tag: "span" })
|
|
1317
|
-
] }),
|
|
1318
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Languages, { alternates: article.alternates, current: pub.locale, c }),
|
|
1319
|
-
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1320
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }),
|
|
1321
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
1322
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: notTranslated }),
|
|
1323
|
-
" ",
|
|
1324
|
-
s.fallbackBody
|
|
1325
|
-
] })
|
|
1326
|
-
] }) : null
|
|
1327
|
-
] }),
|
|
1328
|
-
toc.narrow,
|
|
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,
|
|
1331
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Pager, { prev: article.prev, next: article.next, c }),
|
|
1332
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.after", slots: base.slots, className: "hyle-after" }),
|
|
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
|
|
1335
|
-
] }) });
|
|
1336
|
-
}
|
|
1337
|
-
function ListPage({ list, olderHref, description, ...base }) {
|
|
1338
|
-
const c = ctx(base, "en");
|
|
1339
|
-
const { s, Link } = c;
|
|
1340
|
-
const Row = base.slots?.["list.item"];
|
|
1341
|
-
const groups = /* @__PURE__ */ new Map();
|
|
1342
|
-
for (const item of list.items) groups.set(item.published_at.slice(0, 7), [...groups.get(item.published_at.slice(0, 7)) ?? [], item]);
|
|
1343
|
-
const notTranslated = list.fallback ? s.fallbackTitle.replace("{language}", languageName(list.fallback.requested_locale, c.locale)) : void 0;
|
|
1344
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-listpage", "data-hyle-page": "list", lang: c.locale, children: [
|
|
1345
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "hyle-head", children: [
|
|
1346
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h1", { className: "hyle-title", children: list.section.title }),
|
|
1347
|
-
description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "hyle-desc", children: description }) : null,
|
|
1348
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "list.header", slots: base.slots, className: "hyle-slot-wrap" }),
|
|
1349
|
-
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1350
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }),
|
|
1351
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
1352
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: notTranslated }),
|
|
1353
|
-
" ",
|
|
1354
|
-
s.fallbackBody
|
|
1355
|
-
] })
|
|
1356
|
-
] }) : null
|
|
1357
|
-
] }),
|
|
1358
|
-
list.items.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-empty", "data-slot-state": "empty", children: [
|
|
1359
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "file" }),
|
|
1360
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { children: s.emptyTitle }),
|
|
1361
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: s.emptyBody }),
|
|
1362
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "list.empty", slots: base.slots })
|
|
1363
|
-
] }) : [...groups].map(([month, items]) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { "aria-label": formatDate(`${month}-01`, c.locale, { month: "long", year: "numeric" }), children: [
|
|
1364
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { className: "hyle-year", children: formatDate(`${month}-01`, c.locale, { month: "long", year: "numeric" }) }),
|
|
1365
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "hyle-items", children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: Row ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Row, { item, href: c.href(item.canonical_path), locale: c.locale }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { className: "hyle-item", href: c.href(item.canonical_path), children: [
|
|
1366
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("time", { dateTime: item.published_at, title: item.published_at, children: formatDate(item.published_at, c.locale) }),
|
|
1367
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
1368
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "t", children: item.title }),
|
|
1369
|
-
item.description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: item.description }) : null
|
|
1370
|
-
] })
|
|
1371
|
-
] }) }, item.canonical_path)) })
|
|
1372
|
-
] }, month)),
|
|
1373
|
-
olderHref ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("nav", { className: "hyle-pagination", "aria-label": s.pager, children: [
|
|
1374
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "sp" }),
|
|
1375
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { className: "hyle-btn sm", href: olderHref, rel: "next", children: [
|
|
1376
|
-
s.older,
|
|
1377
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev" })
|
|
1378
|
-
] })
|
|
1379
|
-
] }) : null
|
|
1380
|
-
] }) });
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
// src/react/index.ts
|
|
1384
|
-
var import_comments2 = require("./comments.cjs");
|
|
1385
1227
|
|
|
1386
1228
|
// src/react/comments-api.ts
|
|
1387
1229
|
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -1487,8 +1329,8 @@ function buildThread(listing, localHeld) {
|
|
|
1487
1329
|
// src/react/comments-body.tsx
|
|
1488
1330
|
var import_hast_util_to_jsx_runtime2 = require("hast-util-to-jsx-runtime");
|
|
1489
1331
|
var import_react2 = require("react");
|
|
1332
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1490
1333
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1491
|
-
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1492
1334
|
var ALLOWED = /* @__PURE__ */ new Set(["p", "a", "em", "strong", "del", "code", "pre", "blockquote", "ul", "ol", "li", "br"]);
|
|
1493
1335
|
var LINK_REL = "nofollow ugc noopener noreferrer";
|
|
1494
1336
|
function narrow(node) {
|
|
@@ -1511,44 +1353,45 @@ function CommentBody({ tree }) {
|
|
|
1511
1353
|
if (error instanceof HastLimitError) return null;
|
|
1512
1354
|
throw error;
|
|
1513
1355
|
}
|
|
1514
|
-
return /* @__PURE__ */ (0,
|
|
1356
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.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_runtime4.jsx, jsxs: import_jsx_runtime4.jsxs, elementAttributeNameCase: "react", stylePropertyNameCase: "dom" }) });
|
|
1515
1357
|
}
|
|
1516
1358
|
|
|
1517
1359
|
// src/react/embed.tsx
|
|
1518
|
-
var
|
|
1519
|
-
function HyleListView({ items, layout = "list", title, headingLevel = 2, moreHref, ...base }) {
|
|
1360
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1361
|
+
function HyleListView({ items, layout = "list", title, headingLevel = 2, moreHref, olderHref, ...base }) {
|
|
1520
1362
|
const c = ctx(base, "en");
|
|
1521
1363
|
const { s, Link } = c;
|
|
1522
1364
|
const Row = base.slots?.["list.item"];
|
|
1523
1365
|
const Heading = `h${headingLevel}`;
|
|
1524
1366
|
const safe = items.filter((item) => item.canonical_path.startsWith("/"));
|
|
1525
|
-
if (safe.length === 0) return base.slots?.["list.empty"] ? /* @__PURE__ */ (0,
|
|
1526
|
-
return /* @__PURE__ */ (0,
|
|
1527
|
-
title ? /* @__PURE__ */ (0,
|
|
1528
|
-
/* @__PURE__ */ (0,
|
|
1529
|
-
/* @__PURE__ */ (0,
|
|
1530
|
-
/* @__PURE__ */ (0,
|
|
1531
|
-
/* @__PURE__ */ (0,
|
|
1532
|
-
item.description ? /* @__PURE__ */ (0,
|
|
1367
|
+
if (safe.length === 0) return base.slots?.["list.empty"] ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle hyle-embed", "data-layout": layout, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Slot, { name: "list.empty", slots: base.slots }) }) : null;
|
|
1368
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle hyle-embed", "data-layout": layout, lang: c.locale, children: [
|
|
1369
|
+
title ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Heading, { className: "hyle-title", children: title }) : null,
|
|
1370
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: "hyle-items", children: safe.map((item) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("li", { children: Row ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Row, { item, href: c.href(item.canonical_path), locale: c.locale }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Link, { className: "hyle-item", href: c.href(item.canonical_path), children: [
|
|
1371
|
+
item.published_at ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("time", { dateTime: item.published_at, title: item.published_at, children: formatDate(item.published_at, c.locale) }) : null,
|
|
1372
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
|
|
1373
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "t", children: item.title }),
|
|
1374
|
+
item.description ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: item.description }) : null
|
|
1533
1375
|
] })
|
|
1534
1376
|
] }) }, item.canonical_path)) }),
|
|
1535
|
-
|
|
1377
|
+
olderHref ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(OlderNav, { href: olderHref, c }) : null,
|
|
1378
|
+
moreHref ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("a", { className: "hyle-more", href: moreHref, children: s.viewAll }) : null
|
|
1536
1379
|
] });
|
|
1537
1380
|
}
|
|
1538
1381
|
function HyleArticleView({ article, headingLevel = 2, ...base }) {
|
|
1539
1382
|
const { publication: pub } = article;
|
|
1540
1383
|
const c = ctx(base, pub.locale);
|
|
1541
1384
|
const Heading = `h${headingLevel}`;
|
|
1542
|
-
return /* @__PURE__ */ (0,
|
|
1543
|
-
/* @__PURE__ */ (0,
|
|
1544
|
-
/* @__PURE__ */ (0,
|
|
1545
|
-
pub.description ? /* @__PURE__ */ (0,
|
|
1546
|
-
/* @__PURE__ */ (0,
|
|
1385
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle hyle-embed", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("article", { lang: c.locale, children: [
|
|
1386
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("header", { className: "hyle-head", children: [
|
|
1387
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Heading, { className: "hyle-title", children: pub.title }),
|
|
1388
|
+
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
1389
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-meta", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("time", { dateTime: pub.published_at, title: pub.published_at, children: formatDate(pub.published_at, c.locale) }) }) })
|
|
1547
1390
|
] }),
|
|
1548
|
-
/* @__PURE__ */ (0,
|
|
1549
|
-
pub.canonical_path.startsWith("/") ? /* @__PURE__ */ (0,
|
|
1391
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
1392
|
+
pub.canonical_path.startsWith("/") ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("a", { className: "hyle-more", href: c.href(pub.canonical_path, pub.locale), rel: "bookmark", children: [
|
|
1550
1393
|
c.s.readAtSource,
|
|
1551
|
-
/* @__PURE__ */ (0,
|
|
1394
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "hyle-sr", children: [
|
|
1552
1395
|
": ",
|
|
1553
1396
|
pub.title
|
|
1554
1397
|
] })
|
|
@@ -1557,35 +1400,35 @@ function HyleArticleView({ article, headingLevel = 2, ...base }) {
|
|
|
1557
1400
|
}
|
|
1558
1401
|
var initials = (name) => name.trim().split(/\s+/).slice(0, 2).map((w) => [...w][0] ?? "").join("").toUpperCase() || "?";
|
|
1559
1402
|
function StaticThread({ nodes, locale, s, level = 1 }) {
|
|
1560
|
-
return /* @__PURE__ */ (0,
|
|
1561
|
-
const kids = node.kids.length > 0 && level < 32 ? /* @__PURE__ */ (0,
|
|
1403
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ol", { className: "hyle-cm-list", role: "list", children: nodes.map((node) => {
|
|
1404
|
+
const kids = node.kids.length > 0 && level < 32 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StaticThread, { nodes: node.kids, locale, s, level: level + 1 }) : null;
|
|
1562
1405
|
if (node.status === "removed") {
|
|
1563
1406
|
const why = node.removedBy === "moderator" ? s.removedByModerator : node.removedBy === "author" ? s.removedByAuthor : s.removed;
|
|
1564
|
-
return /* @__PURE__ */ (0,
|
|
1565
|
-
/* @__PURE__ */ (0,
|
|
1566
|
-
/* @__PURE__ */ (0,
|
|
1567
|
-
/* @__PURE__ */ (0,
|
|
1407
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: "hyle-cm", "data-depth": node.depth, "data-status": "removed", "data-removed-by": node.removedBy, children: [
|
|
1408
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("article", { "aria-label": why, children: [
|
|
1409
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "ban" }) }),
|
|
1410
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-main", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-body", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: why }) }) })
|
|
1568
1411
|
] }),
|
|
1569
1412
|
kids
|
|
1570
1413
|
] }, node.id);
|
|
1571
1414
|
}
|
|
1572
|
-
return /* @__PURE__ */ (0,
|
|
1573
|
-
/* @__PURE__ */ (0,
|
|
1574
|
-
/* @__PURE__ */ (0,
|
|
1575
|
-
/* @__PURE__ */ (0,
|
|
1576
|
-
/* @__PURE__ */ (0,
|
|
1577
|
-
/* @__PURE__ */ (0,
|
|
1578
|
-
/* @__PURE__ */ (0,
|
|
1579
|
-
/* @__PURE__ */ (0,
|
|
1580
|
-
node.editedAt ? /* @__PURE__ */ (0,
|
|
1415
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: "hyle-cm", "data-depth": node.depth, "data-status": "visible", children: [
|
|
1416
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("article", { children: [
|
|
1417
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: initials(node.name ?? "") }),
|
|
1418
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-main", children: [
|
|
1419
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-by", children: [
|
|
1420
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { children: node.name }),
|
|
1421
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
|
|
1422
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("time", { dateTime: node.createdAt, title: node.createdAt, children: formatDate(node.createdAt, locale) }),
|
|
1423
|
+
node.editedAt ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1581
1424
|
" ",
|
|
1582
|
-
/* @__PURE__ */ (0,
|
|
1425
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "aria-hidden": "true", children: "\xB7" }),
|
|
1583
1426
|
" ",
|
|
1584
|
-
/* @__PURE__ */ (0,
|
|
1427
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: s.edited })
|
|
1585
1428
|
] }) : null
|
|
1586
1429
|
] })
|
|
1587
1430
|
] }),
|
|
1588
|
-
/* @__PURE__ */ (0,
|
|
1431
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CommentBody, { tree: node.tree })
|
|
1589
1432
|
] })
|
|
1590
1433
|
] }),
|
|
1591
1434
|
kids
|
|
@@ -1596,31 +1439,367 @@ function HyleCommentsView({ listing, locale }) {
|
|
|
1596
1439
|
const thread = buildThread(listing, []);
|
|
1597
1440
|
if (thread.length === 0) return null;
|
|
1598
1441
|
const s = stringsFor(locale).comments;
|
|
1599
|
-
return /* @__PURE__ */ (0,
|
|
1600
|
-
/* @__PURE__ */ (0,
|
|
1442
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle hyle-embed", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("section", { className: "hyle-comments", "aria-label": s.heading, "data-slot-component": "Comments", lang: locale, children: [
|
|
1443
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-head", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("h2", { children: [
|
|
1601
1444
|
s.heading,
|
|
1602
1445
|
" ",
|
|
1603
|
-
/* @__PURE__ */ (0,
|
|
1446
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-cm-count", "aria-label": s.countLabel.replace("{n}", String(listing.comment_count)), children: listing.comment_count })
|
|
1604
1447
|
] }) }),
|
|
1605
|
-
/* @__PURE__ */ (0,
|
|
1606
|
-
listing.truncated ? /* @__PURE__ */ (0,
|
|
1448
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StaticThread, { nodes: thread, locale, s }),
|
|
1449
|
+
listing.truncated ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "hyle-cm-note", children: s.truncated }) : null
|
|
1607
1450
|
] }) });
|
|
1608
1451
|
}
|
|
1609
1452
|
function HyleCommentsFallback({ locale }) {
|
|
1610
1453
|
const s = stringsFor(locale).comments;
|
|
1611
|
-
return /* @__PURE__ */ (0,
|
|
1612
|
-
/* @__PURE__ */ (0,
|
|
1613
|
-
/* @__PURE__ */ (0,
|
|
1614
|
-
/* @__PURE__ */ (0,
|
|
1615
|
-
/* @__PURE__ */ (0,
|
|
1616
|
-
/* @__PURE__ */ (0,
|
|
1617
|
-
/* @__PURE__ */ (0,
|
|
1618
|
-
/* @__PURE__ */ (0,
|
|
1454
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle hyle-embed", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("section", { className: "hyle-comments", "aria-label": s.heading, "data-slot-component": "Comments", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { role: "status", "aria-live": "polite", "aria-busy": "true", children: [
|
|
1455
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-sr", children: s.loading }),
|
|
1456
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { "aria-hidden": "true", children: [0, 1, 2].map((i) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-sk", children: [
|
|
1457
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-sk c" }),
|
|
1458
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
|
|
1459
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-sk l", style: { width: 120 } }),
|
|
1460
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-sk l", style: { width: "100%" } }),
|
|
1461
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-sk l", style: { width: "72%" } })
|
|
1619
1462
|
] })
|
|
1620
1463
|
] }, i)) })
|
|
1621
1464
|
] }) }) });
|
|
1622
1465
|
}
|
|
1623
1466
|
|
|
1467
|
+
// src/react/seo.ts
|
|
1468
|
+
var BARE_HTTPS_ORIGIN = /^https:\/\/[^/]+$/;
|
|
1469
|
+
var bareOrigin = (origin) => origin && BARE_HTTPS_ORIGIN.test(origin) ? origin : void 0;
|
|
1470
|
+
var absoluteUrl = (origin, href) => origin + encodeURI(href);
|
|
1471
|
+
var modifiedAt = (pub) => pub.updated_at && Date.parse(pub.updated_at) > Date.parse(pub.published_at) ? pub.updated_at : void 0;
|
|
1472
|
+
var wordCountOf = (pub) => Number.isInteger(pub.word_count) && pub.word_count > 0 ? pub.word_count : void 0;
|
|
1473
|
+
var WORDS_PER_MINUTE = 275;
|
|
1474
|
+
var readingMinutes = (wordCount) => Math.max(1, Math.ceil(wordCount / WORDS_PER_MINUTE));
|
|
1475
|
+
var breadcrumbItems = (article, jsonLd) => [
|
|
1476
|
+
...jsonLd?.breadcrumbRoot ? [{ title: jsonLd.breadcrumbRoot.name, canonical_path: "/" }] : [],
|
|
1477
|
+
...article.breadcrumbs
|
|
1478
|
+
];
|
|
1479
|
+
var crumbHref = (href, path, locale) => path === "/" ? href("/", locale).replace(/(.)\/$/, "$1") : href(path, locale);
|
|
1480
|
+
function articleAuthor(article, jsonLd) {
|
|
1481
|
+
const authored = article.publication.author;
|
|
1482
|
+
if (authored?.name) return { name: authored.name, ...authored.url ? { url: authored.url } : {} };
|
|
1483
|
+
const given = jsonLd?.author?.(article);
|
|
1484
|
+
if (given && typeof given.name === "string" && given.name) return given;
|
|
1485
|
+
const fromFrontmatter = article.frontmatter.author;
|
|
1486
|
+
return typeof fromFrontmatter === "string" && fromFrontmatter ? { name: fromFrontmatter } : void 0;
|
|
1487
|
+
}
|
|
1488
|
+
var UNSAFE_URL = /[\u0000- \u007f\\]/;
|
|
1489
|
+
var positive = (n) => typeof n === "number" && Number.isInteger(n) && n > 0 ? n : void 0;
|
|
1490
|
+
function validOgImage(image, origin) {
|
|
1491
|
+
if (!image || typeof image.url !== "string" || UNSAFE_URL.test(image.url)) return void 0;
|
|
1492
|
+
const relative = image.url.startsWith("/") && !image.url.startsWith("//");
|
|
1493
|
+
const url = relative ? origin ? origin + image.url : void 0 : image.url;
|
|
1494
|
+
if (!url) return void 0;
|
|
1495
|
+
try {
|
|
1496
|
+
const parsed = new URL(url);
|
|
1497
|
+
if (parsed.protocol !== "https:" || relative && parsed.origin !== origin) return void 0;
|
|
1498
|
+
} catch {
|
|
1499
|
+
return void 0;
|
|
1500
|
+
}
|
|
1501
|
+
const width = positive(image.width);
|
|
1502
|
+
const height = positive(image.height);
|
|
1503
|
+
const type = typeof image.type === "string" && image.type ? image.type : "image/png";
|
|
1504
|
+
return { url, type, ...width ? { width } : {}, ...height ? { height } : {}, ...typeof image.alt === "string" && image.alt ? { alt: image.alt } : {} };
|
|
1505
|
+
}
|
|
1506
|
+
function hreflangLanguages(members, defaultLocale, selfUrl, url) {
|
|
1507
|
+
const defaultMember = members.find((m) => m.locale === defaultLocale);
|
|
1508
|
+
return { ...Object.fromEntries(members.map((m) => [m.locale, url(m)])), "x-default": defaultMember ? url(defaultMember) : selfUrl };
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
// src/react/jsonld.ts
|
|
1512
|
+
var script = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
|
|
1513
|
+
var organization = (publisher) => ({ "@type": "Organization", "@id": publisher.id, name: publisher.name, ...publisher.logo ? { logo: publisher.logo } : {} });
|
|
1514
|
+
var webSite = (website) => ({ "@type": "WebSite", "@id": website.id, name: website.name });
|
|
1515
|
+
function articleJsonLd({ article, origin, href, jsonLd, imageUrl, imageWidth, imageHeight }) {
|
|
1516
|
+
const { publication: pub } = article;
|
|
1517
|
+
const url = (path) => absoluteUrl(origin, href(path, pub.locale));
|
|
1518
|
+
const canonical = url(pub.canonical_path);
|
|
1519
|
+
const id = (fragment) => ({ "@id": `${canonical}#${fragment}` });
|
|
1520
|
+
const full = jsonLd !== void 0;
|
|
1521
|
+
const author = articleAuthor(article, jsonLd);
|
|
1522
|
+
const publisher = jsonLd?.publisher;
|
|
1523
|
+
const website = jsonLd?.website?.(pub.locale);
|
|
1524
|
+
const modified = modifiedAt(pub);
|
|
1525
|
+
const words = wordCountOf(pub);
|
|
1526
|
+
const publisherNode = publisher ? organization(publisher) : void 0;
|
|
1527
|
+
const section = article.breadcrumbs[0]?.title;
|
|
1528
|
+
const graph = [
|
|
1529
|
+
...full ? [{
|
|
1530
|
+
"@type": "WebPage",
|
|
1531
|
+
...id("webpage"),
|
|
1532
|
+
url: canonical,
|
|
1533
|
+
name: pub.title,
|
|
1534
|
+
...pub.description ? { description: pub.description } : {},
|
|
1535
|
+
inLanguage: pub.locale,
|
|
1536
|
+
...website ? { isPartOf: webSite(website) } : {},
|
|
1537
|
+
...publisherNode ? { publisher: publisherNode } : {},
|
|
1538
|
+
breadcrumb: id("breadcrumb"),
|
|
1539
|
+
mainEntity: id("article")
|
|
1540
|
+
}] : [],
|
|
1541
|
+
{
|
|
1542
|
+
"@type": "BlogPosting",
|
|
1543
|
+
...id("article"),
|
|
1544
|
+
headline: pub.title,
|
|
1545
|
+
...pub.description ? { description: pub.description } : {},
|
|
1546
|
+
datePublished: pub.published_at,
|
|
1547
|
+
...section ? { articleSection: section } : {},
|
|
1548
|
+
...modified ? { dateModified: modified } : {},
|
|
1549
|
+
...words ? { wordCount: words } : {},
|
|
1550
|
+
url: canonical,
|
|
1551
|
+
mainEntityOfPage: full ? id("webpage") : canonical,
|
|
1552
|
+
...author ? { author: { "@type": "Person", ...author.id ? { "@id": author.id } : {}, name: author.name, ...author.url ? { url: author.url } : {} } } : {},
|
|
1553
|
+
...publisherNode ? { publisher: publisherNode } : {},
|
|
1554
|
+
inLanguage: pub.locale,
|
|
1555
|
+
...imageUrl ? { image: imageWidth && imageHeight ? { "@type": "ImageObject", url: imageUrl, width: imageWidth, height: imageHeight } : [imageUrl] } : {}
|
|
1556
|
+
},
|
|
1557
|
+
{
|
|
1558
|
+
"@type": "BreadcrumbList",
|
|
1559
|
+
...id("breadcrumb"),
|
|
1560
|
+
itemListElement: breadcrumbItems(article, jsonLd).map((b, i) => ({
|
|
1561
|
+
"@type": "ListItem",
|
|
1562
|
+
position: i + 1,
|
|
1563
|
+
name: b.title,
|
|
1564
|
+
item: absoluteUrl(origin, crumbHref(href, b.canonical_path, pub.locale).replace(/^\/$/, ""))
|
|
1565
|
+
}))
|
|
1566
|
+
}
|
|
1567
|
+
];
|
|
1568
|
+
return script({ "@context": "https://schema.org", "@graph": graph });
|
|
1569
|
+
}
|
|
1570
|
+
function listJsonLd({ list, origin, href, path, locale, description, jsonLd, cursor }) {
|
|
1571
|
+
const url = absoluteUrl(origin, href(path)) + (cursor ? `?cursor=${cursor}` : "");
|
|
1572
|
+
const website = jsonLd?.website?.(locale);
|
|
1573
|
+
return script({
|
|
1574
|
+
"@context": "https://schema.org",
|
|
1575
|
+
"@type": "CollectionPage",
|
|
1576
|
+
...jsonLd ? { "@id": `${url}#webpage` } : {},
|
|
1577
|
+
url,
|
|
1578
|
+
...website ? { isPartOf: webSite(website) } : {},
|
|
1579
|
+
...jsonLd?.publisher ? { publisher: organization(jsonLd.publisher) } : {},
|
|
1580
|
+
name: list.section.title,
|
|
1581
|
+
...description ? { description } : {},
|
|
1582
|
+
inLanguage: locale,
|
|
1583
|
+
mainEntity: {
|
|
1584
|
+
"@type": "ItemList",
|
|
1585
|
+
itemListElement: list.items.map((item, i) => ({ "@type": "ListItem", position: i + 1, url: absoluteUrl(origin, href(item.canonical_path)), name: item.title }))
|
|
1586
|
+
}
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
// src/react/pages.tsx
|
|
1591
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1592
|
+
function Slot({ name, slots, tag: Tag = "div", className }) {
|
|
1593
|
+
const fill = slots?.[name];
|
|
1594
|
+
return fill ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Tag, { "data-slot": name, className, children: fill }) : null;
|
|
1595
|
+
}
|
|
1596
|
+
function Shell({ children }) {
|
|
1597
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-page", children }) });
|
|
1598
|
+
}
|
|
1599
|
+
function ctx(p, fallbackLocale) {
|
|
1600
|
+
const locale = p.locale ?? fallbackLocale;
|
|
1601
|
+
return { s: stringsFor(locale), locale, href: (path, linkLocale) => p.toHref ? p.toHref(path, linkLocale ?? locale) : path, Link: p.components?.Link ?? "a" };
|
|
1602
|
+
}
|
|
1603
|
+
function Pager({ prev, next, c }) {
|
|
1604
|
+
if (!prev && !next) return null;
|
|
1605
|
+
const { Link, s } = c;
|
|
1606
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("nav", { className: "hyle-pager", "aria-label": s.pager, children: [
|
|
1607
|
+
prev ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Link, { href: c.href(prev.canonical_path), rel: "prev", children: [
|
|
1608
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "dir", children: [
|
|
1609
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "chev-left" }),
|
|
1610
|
+
s.prev
|
|
1611
|
+
] }),
|
|
1612
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "ttl", children: prev.title })
|
|
1613
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "none", "aria-hidden": "true" }),
|
|
1614
|
+
next ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Link, { href: c.href(next.canonical_path), rel: "next", className: "next", children: [
|
|
1615
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "dir", children: [
|
|
1616
|
+
s.next,
|
|
1617
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "chev" })
|
|
1618
|
+
] }),
|
|
1619
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "ttl", children: next.title })
|
|
1620
|
+
] }) : null
|
|
1621
|
+
] });
|
|
1622
|
+
}
|
|
1623
|
+
function OlderNav({ href, c }) {
|
|
1624
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("nav", { className: "hyle-pagination", "aria-label": c.s.pager, children: [
|
|
1625
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "sp" }),
|
|
1626
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(c.Link, { className: "hyle-btn sm", href, rel: "next", children: [
|
|
1627
|
+
c.s.older,
|
|
1628
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "chev" })
|
|
1629
|
+
] })
|
|
1630
|
+
] });
|
|
1631
|
+
}
|
|
1632
|
+
function TocList({ toc }) {
|
|
1633
|
+
const groups = [];
|
|
1634
|
+
for (const entry of toc) {
|
|
1635
|
+
const last = groups.at(-1);
|
|
1636
|
+
if (entry.depth === 3 && last) last.subs.push(entry);
|
|
1637
|
+
else groups.push({ entry, subs: [] });
|
|
1638
|
+
}
|
|
1639
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { children: groups.map(({ entry, subs }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { children: [
|
|
1640
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { href: `#${scopeId(entry.id)}`, children: entry.text }),
|
|
1641
|
+
subs.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { children: subs.map((sub) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { href: `#${scopeId(sub.id)}`, children: sub.text }) }, sub.id)) }) : null
|
|
1642
|
+
] }, entry.id)) });
|
|
1643
|
+
}
|
|
1644
|
+
function Toc({ toc, c, aside }) {
|
|
1645
|
+
const entries = toc.filter((t) => t.depth === 2 || t.depth === 3);
|
|
1646
|
+
if (entries.length === 0 && !aside) return { narrow: null, wide: null };
|
|
1647
|
+
const { s } = c;
|
|
1648
|
+
return {
|
|
1649
|
+
narrow: entries.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("details", { className: "hyle-toc-m", children: [
|
|
1650
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("summary", { children: [
|
|
1651
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "file" }),
|
|
1652
|
+
s.toc,
|
|
1653
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "chev-down", className: "hyle-chev" })
|
|
1654
|
+
] }),
|
|
1655
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("nav", { className: "hyle-toc-list", "aria-label": s.toc, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TocList, { toc: entries }) })
|
|
1656
|
+
] }),
|
|
1657
|
+
wide: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("aside", { className: "hyle-toc-d", "aria-label": s.toc, children: [
|
|
1658
|
+
entries.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1659
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-toc-title", children: s.toc }),
|
|
1660
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("nav", { className: "hyle-toc-list", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TocList, { toc: entries }) })
|
|
1661
|
+
] }),
|
|
1662
|
+
aside
|
|
1663
|
+
] })
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
function Body({ article, components, locale }) {
|
|
1667
|
+
const { content, publication } = article;
|
|
1668
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-body hyle-prose", lang: article.fallback ? void 0 : publication.locale, children: content.format === "hast" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HastContent, { tree: content.tree, title: publication.title, description: publication.description, components: components ?? {}, locale }) : content.format === "html" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TrustedServerHtml, { html: content.html }) : null });
|
|
1669
|
+
}
|
|
1670
|
+
function Languages({ alternates, current, c }) {
|
|
1671
|
+
if (alternates.length < 2) return null;
|
|
1672
|
+
const { Link, s } = c;
|
|
1673
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("nav", { className: "hyle-langs", "aria-label": s.languages, children: [
|
|
1674
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: s.readIn }),
|
|
1675
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { children: alternates.map((a) => {
|
|
1676
|
+
const label = languageName(a.locale, a.locale);
|
|
1677
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("li", { children: a.locale === current ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { href: c.href(a.canonical_path, a.locale), hrefLang: a.locale, lang: a.locale, "aria-current": "true", children: label }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Link, { href: c.href(a.canonical_path, a.locale), hrefLang: a.locale, lang: a.locale, children: label }) }, a.locale);
|
|
1678
|
+
}) })
|
|
1679
|
+
] });
|
|
1680
|
+
}
|
|
1681
|
+
function LdScript({ json: json2 }) {
|
|
1682
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("script", { type: "application/ld+json", dangerouslySetInnerHTML: { __html: json2 } });
|
|
1683
|
+
}
|
|
1684
|
+
function Crumbs({ items, c }) {
|
|
1685
|
+
const { Link } = c;
|
|
1686
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("nav", { className: "hyle-crumbs", "aria-label": c.s.crumbs, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ol", { children: items.map((b, i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("li", { "aria-current": i === items.length - 1 ? "page" : void 0, children: i === items.length - 1 ? b.title : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Link, { href: crumbHref(c.href, b.canonical_path, c.locale), children: b.title }) }, b.canonical_path)) }) });
|
|
1687
|
+
}
|
|
1688
|
+
function ArticlePage({ article, engagement, origin, jsonLd, imageUrl, imageWidth, imageHeight, related, ...base }) {
|
|
1689
|
+
const { publication: pub } = article;
|
|
1690
|
+
const c = ctx(base, pub.locale);
|
|
1691
|
+
const { s } = c;
|
|
1692
|
+
const jsonLdOrigin = bareOrigin(origin);
|
|
1693
|
+
const author = articleAuthor(article, jsonLd)?.name;
|
|
1694
|
+
const modified = modifiedAt(pub);
|
|
1695
|
+
const words = wordCountOf(pub);
|
|
1696
|
+
const toc = Toc({ toc: article.toc, c, aside: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Slot, { name: "article.aside", slots: base.slots, className: "hyle-slot-wrap" }) });
|
|
1697
|
+
const notTranslated = article.fallback ? s.fallbackTitle.replace("{language}", languageName(article.fallback.requested_locale, c.locale)) : void 0;
|
|
1698
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("article", { className: "hyle-article", "data-hyle-page": "article", lang: c.locale, children: [
|
|
1699
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("header", { className: "hyle-head", children: [
|
|
1700
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Slot, { name: "article.before", slots: base.slots, className: "hyle-eyebrow" }),
|
|
1701
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Crumbs, { items: breadcrumbItems(article, jsonLd), c }),
|
|
1702
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h1", { className: "hyle-title", children: pub.title }),
|
|
1703
|
+
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
1704
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-meta", children: [
|
|
1705
|
+
author ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
1706
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: author.slice(0, 2).toUpperCase() }),
|
|
1707
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
1708
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "hyle-sr", children: [
|
|
1709
|
+
s.by,
|
|
1710
|
+
" "
|
|
1711
|
+
] }),
|
|
1712
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "by", children: author })
|
|
1713
|
+
] })
|
|
1714
|
+
] }) : null,
|
|
1715
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
1716
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "calendar" }),
|
|
1717
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: pub.published_at, title: pub.published_at, children: formatDate(pub.published_at, c.locale) })
|
|
1718
|
+
] }),
|
|
1719
|
+
modified ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
1720
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "calendar" }),
|
|
1721
|
+
s.updated,
|
|
1722
|
+
" ",
|
|
1723
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: modified, title: modified, children: formatDate(modified, c.locale) })
|
|
1724
|
+
] }) : null,
|
|
1725
|
+
words ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
1726
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "clock" }),
|
|
1727
|
+
s.readingTime.replace("{n}", String(readingMinutes(words)))
|
|
1728
|
+
] }) : null,
|
|
1729
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
1730
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "globe" }),
|
|
1731
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { lang: pub.locale, children: languageName(pub.locale, c.locale) })
|
|
1732
|
+
] }),
|
|
1733
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Slot, { name: "article.meta", slots: base.slots, tag: "span" })
|
|
1734
|
+
] }),
|
|
1735
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Languages, { alternates: article.alternates, current: pub.locale, c }),
|
|
1736
|
+
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1737
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "alert" }),
|
|
1738
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
1739
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: notTranslated }),
|
|
1740
|
+
" ",
|
|
1741
|
+
s.fallbackBody
|
|
1742
|
+
] })
|
|
1743
|
+
] }) : null
|
|
1744
|
+
] }),
|
|
1745
|
+
toc.narrow,
|
|
1746
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
1747
|
+
engagement ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_comments.Comments, { path: pub.canonical_path, endpoint: engagement.endpoint ?? "/api/hyle/engage", signInHref: engagement.signInHref, locale: c.locale, labels: s.comments }) : null,
|
|
1748
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Pager, { prev: article.prev, next: article.next, c }),
|
|
1749
|
+
related ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1750
|
+
related.items.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HyleListView, { items: related.items, title: related.title ?? s.moreInSection, ...base, locale: c.locale }) : null,
|
|
1751
|
+
article.children.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HyleListView, { items: article.children.map((child) => ({ ...child, description: null, published_at: "" })), title: s.subPages, ...base, locale: c.locale }) : null
|
|
1752
|
+
] }) : null,
|
|
1753
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Slot, { name: "article.after", slots: base.slots, className: "hyle-after" }),
|
|
1754
|
+
toc.wide,
|
|
1755
|
+
jsonLdOrigin ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(LdScript, { json: articleJsonLd({ article, origin: jsonLdOrigin, href: c.href, jsonLd, imageUrl, imageWidth, imageHeight }) }) : null
|
|
1756
|
+
] }) });
|
|
1757
|
+
}
|
|
1758
|
+
function ListPage({ list, olderHref, description, origin, path, jsonLd, cursor, ...base }) {
|
|
1759
|
+
const c = ctx(base, "en");
|
|
1760
|
+
const { s, Link } = c;
|
|
1761
|
+
const Row = base.slots?.["list.item"];
|
|
1762
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1763
|
+
for (const item of list.items) groups.set(item.published_at.slice(0, 7), [...groups.get(item.published_at.slice(0, 7)) ?? [], item]);
|
|
1764
|
+
const notTranslated = list.fallback ? s.fallbackTitle.replace("{language}", languageName(list.fallback.requested_locale, c.locale)) : void 0;
|
|
1765
|
+
const jsonLdOrigin = bareOrigin(origin);
|
|
1766
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-listpage", "data-hyle-page": "list", lang: c.locale, children: [
|
|
1767
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("header", { className: "hyle-head", children: [
|
|
1768
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h1", { className: "hyle-title", children: list.section.title }),
|
|
1769
|
+
description ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-desc", children: description }) : null,
|
|
1770
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Slot, { name: "list.header", slots: base.slots, className: "hyle-slot-wrap" }),
|
|
1771
|
+
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1772
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "alert" }),
|
|
1773
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
1774
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: notTranslated }),
|
|
1775
|
+
" ",
|
|
1776
|
+
s.fallbackBody
|
|
1777
|
+
] })
|
|
1778
|
+
] }) : null
|
|
1779
|
+
] }),
|
|
1780
|
+
list.items.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-empty", "data-slot-state": "empty", children: [
|
|
1781
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "file" }),
|
|
1782
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h2", { children: s.emptyTitle }),
|
|
1783
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.emptyBody }),
|
|
1784
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Slot, { name: "list.empty", slots: base.slots })
|
|
1785
|
+
] }) : [...groups].map(([month, items]) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { "aria-label": formatDate(`${month}-01`, c.locale, { month: "long", year: "numeric" }), children: [
|
|
1786
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h2", { className: "hyle-year", children: formatDate(`${month}-01`, c.locale, { month: "long", year: "numeric" }) }),
|
|
1787
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "hyle-items", children: items.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: [
|
|
1788
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: item.published_at, title: item.published_at, children: formatDate(item.published_at, c.locale) }),
|
|
1789
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
1790
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "t", children: item.title }),
|
|
1791
|
+
item.description ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: item.description }) : null
|
|
1792
|
+
] })
|
|
1793
|
+
] }) }, item.canonical_path)) })
|
|
1794
|
+
] }, month)),
|
|
1795
|
+
olderHref ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OlderNav, { href: olderHref, c }) : null,
|
|
1796
|
+
jsonLdOrigin && path ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(LdScript, { json: listJsonLd({ list, origin: jsonLdOrigin, href: c.href, path, locale: c.locale, description, jsonLd, cursor }) }) : null
|
|
1797
|
+
] }) });
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
// src/react/index.ts
|
|
1801
|
+
var import_comments2 = require("./comments.cjs");
|
|
1802
|
+
|
|
1624
1803
|
// src/react/docs.tsx
|
|
1625
1804
|
var import_docs_enhance = require("./docs-enhance.cjs");
|
|
1626
1805
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
@@ -1754,7 +1933,7 @@ var MAX_TAGS2 = 64;
|
|
|
1754
1933
|
function workspaceTags(workspaceId, sections = []) {
|
|
1755
1934
|
const workspaceTag = `hyle:1:ws:${workspaceId}`;
|
|
1756
1935
|
if (!isValidCacheTag(workspaceTag)) throw new TypeError("hyle: `workspaceId` is not a valid workspace id (a uuid)");
|
|
1757
|
-
const slugs =
|
|
1936
|
+
const slugs = new Set(sections);
|
|
1758
1937
|
const tags = [...slugs].map((slug) => `hyle:1:sec:${workspaceId}:${slug}`);
|
|
1759
1938
|
if (!tags.every(isValidCacheTag)) throw new TypeError("hyle: a configured `sections` slug cannot be used in a cache tag (printable ASCII, at most 200 characters)");
|
|
1760
1939
|
return [workspaceTag, ...tags].slice(0, MAX_TAGS2);
|
|
@@ -1764,9 +1943,10 @@ function fetchResolver(options) {
|
|
|
1764
1943
|
const client = createHyleClient({ baseUrl: options.baseUrl, token: options.token });
|
|
1765
1944
|
const revalidate = options.revalidate ?? DEFAULT_REVALIDATE;
|
|
1766
1945
|
const tags = workspaceTags(options.workspaceId, options.sections);
|
|
1767
|
-
return (path, locale, limit, cursor, nav) => client.resolve({
|
|
1946
|
+
return (path, locale, limit, cursor, nav, format) => client.resolve({
|
|
1768
1947
|
path,
|
|
1769
1948
|
...nav !== void 0 ? { nav } : {},
|
|
1949
|
+
...format !== void 0 ? { format } : {},
|
|
1770
1950
|
...locale !== void 0 ? { locale } : {},
|
|
1771
1951
|
...limit !== void 0 ? { limit } : {},
|
|
1772
1952
|
...cursor !== void 0 ? { cursor } : {},
|
|
@@ -1778,16 +1958,22 @@ function fetchResolver(options) {
|
|
|
1778
1958
|
function resolverFor(options) {
|
|
1779
1959
|
return options.resolver ?? fetchResolver(options);
|
|
1780
1960
|
}
|
|
1961
|
+
function articleImage(options, article) {
|
|
1962
|
+
const { canonical_path, locale, title, updated_at } = article.publication;
|
|
1963
|
+
const edited = Date.parse(updated_at);
|
|
1964
|
+
const fallback = { url: `/api/hyle/og${canonical_path.split("/").map(encodeURIComponent).join("/")}?locale=${encodeURIComponent(locale)}${Number.isNaN(edited) ? "" : `&v=${edited}`}`, width: 1200, height: 630, alt: title };
|
|
1965
|
+
return validOgImage(options.ogImage ? options.ogImage(article) : options.ogImageRoute ? fallback : void 0, bareOrigin(options.siteOrigin));
|
|
1966
|
+
}
|
|
1781
1967
|
var CURSOR = /^[A-Za-z0-9_-]{1,256}$/;
|
|
1782
1968
|
var validCursor = (value) => typeof value === "string" && CURSOR.test(value) ? value : void 0;
|
|
1783
|
-
var
|
|
1969
|
+
var LOCALE_TAG2 = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
|
|
1784
1970
|
var MAX_LOCALE_LENGTH = 35;
|
|
1785
1971
|
function routeContext(options, params) {
|
|
1786
1972
|
const basePath = normalizeBasePath(options.basePath);
|
|
1787
1973
|
const segments = params[options.param ?? "hyle"];
|
|
1788
1974
|
const path = sitePathFrom(basePath, typeof segments === "string" ? [segments] : segments);
|
|
1789
1975
|
const given = typeof options.locale === "function" ? options.locale(params) : options.locale;
|
|
1790
|
-
const locale = typeof given === "string" && given.length <= MAX_LOCALE_LENGTH &&
|
|
1976
|
+
const locale = typeof given === "string" && given.length <= MAX_LOCALE_LENGTH && LOCALE_TAG2.test(given) ? given : void 0;
|
|
1791
1977
|
const prefix = options.localePrefix ?? (() => "");
|
|
1792
1978
|
const toHref = (sitePath, linkLocale = locale) => (linkLocale ? prefix(linkLocale) : "") + sitePath;
|
|
1793
1979
|
return { basePath, path, locale, toHref };
|
|
@@ -1797,41 +1983,406 @@ function isRejectedRequest(error) {
|
|
|
1797
1983
|
return error instanceof Cp1ClientError && error.status >= 400 && error.status < 500 && ![401, 403, 429].includes(error.status);
|
|
1798
1984
|
}
|
|
1799
1985
|
|
|
1800
|
-
// src/next/
|
|
1801
|
-
var
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1986
|
+
// src/next/embed.tsx
|
|
1987
|
+
var import_navigation2 = require("next/navigation");
|
|
1988
|
+
|
|
1989
|
+
// src/next/engage.ts
|
|
1990
|
+
var ENGAGE_CSRF_HEADER = "x-hyle-engage";
|
|
1991
|
+
var DEFAULT_TIMEOUT_MS2 = 1e4;
|
|
1992
|
+
var DEFAULT_SHARE_MS = 3e3;
|
|
1993
|
+
var MAX_SHARED = 100;
|
|
1994
|
+
var MAX_SHARED_BYTES = 8 * 1024 * 1024;
|
|
1995
|
+
var MAX_SHARED_ENTRY_BYTES = 256 * 1024;
|
|
1996
|
+
var MAX_BODY_BYTES2 = 20 * 1024;
|
|
1997
|
+
var MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
1998
|
+
var MAX_COMMENT_CHARACTERS = 4e3;
|
|
1999
|
+
var MAX_PATH_LENGTH2 = 1024;
|
|
2000
|
+
var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
2001
|
+
var CONTROL = /[\u0000-\u001f\u007f\\]/;
|
|
2002
|
+
var HEADERS = { "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" };
|
|
2003
|
+
var isSwitchedOff = (value) => {
|
|
2004
|
+
const v = value?.trim().toLowerCase() ?? "";
|
|
2005
|
+
return v !== "" && v !== "1" && v !== "true";
|
|
2006
|
+
};
|
|
2007
|
+
var json = (status, body, extra = {}) => new Response(JSON.stringify(body), { status, headers: { ...HEADERS, "Content-Type": "application/json; charset=utf-8", ...extra } });
|
|
2008
|
+
var refuse = (status, code, extra = {}) => json(status, { error: { code } }, extra);
|
|
2009
|
+
function isSitePath2(value) {
|
|
2010
|
+
if (typeof value !== "string" || value.length > MAX_PATH_LENGTH2 || !value.startsWith("/") || value.startsWith("//")) return false;
|
|
2011
|
+
if (CONTROL.test(value) || /[?#]/.test(value)) return false;
|
|
2012
|
+
return !value.split("/").some((segment) => segment === "." || segment === "..");
|
|
2013
|
+
}
|
|
2014
|
+
function match(segments) {
|
|
2015
|
+
const [a, b, ...rest] = segments;
|
|
2016
|
+
if (a === "session" && b === void 0) return { local: "session", action: () => "session", methods: ["GET"], rebuild: () => void 0 };
|
|
2017
|
+
if (a === "comments" && b === void 0) {
|
|
2018
|
+
return {
|
|
2019
|
+
action: (m) => m === "GET" ? "comments.list" : "comments.create",
|
|
2020
|
+
methods: ["GET", "POST"],
|
|
2021
|
+
rebuild: (method, body, url) => {
|
|
2022
|
+
if (method === "GET") {
|
|
2023
|
+
const keys = [...url.searchParams.keys()];
|
|
2024
|
+
const path = url.searchParams.get("path");
|
|
2025
|
+
return keys.length === 1 && isSitePath2(path) ? { upstream: "/comments", query: new URLSearchParams({ path }) } : void 0;
|
|
2026
|
+
}
|
|
2027
|
+
const clean2 = pick(body, ["path", "body", "parent_id"], ["path", "body"]);
|
|
2028
|
+
if (!clean2 || !isSitePath2(clean2.path) || !isCommentText(clean2.body)) return void 0;
|
|
2029
|
+
if (clean2.parent_id === null) delete clean2.parent_id;
|
|
2030
|
+
if (clean2.parent_id !== void 0 && !(typeof clean2.parent_id === "string" && UUID2.test(clean2.parent_id))) return void 0;
|
|
2031
|
+
return { upstream: "/comments", body: clean2 };
|
|
2032
|
+
}
|
|
2033
|
+
};
|
|
2034
|
+
}
|
|
2035
|
+
if (a === "comments" && typeof b === "string" && UUID2.test(b) && rest.length === 0) {
|
|
2036
|
+
return {
|
|
2037
|
+
action: (m) => m === "PATCH" ? "comments.edit" : "comments.delete",
|
|
2038
|
+
methods: ["PATCH", "DELETE"],
|
|
2039
|
+
rebuild: (method, body) => {
|
|
2040
|
+
if (method === "DELETE") return body === void 0 ? { upstream: `/comments/${b}` } : void 0;
|
|
2041
|
+
const clean2 = pick(body, ["body"], ["body"]);
|
|
2042
|
+
return clean2 && isCommentText(clean2.body) ? { upstream: `/comments/${b}`, body: clean2 } : void 0;
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
}
|
|
2046
|
+
if (a === "reactions" && b === void 0) {
|
|
2047
|
+
return {
|
|
2048
|
+
action: (m) => m === "PUT" ? "reactions.add" : "reactions.remove",
|
|
2049
|
+
methods: ["PUT", "DELETE"],
|
|
2050
|
+
rebuild: (_method, body) => {
|
|
2051
|
+
const type = body?.subject_type;
|
|
2052
|
+
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;
|
|
2053
|
+
if (!clean2) return void 0;
|
|
2054
|
+
const valid = type === "article" ? isSitePath2(clean2.path) : typeof clean2.comment_id === "string" && UUID2.test(clean2.comment_id);
|
|
2055
|
+
return valid ? { upstream: "/reactions", body: clean2 } : void 0;
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
return void 0;
|
|
2060
|
+
}
|
|
2061
|
+
function pick(body, allowed, required) {
|
|
2062
|
+
if (!body || Object.keys(body).some((k) => !allowed.includes(k)) || !required.every((k) => k in body)) return void 0;
|
|
2063
|
+
return Object.fromEntries(allowed.filter((k) => k in body).map((k) => [k, body[k]]));
|
|
2064
|
+
}
|
|
2065
|
+
function isCommentText(value) {
|
|
2066
|
+
return typeof value === "string" && value.trim().length > 0 && [...value].length <= MAX_COMMENT_CHARACTERS && !/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/.test(value);
|
|
2067
|
+
}
|
|
2068
|
+
function sameOriginProblem(req, write, allowedOrigins) {
|
|
2069
|
+
const site = req.headers.get("sec-fetch-site");
|
|
2070
|
+
if (site !== null && site !== "same-origin") return true;
|
|
2071
|
+
if (!write) return false;
|
|
2072
|
+
const origin = req.headers.get("origin");
|
|
2073
|
+
if (origin === null) return true;
|
|
2074
|
+
let parsed;
|
|
2075
|
+
try {
|
|
2076
|
+
parsed = new URL(origin);
|
|
2077
|
+
} catch {
|
|
2078
|
+
return true;
|
|
2079
|
+
}
|
|
2080
|
+
if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
|
|
2081
|
+
if (allowedOrigins) return !allowedOrigins.some((o) => safeOrigin(o) === parsed.origin);
|
|
2082
|
+
const host = req.headers.get("x-forwarded-host")?.split(",")[0]?.trim() || req.headers.get("host") || new URL(req.url).host;
|
|
2083
|
+
const proto = req.headers.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase();
|
|
2084
|
+
if (proto && proto !== parsed.protocol.slice(0, -1)) return true;
|
|
2085
|
+
return parsed.host !== host;
|
|
2086
|
+
}
|
|
2087
|
+
var safeOrigin = (value) => {
|
|
2088
|
+
try {
|
|
2089
|
+
return new URL(value).origin;
|
|
2090
|
+
} catch {
|
|
2091
|
+
return void 0;
|
|
2092
|
+
}
|
|
2093
|
+
};
|
|
2094
|
+
async function readBody(req, expected) {
|
|
2095
|
+
if (!expected) return { kind: "ok", body: void 0 };
|
|
2096
|
+
if (!/^application\/json(\s*;|$)/i.test(req.headers.get("content-type") ?? "")) return { kind: "refused", response: refuse(415, "UNSUPPORTED_MEDIA_TYPE") };
|
|
2097
|
+
if (Number(req.headers.get("content-length")) > MAX_BODY_BYTES2) return { kind: "refused", response: refuse(413, "PAYLOAD_TOO_LARGE") };
|
|
2098
|
+
if (!req.body) return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
2099
|
+
const reader = req.body.getReader();
|
|
2100
|
+
const chunks = [];
|
|
2101
|
+
let total = 0;
|
|
2102
|
+
for (; ; ) {
|
|
2103
|
+
const { done, value } = await reader.read();
|
|
2104
|
+
if (done) break;
|
|
2105
|
+
total += value.byteLength;
|
|
2106
|
+
if (total > MAX_BODY_BYTES2) {
|
|
2107
|
+
await reader.cancel().catch(() => {
|
|
2108
|
+
});
|
|
2109
|
+
return { kind: "refused", response: refuse(413, "PAYLOAD_TOO_LARGE") };
|
|
2110
|
+
}
|
|
2111
|
+
chunks.push(value);
|
|
2112
|
+
}
|
|
2113
|
+
try {
|
|
2114
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
2115
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return { kind: "ok", body: parsed };
|
|
2116
|
+
} catch {
|
|
2117
|
+
}
|
|
2118
|
+
return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
2119
|
+
}
|
|
2120
|
+
var SUB_CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
|
|
2121
|
+
function validReader(r) {
|
|
2122
|
+
if (!r || typeof r.sub !== "string" || typeof r.name !== "string") return null;
|
|
2123
|
+
if (r.sub.length < 1 || [...r.sub].length > 255 || SUB_CONTROL.test(r.sub)) return null;
|
|
2124
|
+
const name = cleanDisplayName(r.name);
|
|
2125
|
+
return name === void 0 ? null : { sub: r.sub, name };
|
|
2126
|
+
}
|
|
2127
|
+
function relayFailure(status, retryAfter) {
|
|
2128
|
+
if (status === 400) return refuse(400, "VALIDATION_ERROR");
|
|
2129
|
+
if (status === 404) return refuse(404, "NOT_FOUND");
|
|
2130
|
+
if (status === 409) return refuse(409, "INVALID_TRANSITION");
|
|
2131
|
+
if (status === 413) return refuse(413, "PAYLOAD_TOO_LARGE");
|
|
2132
|
+
if (status === 429) {
|
|
2133
|
+
const seconds = Math.min(3600, Math.max(1, Math.trunc(Number(retryAfter)) || 60));
|
|
2134
|
+
return refuse(429, "RATE_LIMITED", { "Retry-After": String(seconds) });
|
|
2135
|
+
}
|
|
2136
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2137
|
+
}
|
|
2138
|
+
function createEngagementRoute(options) {
|
|
2139
|
+
let ready;
|
|
2140
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
2141
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2142
|
+
let cacheBytes = 0;
|
|
2143
|
+
const clearCache = () => {
|
|
2144
|
+
cache.clear();
|
|
2145
|
+
cacheBytes = 0;
|
|
2146
|
+
};
|
|
2147
|
+
async function listing(viewer, call) {
|
|
2148
|
+
if (!viewer) return call(void 0);
|
|
2149
|
+
let out = await call(viewer.sign("read"));
|
|
2150
|
+
if (out.status === 401) out = await call(viewer.sign("read"));
|
|
2151
|
+
if (out.status !== 401 && out.status !== 404 && !(out.status === 429 && out.throttle === "viewer")) return out;
|
|
2152
|
+
return { ...await call(void 0), noShare: true };
|
|
2153
|
+
}
|
|
2154
|
+
function shared(key, call) {
|
|
2155
|
+
const ttl = options.cacheTtlMs ?? DEFAULT_SHARE_MS;
|
|
2156
|
+
if (ttl <= 0) return call();
|
|
2157
|
+
const hit = cache.get(key);
|
|
2158
|
+
if (hit && Date.now() - hit.at < ttl) {
|
|
2159
|
+
cache.delete(key);
|
|
2160
|
+
cache.set(key, hit);
|
|
2161
|
+
return hit.result;
|
|
2162
|
+
}
|
|
2163
|
+
if (hit) forget(key, hit);
|
|
2164
|
+
const entry = { at: Date.now(), result: call(), bytes: 0 };
|
|
2165
|
+
cache.set(key, entry);
|
|
2166
|
+
entry.result.then(
|
|
2167
|
+
(o) => {
|
|
2168
|
+
if (cache.get(key) !== entry) return;
|
|
2169
|
+
if (o.status !== 200 && o.status !== 404 || o.noShare || o.text.length > MAX_SHARED_ENTRY_BYTES) return forget(key, entry);
|
|
2170
|
+
entry.bytes = o.text.length;
|
|
2171
|
+
cacheBytes += entry.bytes;
|
|
2172
|
+
while ((cacheBytes > MAX_SHARED_BYTES || cache.size > MAX_SHARED) && cache.size > 0) {
|
|
2173
|
+
const oldest = cache.entries().next().value;
|
|
2174
|
+
forget(oldest[0], oldest[1]);
|
|
2175
|
+
}
|
|
2176
|
+
},
|
|
2177
|
+
() => forget(key, entry)
|
|
2178
|
+
);
|
|
2179
|
+
return entry.result;
|
|
2180
|
+
}
|
|
2181
|
+
function forget(key, entry) {
|
|
2182
|
+
if (cache.get(key) !== entry) return;
|
|
2183
|
+
cache.delete(key);
|
|
2184
|
+
cacheBytes -= entry.bytes;
|
|
2185
|
+
}
|
|
2186
|
+
function configured() {
|
|
2187
|
+
if (ready !== void 0) return ready;
|
|
2188
|
+
try {
|
|
2189
|
+
const baseUrl = options.baseUrl?.trim() ?? "";
|
|
2190
|
+
checkBaseUrl(baseUrl);
|
|
2191
|
+
if (!options.token?.trim() || !options.workspaceId?.trim() || !options.signingKey) throw new TypeError("not provisioned");
|
|
2192
|
+
ready = { base: baseUrl.replace(/\/+$/, ""), key: engagementSigningKey(options.signingKey.trim()) };
|
|
2193
|
+
} catch {
|
|
2194
|
+
ready = null;
|
|
2195
|
+
}
|
|
2196
|
+
return ready;
|
|
2197
|
+
}
|
|
2198
|
+
async function reader(req, config) {
|
|
2199
|
+
try {
|
|
2200
|
+
const found = validReader(await options.getReader(req));
|
|
2201
|
+
if (!found) return null;
|
|
2202
|
+
const claims = { sub: found.sub, name: found.name, workspace: options.workspaceId.trim() };
|
|
2203
|
+
const sign2 = (scope) => signReaderAssertion(config.key, claims, void 0, scope);
|
|
2204
|
+
return { reader: found, assertion: sign2(), sign: sign2 };
|
|
2205
|
+
} catch {
|
|
2206
|
+
return null;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
async function handle(req, ctx2) {
|
|
2210
|
+
const env = options.env ?? process.env;
|
|
2211
|
+
if (isSwitchedOff(env.HYLE_ENGAGE_ENABLED) || isSwitchedOff(env.HYLE_CONTENT_ENABLED)) return refuse(404, "NOT_FOUND");
|
|
2212
|
+
const config = configured();
|
|
2213
|
+
const route = match((await ctx2.params).path ?? []);
|
|
2214
|
+
if (!config || !route) return refuse(404, "NOT_FOUND");
|
|
2215
|
+
if (!route.methods.includes(req.method)) return refuse(405, "METHOD_NOT_ALLOWED", { Allow: route.methods.join(", ") });
|
|
2216
|
+
const write = req.method !== "GET";
|
|
2217
|
+
if (sameOriginProblem(req, write, options.allowedOrigins)) return refuse(403, "FORBIDDEN");
|
|
2218
|
+
if (options.onRequest) {
|
|
2219
|
+
try {
|
|
2220
|
+
const early = await options.onRequest(req, { action: route.action(req.method) });
|
|
2221
|
+
if (early instanceof Response) {
|
|
2222
|
+
const headers = new Headers(early.headers);
|
|
2223
|
+
headers.set("cache-control", "no-store");
|
|
2224
|
+
return new Response(early.body, { status: early.status, headers });
|
|
2225
|
+
}
|
|
2226
|
+
} catch {
|
|
2227
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
if (route.local === "session") {
|
|
2231
|
+
const who = await reader(req, config);
|
|
2232
|
+
return json(200, { data: { reader: who ? { name: who.reader.name } : null } });
|
|
2233
|
+
}
|
|
2234
|
+
let assertion;
|
|
2235
|
+
let viewer = null;
|
|
2236
|
+
if (route.action(req.method) === "comments.list") viewer = await reader(req, config);
|
|
2237
|
+
if (write) {
|
|
2238
|
+
const who = await reader(req, config);
|
|
2239
|
+
if (!who) return refuse(401, "UNAUTHENTICATED");
|
|
2240
|
+
assertion = who.assertion;
|
|
2241
|
+
}
|
|
2242
|
+
const url = new URL(req.url);
|
|
2243
|
+
const hasBody = write && !(req.method === "DELETE" && (await ctx2.params).path?.[0] === "comments");
|
|
2244
|
+
const body = await readBody(req, hasBody);
|
|
2245
|
+
if (body.kind === "refused") return body.response;
|
|
2246
|
+
const built = route.rebuild(req.method, body.body, url);
|
|
2247
|
+
if (!built) return refuse(400, "VALIDATION_ERROR");
|
|
2248
|
+
const baseHeaders = new Headers({ authorization: `Bearer ${options.token.trim()}`, accept: "application/json" });
|
|
2249
|
+
if (built.body) baseHeaders.set("content-type", "application/json");
|
|
2250
|
+
const target = `${config.base}/cp1/engage${built.upstream}${built.query ? `?${built.query}` : ""}`;
|
|
2251
|
+
const call = async (withAssertion = assertion) => {
|
|
2252
|
+
const headers = new Headers(baseHeaders);
|
|
2253
|
+
if (withAssertion) headers.set("hyle-reader-assertion", withAssertion);
|
|
2254
|
+
const res = await fetchImpl(target, {
|
|
2255
|
+
method: req.method,
|
|
2256
|
+
headers,
|
|
2257
|
+
...built.body ? { body: JSON.stringify(built.body) } : {},
|
|
2258
|
+
redirect: "error",
|
|
2259
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS2)
|
|
2260
|
+
});
|
|
2261
|
+
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") };
|
|
2262
|
+
};
|
|
2263
|
+
try {
|
|
2264
|
+
const out = route.action(req.method) === "comments.list" ? await shared(`${viewer?.reader.sub ?? ""}
|
|
2265
|
+
${built.query.toString()}`, () => listing(viewer, call)) : await call();
|
|
2266
|
+
if (!out.ok) return relayFailure(out.status, out.retryAfter);
|
|
2267
|
+
if (write) clearCache();
|
|
2268
|
+
const data = JSON.parse(out.text).data;
|
|
2269
|
+
return typeof data === "object" && data !== null ? json(out.status === 201 ? 201 : 200, { data }) : refuse(502, "UPSTREAM_ERROR");
|
|
2270
|
+
} catch {
|
|
2271
|
+
return refuse(502, "UPSTREAM_ERROR");
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
return { GET: handle, POST: handle, PATCH: handle, PUT: handle, DELETE: handle };
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
// src/next/embed.tsx
|
|
2278
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
2279
|
+
async function resolveEmbed(options, run) {
|
|
2280
|
+
try {
|
|
2281
|
+
return { result: await run() };
|
|
2282
|
+
} catch (error) {
|
|
2283
|
+
if (isRejectedRequest(error)) return {};
|
|
2284
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2285
|
+
return { failure: options.onError ? options.onError(error) : null };
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
async function HyleList({ options, limit = 5, locale, layout, title, headingLevel, moreHref, cursor, olderHref }) {
|
|
2289
|
+
const resolve = resolverFor(options);
|
|
2290
|
+
const route = routeContext(locale ? { ...options, locale } : options, {});
|
|
2291
|
+
const path = sitePathFrom(route.basePath, void 0);
|
|
2292
|
+
if (path === void 0) return null;
|
|
2293
|
+
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale, limit, validCursor(cursor)));
|
|
2294
|
+
if (failure !== void 0) return failure;
|
|
2295
|
+
const next = olderHref && result?.kind === "list" ? validCursor(result.next_cursor) : void 0;
|
|
2296
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(HyleListView, { items: result?.kind === "list" ? result.items : [], layout, title, headingLevel, moreHref, olderHref: next ? olderHref?.(next) : void 0, components: options.components, slots: options.slots, locale: route.locale, toHref: route.toHref });
|
|
2297
|
+
}
|
|
2298
|
+
async function HyleArticle({ options, path, locale, headingLevel }) {
|
|
2299
|
+
if (!isSitePath2(path)) return null;
|
|
2300
|
+
const resolve = resolverFor(options);
|
|
2301
|
+
const route = routeContext(locale ? { ...options, locale } : options, {});
|
|
2302
|
+
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale));
|
|
2303
|
+
if (failure !== void 0) return failure;
|
|
2304
|
+
if (result?.kind !== "article") return null;
|
|
2305
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(HyleArticleView, { article: result, headingLevel, components: options.components, slots: options.slots, locale: route.locale, toHref: route.toHref });
|
|
2306
|
+
}
|
|
2307
|
+
var MAX_LISTING_BYTES = 4 * 1024 * 1024;
|
|
2308
|
+
var COMMENTS_TIMEOUT_MS = 1e4;
|
|
2309
|
+
async function HyleComments({ options, path, revalidate = 60, interactive }) {
|
|
2310
|
+
checkBaseUrl(options.baseUrl);
|
|
2311
|
+
if (!options.token) throw new TypeError("token is required");
|
|
2312
|
+
if (!isSitePath2(path)) return null;
|
|
2313
|
+
const locale = options.locale ?? "en";
|
|
2314
|
+
let listing;
|
|
2315
|
+
let fetchedAt;
|
|
2316
|
+
try {
|
|
2317
|
+
const init = {
|
|
2318
|
+
headers: { authorization: `Bearer ${options.token}`, accept: "application/json" },
|
|
2319
|
+
redirect: "error",
|
|
2320
|
+
signal: AbortSignal.timeout(COMMENTS_TIMEOUT_MS),
|
|
2321
|
+
next: { revalidate }
|
|
2322
|
+
};
|
|
2323
|
+
const res = await fetch(`${options.baseUrl.replace(/\/+$/, "")}/cp1/engage/comments?${new URLSearchParams({ path })}`, init);
|
|
2324
|
+
if (!res.ok) {
|
|
2325
|
+
if (res.status !== 404) console.error(`hyle: comments answered HTTP ${res.status}`);
|
|
2326
|
+
return null;
|
|
2327
|
+
}
|
|
2328
|
+
listing = parseListing(JSON.parse(await readCapped(res, MAX_LISTING_BYTES)).data);
|
|
2329
|
+
const date = Date.parse(res.headers.get("date") ?? "");
|
|
2330
|
+
fetchedAt = Number.isFinite(date) ? date : void 0;
|
|
2331
|
+
} catch (error) {
|
|
2332
|
+
(0, import_navigation2.unstable_rethrow)(error);
|
|
2333
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2334
|
+
return null;
|
|
2335
|
+
}
|
|
2336
|
+
if (!listing) return null;
|
|
2337
|
+
if (!interactive) return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(HyleCommentsView, { listing, locale });
|
|
2338
|
+
const config = interactive === true ? {} : interactive;
|
|
2339
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "hyle hyle-embed", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_comments2.Comments, { path, endpoint: config.endpoint ?? "/api/hyle/engage", signInHref: config.signInHref, locale, labels: stringsFor(locale).comments, initial: listing, initialAt: fetchedAt }) });
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2342
|
+
// src/next/page.tsx
|
|
2343
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
2344
|
+
function hylePage(options) {
|
|
2345
|
+
const resolve = resolverFor(options);
|
|
2346
|
+
async function relatedItems(article) {
|
|
2347
|
+
const { limit = 5, title } = options.related ?? {};
|
|
2348
|
+
const section = article.breadcrumbs[0]?.canonical_path ?? (normalizeBasePath(options.basePath) || "/");
|
|
2349
|
+
const { result } = await resolveEmbed(options, () => resolve(section, article.publication.locale, limit + 1));
|
|
2350
|
+
const items = result?.kind === "list" ? result.items.filter((item) => item.canonical_path !== article.publication.canonical_path).slice(0, limit) : [];
|
|
2351
|
+
return { title, items };
|
|
2352
|
+
}
|
|
2353
|
+
return async function HylePage({ params, searchParams }) {
|
|
2354
|
+
const { path, locale, toHref } = routeContext(options, await params ?? {});
|
|
2355
|
+
if (path === void 0) (0, import_navigation3.notFound)();
|
|
2356
|
+
try {
|
|
2357
|
+
const cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
2358
|
+
const result = await resolve(path, locale, options.listLimit, cursor, options.layout === "docs" ? "tree" : void 0);
|
|
2359
|
+
switch (result.kind) {
|
|
2360
|
+
case "article": {
|
|
2361
|
+
const image = articleImage(options, result);
|
|
2362
|
+
const related = options.related && options.layout !== "docs" ? await relatedItems(result) : void 0;
|
|
2363
|
+
const props = { article: result, components: options.components, slots: options.slots, locale, toHref };
|
|
2364
|
+
return options.layout === "docs" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(DocsPage, { ...props }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ArticlePage, { ...props, origin: options.siteOrigin, jsonLd: options.jsonLd, imageUrl: image?.url, imageWidth: image?.width, imageHeight: image?.height, related, ...options.engagement ? { engagement: options.engagement } : {} });
|
|
2365
|
+
}
|
|
2366
|
+
case "list": {
|
|
1816
2367
|
const list = options.list?.title ? { ...result, section: { ...result.section, title: options.list.title } } : result;
|
|
1817
2368
|
const next = options.paginate === "searchParams" ? validCursor(result.next_cursor) : void 0;
|
|
1818
2369
|
const olderHref = next ? `${toHref(path)}?cursor=${next}` : void 0;
|
|
1819
|
-
return /* @__PURE__ */ (0,
|
|
2370
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ListPage, { list, ...olderHref ? { olderHref } : {}, ...options.list?.description ? { description: options.list.description } : {}, components: options.components, slots: options.slots, locale, toHref, origin: options.siteOrigin, path, jsonLd: options.jsonLd, cursor });
|
|
1820
2371
|
}
|
|
1821
2372
|
case "redirect": {
|
|
1822
2373
|
const to = safeRedirectTarget(result.to);
|
|
1823
2374
|
if (to === void 0) throw new Cp1ClientError("INVALID_RESPONSE", "hyle returned an unsafe redirect target", 502, "");
|
|
1824
2375
|
const target = safeRedirectTarget(toHref(to));
|
|
1825
2376
|
if (target === void 0) throw new Cp1ClientError("INVALID_RESPONSE", "hyle returned an unsafe redirect target", 502, "");
|
|
1826
|
-
if (target === toHref(path)) (0,
|
|
1827
|
-
return result.status === 301 ? (0,
|
|
2377
|
+
if (target === toHref(path)) (0, import_navigation3.notFound)();
|
|
2378
|
+
return result.status === 301 ? (0, import_navigation3.permanentRedirect)(target) : (0, import_navigation3.redirect)(target);
|
|
1828
2379
|
}
|
|
1829
2380
|
case "notfound":
|
|
1830
2381
|
case "disabled":
|
|
1831
|
-
(0,
|
|
2382
|
+
(0, import_navigation3.notFound)();
|
|
1832
2383
|
}
|
|
1833
2384
|
} catch (error) {
|
|
1834
|
-
if (isRejectedRequest(error)) (0,
|
|
2385
|
+
if (isRejectedRequest(error)) (0, import_navigation3.notFound)();
|
|
1835
2386
|
if (!options.onError) throw error;
|
|
1836
2387
|
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
1837
2388
|
return options.onError(error);
|
|
@@ -1841,6 +2392,7 @@ function hylePage(options) {
|
|
|
1841
2392
|
|
|
1842
2393
|
// src/next/sitemap.ts
|
|
1843
2394
|
var ISO_DATE = /^\d{4}-\d{2}-\d{2}T/;
|
|
2395
|
+
var isoTime = (value) => value && ISO_DATE.test(value) ? Date.parse(value) : NaN;
|
|
1844
2396
|
function httpsOrigin(origin) {
|
|
1845
2397
|
let url;
|
|
1846
2398
|
try {
|
|
@@ -1859,60 +2411,153 @@ async function hyleSitemap(options) {
|
|
|
1859
2411
|
const locale = typeof options.locale === "string" ? options.locale : void 0;
|
|
1860
2412
|
const { basePath, toHref } = routeContext({ ...options, locale: () => locale }, {});
|
|
1861
2413
|
const client = { resolve: ({ path, locale: l, limit, cursor }) => resolve(path, l, limit, cursor) };
|
|
1862
|
-
const { paths, complete } = await listPublicationPaths({ client, basePath, ...
|
|
2414
|
+
const { paths, complete } = await listPublicationPaths({ client, basePath, ...locale ? { locale } : {} });
|
|
1863
2415
|
if (!complete && (options.onIncomplete === "throw" || options.onIncomplete === void 0 && paths.length === 0)) {
|
|
1864
2416
|
throw new Error("hyleSitemap: hyle could not be listed completely (see onIncomplete)");
|
|
1865
2417
|
}
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
2418
|
+
const memberUrl = (a) => origin + encodeURI(toHref(a.path, a.locale));
|
|
2419
|
+
return paths.map(({ path, publishedAt, updatedAt, alternates }) => {
|
|
2420
|
+
const latest = [publishedAt, updatedAt].filter((v) => !Number.isNaN(isoTime(v))).sort((x, y) => isoTime(y) - isoTime(x))[0];
|
|
2421
|
+
const modified = latest && new Date(latest).toISOString();
|
|
2422
|
+
const url = origin + encodeURI(toHref(path));
|
|
2423
|
+
return {
|
|
2424
|
+
url,
|
|
2425
|
+
...modified ? { lastModified: modified } : {},
|
|
2426
|
+
// Same gate as the page's hreflang: a group of one is not an alternate set.
|
|
2427
|
+
...alternates && alternates.length > 1 ? { alternates: { languages: options.defaultLocale === void 0 ? Object.fromEntries(alternates.map((a) => [a.locale, memberUrl(a)])) : hreflangLanguages(alternates, options.defaultLocale, url, memberUrl) } } : {}
|
|
2428
|
+
};
|
|
2429
|
+
});
|
|
1870
2430
|
}
|
|
1871
2431
|
|
|
1872
2432
|
// src/next/metadata.ts
|
|
2433
|
+
var titled = (template, title) => template?.includes("%s") ? { absolute: template.replace("%s", () => title) } : title;
|
|
2434
|
+
var LARGE_PREVIEW = "max-image-preview:large";
|
|
2435
|
+
var addDirective = (inherited) => {
|
|
2436
|
+
const tokens = (inherited ?? "").split(",").map((t) => t.trim()).filter(Boolean);
|
|
2437
|
+
return (tokens.includes(LARGE_PREVIEW) ? tokens : [...tokens, LARGE_PREVIEW]).join(", ");
|
|
2438
|
+
};
|
|
2439
|
+
var ROBOTS_KEYS = /* @__PURE__ */ new Set(["noarchive", "nosnippet", "noimageindex", "nocache", "notranslate", "indexifembedded", "nositelinkssearchbox", "unavailable_after", "max-video-preview", "max-image-preview", "max-snippet"]);
|
|
2440
|
+
var ROBOTS_ALIASES = {
|
|
2441
|
+
none: { index: false, follow: false },
|
|
2442
|
+
all: { index: true, follow: true },
|
|
2443
|
+
index: { index: true },
|
|
2444
|
+
noindex: { index: false },
|
|
2445
|
+
follow: { follow: true },
|
|
2446
|
+
nofollow: { follow: false }
|
|
2447
|
+
};
|
|
2448
|
+
function composeRobots(inherited) {
|
|
2449
|
+
const basic = addDirective(inherited?.basic);
|
|
2450
|
+
const object = {};
|
|
2451
|
+
for (const token of basic.split(", ")) {
|
|
2452
|
+
const colon = token.indexOf(":");
|
|
2453
|
+
const key = colon < 0 ? token : token.slice(0, colon);
|
|
2454
|
+
if (ROBOTS_KEYS.has(key)) object[key] = colon < 0 ? true : token.slice(colon + 1);
|
|
2455
|
+
else if (ROBOTS_ALIASES[key] && colon < 0) Object.assign(object, ROBOTS_ALIASES[key]);
|
|
2456
|
+
else return basic;
|
|
2457
|
+
}
|
|
2458
|
+
return { ...object, googleBot: addDirective(inherited?.googleBot) };
|
|
2459
|
+
}
|
|
2460
|
+
function hyleFeedLink(options, locale) {
|
|
2461
|
+
const { feed } = options;
|
|
2462
|
+
if (!feed || typeof feed.path === "function" && !locale) return void 0;
|
|
2463
|
+
const href = typeof feed.path === "function" ? feed.path(locale) : feed.path;
|
|
2464
|
+
const origin = bareOrigin(options.siteOrigin);
|
|
2465
|
+
return { url: origin ? absoluteUrl(origin, href) : href, title: feed.title ?? (options.siteName ? `${options.siteName} feed` : "Feed") };
|
|
2466
|
+
}
|
|
1873
2467
|
function hyleMetadata(options) {
|
|
1874
2468
|
const resolve = resolverFor(options);
|
|
1875
|
-
|
|
2469
|
+
const origin = bareOrigin(options.siteOrigin);
|
|
2470
|
+
return async function generateMetadata({ params, searchParams }, parent) {
|
|
1876
2471
|
const { path, locale, toHref } = routeContext(options, await params ?? {});
|
|
1877
2472
|
if (path === void 0) return {};
|
|
2473
|
+
const link = (sitePath, linkLocale) => {
|
|
2474
|
+
const href = toHref(sitePath, linkLocale);
|
|
2475
|
+
return origin ? absoluteUrl(origin, href) : href;
|
|
2476
|
+
};
|
|
2477
|
+
const withTypes = async (alternates, markdown) => {
|
|
2478
|
+
const feed = hyleFeedLink(options, locale);
|
|
2479
|
+
const types = {
|
|
2480
|
+
...parent ? (await parent).alternates?.types : void 0,
|
|
2481
|
+
...feed ? { "application/rss+xml": [feed] } : {},
|
|
2482
|
+
...markdown ? { "text/markdown": [{ url: markdown }] } : {}
|
|
2483
|
+
};
|
|
2484
|
+
return Object.keys(types).length ? { ...alternates, types } : alternates;
|
|
2485
|
+
};
|
|
1878
2486
|
try {
|
|
1879
2487
|
const cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
1880
2488
|
const result = await resolve(path, locale, options.listLimit, cursor, options.layout === "docs" ? "tree" : void 0);
|
|
2489
|
+
const parentMeta = parent ? await parent : void 0;
|
|
2490
|
+
const parentImages = parentMeta?.openGraph?.images;
|
|
1881
2491
|
if (result.kind === "list") {
|
|
1882
2492
|
const title = (options.list?.title || result.section.title) + (cursor ? ` - ${stringsFor(locale).older}` : "");
|
|
1883
2493
|
const description2 = options.list?.description;
|
|
2494
|
+
const ogLocale = locale && options.ogLocale?.(locale) || locale;
|
|
2495
|
+
const canonical2 = link(path) + (cursor ? `?cursor=${cursor}` : "");
|
|
1884
2496
|
return {
|
|
1885
|
-
title,
|
|
2497
|
+
title: titled(options.titleTemplate, title),
|
|
1886
2498
|
...description2 ? { description: description2 } : {},
|
|
1887
|
-
alternates: { canonical:
|
|
1888
|
-
openGraph: {
|
|
2499
|
+
alternates: await withTypes({ canonical: canonical2 }),
|
|
2500
|
+
openGraph: {
|
|
2501
|
+
type: "website",
|
|
2502
|
+
title,
|
|
2503
|
+
...description2 ? { description: description2 } : {},
|
|
2504
|
+
url: canonical2,
|
|
2505
|
+
...options.siteName ? { siteName: options.siteName } : {},
|
|
2506
|
+
...ogLocale ? { locale: ogLocale } : {},
|
|
2507
|
+
...parentImages?.length ? { images: parentImages } : {}
|
|
2508
|
+
}
|
|
1889
2509
|
};
|
|
1890
2510
|
}
|
|
1891
2511
|
if (result.kind !== "article") return {};
|
|
1892
2512
|
const { publication: pub, alternates, default_locale } = result;
|
|
1893
|
-
const canonical =
|
|
1894
|
-
const defaultAlternate = alternates.find((a) => a.locale === default_locale);
|
|
1895
|
-
const xDefault = defaultAlternate ? toHref(defaultAlternate.canonical_path, defaultAlternate.locale) : canonical;
|
|
2513
|
+
const canonical = link(pub.canonical_path, pub.locale);
|
|
1896
2514
|
const description = pub.description ?? void 0;
|
|
1897
|
-
const author =
|
|
1898
|
-
const modified =
|
|
2515
|
+
const author = articleAuthor(result, options.jsonLd)?.name;
|
|
2516
|
+
const modified = modifiedAt(pub);
|
|
2517
|
+
const image = articleImage(options, result);
|
|
2518
|
+
const alternateLocale = options.ogLocale ? alternates.filter((a) => a.locale !== pub.locale).flatMap((a) => options.ogLocale?.(a.locale) ?? []) : [];
|
|
2519
|
+
const { twitter } = options;
|
|
2520
|
+
const inherited = parentMeta?.robots;
|
|
2521
|
+
const section = result.breadcrumbs[0]?.title;
|
|
2522
|
+
const words = wordCountOf(pub);
|
|
1899
2523
|
return {
|
|
1900
|
-
title: pub.title,
|
|
2524
|
+
title: titled(options.titleTemplate, pub.title),
|
|
1901
2525
|
...description ? { description } : {},
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
2526
|
+
// Next replaces a parent's robots per key, so keep the inherited directives (a host's noindex) and add ours once.
|
|
2527
|
+
robots: composeRobots(inherited),
|
|
2528
|
+
alternates: await withTypes(
|
|
2529
|
+
{
|
|
2530
|
+
canonical,
|
|
2531
|
+
...alternates.length > 1 ? { languages: hreflangLanguages(alternates, default_locale, canonical, (a) => link(a.canonical_path, a.locale)) } : {}
|
|
2532
|
+
},
|
|
2533
|
+
options.markdownTwin ? `${canonical}.md` : void 0
|
|
2534
|
+
),
|
|
1906
2535
|
openGraph: {
|
|
1907
2536
|
type: "article",
|
|
1908
2537
|
title: pub.title,
|
|
1909
2538
|
...description ? { description } : {},
|
|
1910
2539
|
url: canonical,
|
|
1911
|
-
|
|
2540
|
+
...options.siteName ? { siteName: options.siteName } : {},
|
|
2541
|
+
locale: options.ogLocale?.(pub.locale) ?? pub.locale,
|
|
2542
|
+
...alternateLocale.length ? { alternateLocale } : {},
|
|
1912
2543
|
publishedTime: pub.published_at,
|
|
1913
2544
|
...modified ? { modifiedTime: modified } : {},
|
|
1914
|
-
...
|
|
1915
|
-
|
|
2545
|
+
...section ? { section } : {},
|
|
2546
|
+
...author ? { authors: [author] } : {},
|
|
2547
|
+
...image ? { images: [image] } : parentImages?.length ? { images: parentImages } : {}
|
|
2548
|
+
},
|
|
2549
|
+
// Next replaces a parent's `other` whole, so the inherited keys are carried over.
|
|
2550
|
+
...words ? { other: { ...parentMeta?.other, "twitter:label1": stringsFor(locale).readingTimeLabel, "twitter:data1": stringsFor(locale).readingTime.replace("{n}", String(readingMinutes(words))) } } : {},
|
|
2551
|
+
...image ? {
|
|
2552
|
+
twitter: {
|
|
2553
|
+
card: "summary_large_image",
|
|
2554
|
+
...twitter?.site ? { site: twitter.site } : {},
|
|
2555
|
+
...twitter?.creator ? { creator: twitter.creator } : {},
|
|
2556
|
+
title: pub.title,
|
|
2557
|
+
...description ? { description } : {},
|
|
2558
|
+
images: [image]
|
|
2559
|
+
}
|
|
2560
|
+
} : {}
|
|
1916
2561
|
};
|
|
1917
2562
|
} catch (error) {
|
|
1918
2563
|
if (isRejectedRequest(error)) return {};
|
|
@@ -1922,7 +2567,7 @@ function hyleMetadata(options) {
|
|
|
1922
2567
|
}
|
|
1923
2568
|
|
|
1924
2569
|
// src/next/feed.ts
|
|
1925
|
-
var
|
|
2570
|
+
var import_navigation4 = require("next/navigation");
|
|
1926
2571
|
var xml = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
1927
2572
|
var tag = (name, value) => `<${name}>${xml(value)}</${name}>`;
|
|
1928
2573
|
var response = (body, status, headers) => new Response(body, { status, ...headers ? { headers } : {} });
|
|
@@ -1957,7 +2602,7 @@ async function hyleFeed(options) {
|
|
|
1957
2602
|
{ "content-type": "application/rss+xml; charset=utf-8" }
|
|
1958
2603
|
);
|
|
1959
2604
|
} catch (error) {
|
|
1960
|
-
(0,
|
|
2605
|
+
(0, import_navigation4.unstable_rethrow)(error);
|
|
1961
2606
|
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
1962
2607
|
return response(null, 503);
|
|
1963
2608
|
}
|
|
@@ -1965,12 +2610,12 @@ async function hyleFeed(options) {
|
|
|
1965
2610
|
|
|
1966
2611
|
// src/next/revalidate.ts
|
|
1967
2612
|
var import_cache = require("next/cache");
|
|
1968
|
-
var
|
|
2613
|
+
var isSwitchedOff2 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
1969
2614
|
function createRevalidateRoute(options) {
|
|
1970
2615
|
let cached;
|
|
1971
2616
|
return {
|
|
1972
2617
|
async POST(req) {
|
|
1973
|
-
if (
|
|
2618
|
+
if (isSwitchedOff2((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return new Response(null, { status: 404 });
|
|
1974
2619
|
const workspaceId = options.workspaceId?.trim();
|
|
1975
2620
|
const secrets = options.secrets.map((s) => s?.trim()).filter((s) => Boolean(s));
|
|
1976
2621
|
if (!workspaceId && secrets.length === 0) return new Response(null, { status: 404 });
|
|
@@ -1985,15 +2630,21 @@ function createRevalidateRoute(options) {
|
|
|
1985
2630
|
}
|
|
1986
2631
|
|
|
1987
2632
|
// src/next/root.ts
|
|
1988
|
-
var
|
|
2633
|
+
var import_navigation5 = require("next/navigation");
|
|
1989
2634
|
|
|
1990
2635
|
// src/next/mount-match.ts
|
|
1991
2636
|
function activeMounts(mounts) {
|
|
1992
2637
|
const out = [];
|
|
1993
|
-
for (const { prefix, default_section } of mounts) {
|
|
2638
|
+
for (const { prefix, default_section, name, locales } of mounts) {
|
|
1994
2639
|
try {
|
|
1995
2640
|
const normalized = normalizeBasePath(prefix);
|
|
1996
|
-
out.push({
|
|
2641
|
+
out.push({
|
|
2642
|
+
prefix: normalized,
|
|
2643
|
+
defaultSection: default_section,
|
|
2644
|
+
depth: normalized === "" ? 0 : normalized.split("/").length - 1,
|
|
2645
|
+
...name ? { name } : {},
|
|
2646
|
+
...locales ? { locales } : {}
|
|
2647
|
+
});
|
|
1997
2648
|
} catch (error) {
|
|
1998
2649
|
console.error(`hyle: ignoring a mount with an invalid prefix (${error instanceof Error ? error.name : "Error"})`);
|
|
1999
2650
|
}
|
|
@@ -2007,8 +2658,8 @@ function isReserved(path, reserved) {
|
|
|
2007
2658
|
|
|
2008
2659
|
// src/next/root.ts
|
|
2009
2660
|
var MOUNTS_MAX_STALE_MS = 15 * 60 * 1e3;
|
|
2010
|
-
var
|
|
2011
|
-
var NONE = { mounts: [], reserved: [] };
|
|
2661
|
+
var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
2662
|
+
var NONE = { mounts: [], reserved: [], defaultLocale: "" };
|
|
2012
2663
|
var lastKnownGood = /* @__PURE__ */ new Map();
|
|
2013
2664
|
function mountsLoader(config) {
|
|
2014
2665
|
if (!config.workspaceId) throw new TypeError("hyleRootPage: `workspaceId` is required for the fetch cache");
|
|
@@ -2022,7 +2673,7 @@ function mountsLoader(config) {
|
|
|
2022
2673
|
lastKnownGood.delete(key);
|
|
2023
2674
|
return NONE;
|
|
2024
2675
|
}
|
|
2025
|
-
const loaded = { mounts: activeMounts(result.mounts), reserved: result.reserved };
|
|
2676
|
+
const loaded = { mounts: activeMounts(result.mounts), reserved: result.reserved, defaultLocale: result.default_locale };
|
|
2026
2677
|
lastKnownGood.set(key, { loaded, at: Date.now() });
|
|
2027
2678
|
return loaded;
|
|
2028
2679
|
} catch (error) {
|
|
@@ -2048,488 +2699,278 @@ function setup(options) {
|
|
|
2048
2699
|
if (configs.some((c) => (c.param ?? "hyle") !== param)) throw new TypeError("hyleRootPage: every config must use the same `param`");
|
|
2049
2700
|
return { configs, param, loaders: configs.map(mountsLoader) };
|
|
2050
2701
|
}
|
|
2051
|
-
|
|
2702
|
+
var sectionsOf = (config, mount) => [
|
|
2703
|
+
...config.sections ?? [],
|
|
2704
|
+
...SECTION_SLUG.test(mount.defaultSection) ? [mount.defaultSection] : []
|
|
2705
|
+
];
|
|
2706
|
+
function mountOptionsOf(config, mount) {
|
|
2707
|
+
const { mountOptions, ...rest } = config;
|
|
2708
|
+
return { ...rest, ...mountOptions?.[mount.prefix === "" ? "/" : mount.prefix], basePath: mount.prefix, sections: sectionsOf(config, mount) };
|
|
2709
|
+
}
|
|
2710
|
+
function rootMounts(options) {
|
|
2052
2711
|
const { configs, param, loaders } = setup(options);
|
|
2712
|
+
return {
|
|
2713
|
+
param,
|
|
2714
|
+
async locate(path) {
|
|
2715
|
+
const loaded = await Promise.all(loaders.map((load) => load()));
|
|
2716
|
+
let best;
|
|
2717
|
+
loaded.forEach(({ mounts, reserved }, index2) => {
|
|
2718
|
+
if (isReserved(path, reserved)) return;
|
|
2719
|
+
for (const mount2 of mounts) if (prefixMatches(mount2.prefix, path) && (!best || mount2.depth > best.mount.depth)) best = { index: index2, mount: mount2 };
|
|
2720
|
+
});
|
|
2721
|
+
if (!best) return void 0;
|
|
2722
|
+
const { index, mount } = best;
|
|
2723
|
+
return { options: mountOptionsOf(configs[index], mount), mount, index };
|
|
2724
|
+
},
|
|
2725
|
+
async all() {
|
|
2726
|
+
const out = [];
|
|
2727
|
+
for (const [index, load] of loaders.entries()) {
|
|
2728
|
+
const { mounts, defaultLocale } = await load();
|
|
2729
|
+
for (const mount of mounts) out.push({ options: mountOptionsOf(configs[index], mount), mount, index, defaultLocale });
|
|
2730
|
+
}
|
|
2731
|
+
return out;
|
|
2732
|
+
}
|
|
2733
|
+
};
|
|
2734
|
+
}
|
|
2735
|
+
function createRouter(options, make) {
|
|
2736
|
+
const mounts = rootMounts(options);
|
|
2053
2737
|
const handlers = /* @__PURE__ */ new Map();
|
|
2054
2738
|
return async function route(params) {
|
|
2055
|
-
const raw = params[param];
|
|
2739
|
+
const raw = params[mounts.param];
|
|
2056
2740
|
const segments = typeof raw === "string" ? [raw] : raw;
|
|
2057
2741
|
const path = sitePathFrom("", segments);
|
|
2058
2742
|
if (path === void 0 || path === "/" || !segments) return void 0;
|
|
2059
|
-
const
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
if (isReserved(path, reserved)) return;
|
|
2063
|
-
for (const mount2 of mounts) if (prefixMatches(mount2.prefix, path) && (!best || mount2.depth > best.mount.depth)) best = { index: index2, mount: mount2 };
|
|
2064
|
-
});
|
|
2065
|
-
if (!best) return void 0;
|
|
2066
|
-
const { index, mount } = best;
|
|
2067
|
-
const config = configs[index];
|
|
2743
|
+
const hit = await mounts.locate(path);
|
|
2744
|
+
if (!hit) return void 0;
|
|
2745
|
+
const { mount, index } = hit;
|
|
2068
2746
|
const id = `${index}|${mount.prefix}|${mount.defaultSection}`;
|
|
2069
2747
|
let handler = handlers.get(id);
|
|
2070
2748
|
if (!handler) {
|
|
2071
|
-
|
|
2072
|
-
handler = make({ ...config, basePath: mount.prefix, sections });
|
|
2749
|
+
handler = make(hit.options);
|
|
2073
2750
|
handlers.set(id, handler);
|
|
2074
2751
|
}
|
|
2075
|
-
return { handler, params: { ...params, [param]: segments.slice(mount.depth) } };
|
|
2752
|
+
return { handler, params: { ...params, [mounts.param]: segments.slice(mount.depth) } };
|
|
2076
2753
|
};
|
|
2077
2754
|
}
|
|
2078
2755
|
function hyleRootPage(options) {
|
|
2079
2756
|
const route = createRouter(options, hylePage);
|
|
2080
2757
|
return async function HyleRootPage({ params, searchParams }) {
|
|
2081
2758
|
const hit = await route(await params ?? {});
|
|
2082
|
-
if (!hit) (0,
|
|
2083
|
-
return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
|
|
2084
|
-
};
|
|
2085
|
-
}
|
|
2086
|
-
function hyleRootMetadata(options) {
|
|
2087
|
-
const route = createRouter(options, hyleMetadata);
|
|
2088
|
-
return async function generateMetadata({ params }) {
|
|
2089
|
-
const hit = await route(await params ?? {});
|
|
2090
|
-
return hit ? hit.handler({ params: Promise.resolve(hit.params) }) : {};
|
|
2091
|
-
};
|
|
2092
|
-
}
|
|
2093
|
-
async function hyleRootSitemap(options, sitemap) {
|
|
2094
|
-
const { configs, loaders } = setup(options);
|
|
2095
|
-
const entries = /* @__PURE__ */ new Map();
|
|
2096
|
-
for (const [index, load] of loaders.entries()) {
|
|
2097
|
-
const config = configs[index];
|
|
2098
|
-
for (const mount of (await load()).mounts) {
|
|
2099
|
-
const sections = [...config.sections ?? [], ...SECTION_SLUG2.test(mount.defaultSection) ? [mount.defaultSection] : []];
|
|
2100
|
-
for (const entry of await hyleSitemap({ ...config, basePath: mount.prefix, sections, ...sitemap })) entries.set(entry.url, entry);
|
|
2101
|
-
}
|
|
2102
|
-
}
|
|
2103
|
-
return [...entries.values()];
|
|
2104
|
-
}
|
|
2105
|
-
|
|
2106
|
-
// src/next/asset.ts
|
|
2107
|
-
var DEFAULT_MAX_BYTES = 16 * 1024 * 1024;
|
|
2108
|
-
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
2109
|
-
var CACHE_CONTROL = "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400";
|
|
2110
|
-
var PARTIAL_CACHE_CONTROL = "no-store";
|
|
2111
|
-
var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
|
|
2112
|
-
var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
|
|
2113
|
-
var isSwitchedOff2 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
2114
|
-
function capped(body, max) {
|
|
2115
|
-
let seen = 0;
|
|
2116
|
-
return body.pipeThrough(
|
|
2117
|
-
new TransformStream({
|
|
2118
|
-
transform(chunk, controller) {
|
|
2119
|
-
seen += chunk.byteLength;
|
|
2120
|
-
if (seen > max) return controller.error(new Error("asset too large"));
|
|
2121
|
-
controller.enqueue(chunk);
|
|
2122
|
-
}
|
|
2123
|
-
})
|
|
2124
|
-
);
|
|
2125
|
-
}
|
|
2126
|
-
function createAssetRoute(options) {
|
|
2127
|
-
let client;
|
|
2128
|
-
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
2129
|
-
async function serve(req, ctx2, head) {
|
|
2130
|
-
if (isSwitchedOff2((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
|
|
2131
|
-
const file = (await ctx2.params).file;
|
|
2132
|
-
if (typeof file !== "string" || !ASSET_FILE.test(file)) return empty(404);
|
|
2133
|
-
try {
|
|
2134
|
-
client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
|
|
2135
|
-
} catch {
|
|
2136
|
-
return empty(404);
|
|
2137
|
-
}
|
|
2138
|
-
let upstream;
|
|
2139
|
-
try {
|
|
2140
|
-
upstream = await client.asset(file, {
|
|
2141
|
-
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS2,
|
|
2142
|
-
headers: { range: req.headers.get("range"), "if-range": req.headers.get("if-range"), "if-none-match": req.headers.get("if-none-match") }
|
|
2143
|
-
});
|
|
2144
|
-
} catch {
|
|
2145
|
-
return empty(502);
|
|
2146
|
-
}
|
|
2147
|
-
const drop = () => void upstream.body?.cancel().catch(() => {
|
|
2148
|
-
});
|
|
2149
|
-
const etag = upstream.headers.get("etag");
|
|
2150
|
-
if (upstream.status === 304) {
|
|
2151
|
-
drop();
|
|
2152
|
-
return new Response(null, { status: 304, headers: { "Cache-Control": CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS, ...etag ? { ETag: etag } : {} } });
|
|
2153
|
-
}
|
|
2154
|
-
if (upstream.status === 404 || upstream.status === 416) {
|
|
2155
|
-
drop();
|
|
2156
|
-
const range = upstream.status === 416 ? upstream.headers.get("content-range") : null;
|
|
2157
|
-
return empty(upstream.status, range ? { "Content-Range": range } : {});
|
|
2158
|
-
}
|
|
2159
|
-
const type = upstream.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase();
|
|
2160
|
-
const length = Number(upstream.headers.get("content-length"));
|
|
2161
|
-
const expectedStatus = upstream.status === 200 || upstream.status === 206;
|
|
2162
|
-
if (!expectedStatus || !upstream.body || !type || !ASSET_CONTENT_TYPES.has(type) || Number.isFinite(length) && length > maxBytes) {
|
|
2163
|
-
drop();
|
|
2164
|
-
return empty(502);
|
|
2165
|
-
}
|
|
2166
|
-
const headers = new Headers({ "Content-Type": type, "Accept-Ranges": "bytes", "Cache-Control": upstream.status === 206 ? PARTIAL_CACHE_CONTROL : CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS });
|
|
2167
|
-
if (etag) headers.set("ETag", etag);
|
|
2168
|
-
const contentRange = upstream.headers.get("content-range");
|
|
2169
|
-
if (upstream.status === 206 && contentRange) headers.set("Content-Range", contentRange);
|
|
2170
|
-
if (!upstream.headers.get("content-encoding") && upstream.headers.get("content-length")) headers.set("Content-Length", String(length));
|
|
2171
|
-
if (head) {
|
|
2172
|
-
drop();
|
|
2173
|
-
return new Response(null, { status: upstream.status, headers });
|
|
2174
|
-
}
|
|
2175
|
-
return new Response(capped(upstream.body, maxBytes), { status: upstream.status, headers });
|
|
2176
|
-
}
|
|
2177
|
-
return { GET: (req, ctx2) => serve(req, ctx2, false), HEAD: (req, ctx2) => serve(req, ctx2, true) };
|
|
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;
|
|
2759
|
+
if (!hit) (0, import_navigation5.notFound)();
|
|
2760
|
+
return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
|
|
2340
2761
|
};
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
return {
|
|
2762
|
+
}
|
|
2763
|
+
function hyleRootMetadata(options) {
|
|
2764
|
+
const route = createRouter(options, hyleMetadata);
|
|
2765
|
+
return async function generateMetadata({ params, searchParams }, parent) {
|
|
2766
|
+
const hit = await route(await params ?? {});
|
|
2767
|
+
return hit ? hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} }, parent) : {};
|
|
2768
|
+
};
|
|
2769
|
+
}
|
|
2770
|
+
async function hyleRootSitemap(options, sitemap) {
|
|
2771
|
+
const entries = /* @__PURE__ */ new Map();
|
|
2772
|
+
for (const { options: mountOptions, mount, defaultLocale } of await rootMounts(options).all()) {
|
|
2773
|
+
for (const locale of mount.locales ?? [defaultLocale]) {
|
|
2774
|
+
for (const entry of await hyleSitemap({ ...mountOptions, ...sitemap, locale, defaultLocale })) entries.set(entry.url, entry);
|
|
2775
|
+
}
|
|
2347
2776
|
}
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2777
|
+
return [...entries.values()];
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2780
|
+
// src/next/markdown.ts
|
|
2781
|
+
var MD_ROUTE_PREFIX = "/api/hyle/md";
|
|
2782
|
+
function markdownRewritePath(pathname) {
|
|
2783
|
+
if (!pathname.startsWith("/") || !pathname.endsWith(".md") || pathname.endsWith("/.md") || pathname.startsWith("/api/")) return void 0;
|
|
2784
|
+
return MD_ROUTE_PREFIX + pathname.slice(0, -3);
|
|
2785
|
+
}
|
|
2786
|
+
var reply = (body, status, headers = {}) => (
|
|
2787
|
+
// noindex on every answer: the .md twin must never compete with the page it mirrors.
|
|
2788
|
+
new Response(body, { status, headers: { "X-Robots-Tag": "noindex", ...headers } })
|
|
2789
|
+
);
|
|
2790
|
+
function createMarkdownRoute(options) {
|
|
2791
|
+
const mounts = rootMounts(options);
|
|
2792
|
+
return {
|
|
2793
|
+
async GET(_req, ctx2) {
|
|
2794
|
+
const params = await ctx2.params ?? {};
|
|
2795
|
+
const segments = params.path;
|
|
2796
|
+
const path = sitePathFrom("", typeof segments === "string" ? [segments] : segments);
|
|
2797
|
+
if (path === void 0 || path === "/") return reply(null, 404);
|
|
2798
|
+
try {
|
|
2799
|
+
const hit = await mounts.locate(path);
|
|
2800
|
+
if (!hit) return reply(null, 404);
|
|
2801
|
+
const { locale, toHref } = routeContext({ ...hit.options, basePath: "", param: "path" }, params);
|
|
2802
|
+
const result = await resolverFor(hit.options)(path, locale, void 0, void 0, void 0, "md");
|
|
2803
|
+
if (result.kind === "article" && result.content.format === "md") {
|
|
2804
|
+
const markdown = result.content.markdown.replaceAll("](/assets/", `](${ASSET_ROUTE_PREFIX}/`);
|
|
2805
|
+
return reply(markdown, 200, { "Content-Type": "text/markdown; charset=utf-8" });
|
|
2806
|
+
}
|
|
2807
|
+
if (result.kind === "redirect") {
|
|
2808
|
+
const to = safeRedirectTarget(result.to);
|
|
2809
|
+
const target = to === void 0 ? void 0 : safeRedirectTarget(toHref(to));
|
|
2810
|
+
if (target === void 0) return reply(null, 502);
|
|
2811
|
+
return target === toHref(path) ? reply(null, 404) : reply(null, result.status === 301 ? 308 : 307, { Location: `${target}.md` });
|
|
2812
|
+
}
|
|
2813
|
+
return reply(null, 404);
|
|
2814
|
+
} catch (error) {
|
|
2815
|
+
if (isRejectedRequest(error)) return reply(null, 404);
|
|
2816
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2817
|
+
return reply(null, 502);
|
|
2818
|
+
}
|
|
2356
2819
|
}
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2820
|
+
};
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
// src/next/llms.ts
|
|
2824
|
+
var import_navigation6 = require("next/navigation");
|
|
2825
|
+
var oneLine = (text) => text.replace(/\s+/g, " ").trim();
|
|
2826
|
+
var linkTarget = (url) => url.replace(/[()]/g, (c) => c === "(" ? "%28" : "%29");
|
|
2827
|
+
function createLlmsTxtRoute(options, llms) {
|
|
2828
|
+
const origin = bareOrigin(llms.origin);
|
|
2829
|
+
if (!origin) throw new TypeError("createLlmsTxtRoute: `origin` must be a bare https origin such as https://example.com");
|
|
2830
|
+
const mounts = rootMounts(options);
|
|
2831
|
+
return {
|
|
2832
|
+
async GET() {
|
|
2833
|
+
try {
|
|
2834
|
+
const lines = [`# ${oneLine(llms.title ?? new URL(origin).host)}`, ...llms.description ? ["", `> ${oneLine(llms.description)}`] : []];
|
|
2835
|
+
for (const { options: mountOptions, mount, defaultLocale } of await mounts.all()) {
|
|
2836
|
+
if (mount.locales && !mount.locales.includes(defaultLocale)) continue;
|
|
2837
|
+
const { basePath, toHref } = routeContext({ ...mountOptions, locale: () => defaultLocale }, {});
|
|
2838
|
+
const resolve = resolverFor(mountOptions);
|
|
2839
|
+
const client = { resolve: ({ path, locale, limit, cursor }) => resolve(path, locale, limit, cursor) };
|
|
2840
|
+
const { paths } = await listPublicationPaths({ client, basePath, locale: defaultLocale });
|
|
2841
|
+
lines.push("", `## ${oneLine(mount.name ?? mount.defaultSection)}`, "");
|
|
2842
|
+
for (const { path, title, description } of paths) {
|
|
2843
|
+
lines.push(`- [${oneLine(title).replace(/[[\]]/g, "")}](${linkTarget(absoluteUrl(origin, toHref(path)))}.md)${description ? `: ${oneLine(description)}` : ""}`);
|
|
2844
|
+
}
|
|
2369
2845
|
}
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2846
|
+
return new Response(`${lines.join("\n")}
|
|
2847
|
+
`, { headers: { "Content-Type": "text/plain; charset=utf-8" } });
|
|
2848
|
+
} catch (error) {
|
|
2849
|
+
(0, import_navigation6.unstable_rethrow)(error);
|
|
2850
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2851
|
+
return new Response(null, { status: 503 });
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
};
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
// src/next/og.tsx
|
|
2858
|
+
var import_og = require("next/og");
|
|
2859
|
+
|
|
2860
|
+
// src/next/asset.ts
|
|
2861
|
+
var DEFAULT_MAX_BYTES = 16 * 1024 * 1024;
|
|
2862
|
+
var DEFAULT_TIMEOUT_MS3 = 3e4;
|
|
2863
|
+
var CACHE_CONTROL = "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400";
|
|
2864
|
+
var PARTIAL_CACHE_CONTROL = "no-store";
|
|
2865
|
+
var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
|
|
2866
|
+
var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
|
|
2867
|
+
var isSwitchedOff3 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
2868
|
+
function capped(body, max) {
|
|
2869
|
+
let seen = 0;
|
|
2870
|
+
return body.pipeThrough(
|
|
2871
|
+
new TransformStream({
|
|
2872
|
+
transform(chunk, controller) {
|
|
2873
|
+
seen += chunk.byteLength;
|
|
2874
|
+
if (seen > max) return controller.error(new Error("asset too large"));
|
|
2875
|
+
controller.enqueue(chunk);
|
|
2876
|
+
}
|
|
2877
|
+
})
|
|
2878
|
+
);
|
|
2879
|
+
}
|
|
2880
|
+
function createAssetRoute(options) {
|
|
2881
|
+
let client;
|
|
2882
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
2883
|
+
async function serve(req, ctx2, head) {
|
|
2884
|
+
if (isSwitchedOff3((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
|
|
2885
|
+
const file = (await ctx2.params).file;
|
|
2886
|
+
if (typeof file !== "string" || !ASSET_FILE.test(file)) return empty(404);
|
|
2382
2887
|
try {
|
|
2383
|
-
|
|
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()) };
|
|
2888
|
+
client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
|
|
2387
2889
|
} catch {
|
|
2388
|
-
|
|
2890
|
+
return empty(404);
|
|
2389
2891
|
}
|
|
2390
|
-
|
|
2391
|
-
}
|
|
2392
|
-
async function reader(req, config) {
|
|
2892
|
+
let upstream;
|
|
2393
2893
|
try {
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
return { reader: found, assertion: sign2(), sign: sign2 };
|
|
2894
|
+
upstream = await client.asset(file, {
|
|
2895
|
+
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS3,
|
|
2896
|
+
headers: { range: req.headers.get("range"), "if-range": req.headers.get("if-range"), "if-none-match": req.headers.get("if-none-match") }
|
|
2897
|
+
});
|
|
2399
2898
|
} catch {
|
|
2400
|
-
return
|
|
2899
|
+
return empty(502);
|
|
2401
2900
|
}
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
const
|
|
2405
|
-
if (
|
|
2406
|
-
|
|
2407
|
-
|
|
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
|
-
}
|
|
2901
|
+
const drop = () => void upstream.body?.cancel().catch(() => {
|
|
2902
|
+
});
|
|
2903
|
+
const etag = upstream.headers.get("etag");
|
|
2904
|
+
if (upstream.status === 304) {
|
|
2905
|
+
drop();
|
|
2906
|
+
return new Response(null, { status: 304, headers: { "Cache-Control": CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS, ...etag ? { ETag: etag } : {} } });
|
|
2423
2907
|
}
|
|
2424
|
-
if (
|
|
2425
|
-
|
|
2426
|
-
|
|
2908
|
+
if (upstream.status === 404 || upstream.status === 416) {
|
|
2909
|
+
drop();
|
|
2910
|
+
const range = upstream.status === 416 ? upstream.headers.get("content-range") : null;
|
|
2911
|
+
return empty(upstream.status, range ? { "Content-Range": range } : {});
|
|
2427
2912
|
}
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
if (
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
assertion = who.assertion;
|
|
2913
|
+
const type = upstream.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase();
|
|
2914
|
+
const length = Number(upstream.headers.get("content-length"));
|
|
2915
|
+
const expectedStatus = upstream.status === 200 || upstream.status === 206;
|
|
2916
|
+
if (!expectedStatus || !upstream.body || !type || !ASSET_CONTENT_TYPES.has(type) || Number.isFinite(length) && length > maxBytes) {
|
|
2917
|
+
drop();
|
|
2918
|
+
return empty(502);
|
|
2435
2919
|
}
|
|
2436
|
-
const
|
|
2437
|
-
|
|
2438
|
-
const
|
|
2439
|
-
if (
|
|
2440
|
-
|
|
2441
|
-
if (
|
|
2442
|
-
|
|
2443
|
-
|
|
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");
|
|
2920
|
+
const headers = new Headers({ "Content-Type": type, "Accept-Ranges": "bytes", "Cache-Control": upstream.status === 206 ? PARTIAL_CACHE_CONTROL : CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS });
|
|
2921
|
+
if (etag) headers.set("ETag", etag);
|
|
2922
|
+
const contentRange = upstream.headers.get("content-range");
|
|
2923
|
+
if (upstream.status === 206 && contentRange) headers.set("Content-Range", contentRange);
|
|
2924
|
+
if (!upstream.headers.get("content-encoding") && upstream.headers.get("content-length")) headers.set("Content-Length", String(length));
|
|
2925
|
+
if (head) {
|
|
2926
|
+
drop();
|
|
2927
|
+
return new Response(null, { status: upstream.status, headers });
|
|
2466
2928
|
}
|
|
2929
|
+
return new Response(capped(upstream.body, maxBytes), { status: upstream.status, headers });
|
|
2467
2930
|
}
|
|
2468
|
-
return { GET:
|
|
2931
|
+
return { GET: (req, ctx2) => serve(req, ctx2, false), HEAD: (req, ctx2) => serve(req, ctx2, true) };
|
|
2469
2932
|
}
|
|
2470
2933
|
|
|
2471
|
-
// src/next/
|
|
2472
|
-
var
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
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;
|
|
2934
|
+
// src/next/og.tsx
|
|
2935
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2936
|
+
var SIZE = { width: 1200, height: 630 };
|
|
2937
|
+
var MAX_TITLE = 140;
|
|
2938
|
+
function createOgImageRoute(options) {
|
|
2493
2939
|
const resolve = resolverFor(options);
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
}
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2940
|
+
return {
|
|
2941
|
+
async GET(req, ctx2) {
|
|
2942
|
+
if (isSwitchedOff3(process.env.HYLE_CONTENT_ENABLED)) return new Response(null, { status: 404 });
|
|
2943
|
+
const segments = (await ctx2.params).path;
|
|
2944
|
+
const route = routeContext({ ...options, basePath: "", param: "path" }, { path: segments });
|
|
2945
|
+
if (!segments?.length || route.path === void 0) return new Response(null, { status: 404 });
|
|
2946
|
+
const path = route.path;
|
|
2947
|
+
const load = async (locale) => {
|
|
2948
|
+
const first = await resolve(path, locale);
|
|
2949
|
+
const target = first.kind === "redirect" ? safeRedirectTarget(first.to) : void 0;
|
|
2950
|
+
return target ? resolve(target, locale) : first;
|
|
2951
|
+
};
|
|
2952
|
+
let title;
|
|
2953
|
+
try {
|
|
2954
|
+
let result = await load();
|
|
2955
|
+
const wanted = new URL(req.url).searchParams.get("locale");
|
|
2956
|
+
if (result.kind === "article" && wanted && wanted !== result.publication.locale && result.alternates.some((a) => a.locale === wanted)) result = await load(wanted);
|
|
2957
|
+
if (result.kind !== "article") return new Response(null, { status: 404 });
|
|
2958
|
+
title = result.publication.title;
|
|
2959
|
+
} catch (error) {
|
|
2960
|
+
return new Response(null, { status: isRejectedRequest(error) ? 404 : 502 });
|
|
2961
|
+
}
|
|
2962
|
+
const chars = [...title];
|
|
2963
|
+
const shown = chars.length > MAX_TITLE ? `${chars.slice(0, MAX_TITLE - 1).join("")}\u2026` : title;
|
|
2964
|
+
return new import_og.ImageResponse(
|
|
2965
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { display: "flex", flexDirection: "column", justifyContent: "space-between", width: "100%", height: "100%", padding: 80, background: "#111827", color: "#ffffff" }, children: [
|
|
2966
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: { fontSize: 64, fontWeight: 700, lineHeight: 1.2 }, children: shown }),
|
|
2967
|
+
options.siteName ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: { fontSize: 32, color: "#9ca3af" }, children: options.siteName }) : null
|
|
2968
|
+
] }),
|
|
2969
|
+
// shortcut: @vercel/og fetches Google Fonts / emoji assets at render time for non-Latin titles and emoji (no switch to disable it), upgrade to a satori render with bundled fonts if a host needs zero egress.
|
|
2970
|
+
{ ...SIZE, headers: { "cache-control": "public, max-age=3600, s-maxage=31536000, immutable" } }
|
|
2971
|
+
);
|
|
2520
2972
|
}
|
|
2521
|
-
|
|
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 }) });
|
|
2973
|
+
};
|
|
2533
2974
|
}
|
|
2534
2975
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2535
2976
|
0 && (module.exports = {
|
|
@@ -2541,14 +2982,19 @@ async function HyleComments({ options, path, revalidate = 60, interactive }) {
|
|
|
2541
2982
|
MOUNTS_MAX_STALE_MS,
|
|
2542
2983
|
createAssetRoute,
|
|
2543
2984
|
createEngagementRoute,
|
|
2985
|
+
createLlmsTxtRoute,
|
|
2986
|
+
createMarkdownRoute,
|
|
2987
|
+
createOgImageRoute,
|
|
2544
2988
|
createRevalidateRoute,
|
|
2545
2989
|
fetchResolver,
|
|
2546
2990
|
hyleFeed,
|
|
2991
|
+
hyleFeedLink,
|
|
2547
2992
|
hyleMetadata,
|
|
2548
2993
|
hylePage,
|
|
2549
2994
|
hyleRootMetadata,
|
|
2550
2995
|
hyleRootPage,
|
|
2551
2996
|
hyleRootSitemap,
|
|
2552
2997
|
hyleSitemap,
|
|
2998
|
+
markdownRewritePath,
|
|
2553
2999
|
workspaceTags
|
|
2554
3000
|
});
|