@tdacorp/hyle-sdk 0.14.1 → 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 +20 -8
- package/dist/check-routes-bin.js +10 -8
- package/dist/{chunk-4V4VKB3O.js → chunk-DMK4XQLU.js} +470 -385
- 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-B76zRRPa.d.cts → embed-BmdwA2G9.d.cts} +9 -4
- package/dist/{embed-SqOBGI-E.d.ts → embed-DNTZ2UXv.d.ts} +9 -4
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- 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 +1330 -1118
- package/dist/next.d.cts +61 -11
- package/dist/next.d.ts +61 -11
- package/dist/next.js +922 -793
- package/dist/react.cjs +267 -184
- package/dist/react.d.cts +29 -6
- package/dist/react.d.ts +29 -6
- package/dist/react.js +1 -1
- package/dist/{resolve-DC2ccfwA.d.ts → resolve-Ae7UFjsQ.d.ts} +1 -1
- package/dist/{resolve-DKLVftk_.d.cts → resolve-euZ4-aC9.d.cts} +1 -1
- package/dist/styles.css +11 -22
- package/dist/{types-ByodIyEv.d.cts → types-Czt887Iv.d.cts} +19 -3
- package/dist/{types-ByodIyEv.d.ts → types-Czt887Iv.d.ts} +19 -3
- package/dist/use-cache.d.cts +2 -2
- package/dist/use-cache.d.ts +2 -2
- package/package.json +1 -1
package/dist/next.cjs
CHANGED
|
@@ -30,9 +30,11 @@ __export(next_exports, {
|
|
|
30
30
|
createEngagementRoute: () => createEngagementRoute,
|
|
31
31
|
createLlmsTxtRoute: () => createLlmsTxtRoute,
|
|
32
32
|
createMarkdownRoute: () => createMarkdownRoute,
|
|
33
|
+
createOgImageRoute: () => createOgImageRoute,
|
|
33
34
|
createRevalidateRoute: () => createRevalidateRoute,
|
|
34
35
|
fetchResolver: () => fetchResolver,
|
|
35
36
|
hyleFeed: () => hyleFeed,
|
|
37
|
+
hyleFeedLink: () => hyleFeedLink,
|
|
36
38
|
hyleMetadata: () => hyleMetadata,
|
|
37
39
|
hylePage: () => hylePage,
|
|
38
40
|
hyleRootMetadata: () => hyleRootMetadata,
|
|
@@ -45,7 +47,7 @@ __export(next_exports, {
|
|
|
45
47
|
module.exports = __toCommonJS(next_exports);
|
|
46
48
|
|
|
47
49
|
// src/next/page.tsx
|
|
48
|
-
var
|
|
50
|
+
var import_navigation3 = require("next/navigation");
|
|
49
51
|
|
|
50
52
|
// src/asset-path.ts
|
|
51
53
|
var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
|
|
@@ -475,9 +477,7 @@ function Icon({ name, className }) {
|
|
|
475
477
|
|
|
476
478
|
// src/react/content.tsx
|
|
477
479
|
var import_mermaid_diagram = require("./mermaid-diagram.cjs");
|
|
478
|
-
|
|
479
|
-
// src/react/mermaid-config.ts
|
|
480
|
-
var MAX_MERMAID_SOURCE = 2e4;
|
|
480
|
+
var import_mermaid_image = require("./mermaid-image.cjs");
|
|
481
481
|
|
|
482
482
|
// src/react/sanitize.ts
|
|
483
483
|
var HastLimitError = class extends Error {
|
|
@@ -489,7 +489,7 @@ var HastLimitError = class extends Error {
|
|
|
489
489
|
var MAX_NODES = 2e4;
|
|
490
490
|
var MAX_TEXT = 512 * 1024;
|
|
491
491
|
var MAX_DEPTH = 128;
|
|
492
|
-
var MAX_SRCDOC =
|
|
492
|
+
var MAX_SRCDOC = 1024 * 1024;
|
|
493
493
|
var DROP = /* @__PURE__ */ new Set(["script", "style", "template", "noscript"]);
|
|
494
494
|
var VOID = /* @__PURE__ */ new Set(["br", "hr", "img", "input", "path"]);
|
|
495
495
|
var isString = (v) => typeof v === "string";
|
|
@@ -506,6 +506,7 @@ var classTokens = (v) => {
|
|
|
506
506
|
};
|
|
507
507
|
var isClass = (v) => classTokens(v) !== void 0;
|
|
508
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);
|
|
509
510
|
var isLength = matches(/^[\d.]+(em|px|%)?$/);
|
|
510
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"]);
|
|
511
512
|
var STYLE_LENGTH = /^(-?\d+(?:\.\d+)?)(em|px|%)?$/;
|
|
@@ -542,10 +543,14 @@ var MERMAID_SRCDOC = new RegExp(
|
|
|
542
543
|
var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
|
|
543
544
|
var ENTITIES = { "<": "<", "&": "&", "<": "<", ">": ">", "&": "&", """: '"', "'": "'" };
|
|
544
545
|
function mermaidSource(srcDoc) {
|
|
545
|
-
|
|
546
|
-
|
|
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;
|
|
547
553
|
}
|
|
548
|
-
var MERMAID_FRAME_CSP = `default-src 'none'; script-src ${MERMAID_SCRIPT_URL} 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:`;
|
|
549
554
|
var heading = { id: isIdValue, className: isClass };
|
|
550
555
|
var ATTRS = new Map(
|
|
551
556
|
Object.entries({
|
|
@@ -570,7 +575,7 @@ var ATTRS = new Map(
|
|
|
570
575
|
h5: heading,
|
|
571
576
|
h6: heading,
|
|
572
577
|
a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, className: isClass },
|
|
573
|
-
img: { src: isSrc, alt: isString },
|
|
578
|
+
img: { src: isSrc, alt: isString, width: isPixels, height: isPixels },
|
|
574
579
|
table: {},
|
|
575
580
|
th: { scope: matches(/^(row|col|rowgroup|colgroup)$/), align: isAlign },
|
|
576
581
|
td: { align: isAlign },
|
|
@@ -584,7 +589,7 @@ var ATTRS = new Map(
|
|
|
584
589
|
video: { src: isSrc, controls: isScalar },
|
|
585
590
|
audio: { src: isSrc, controls: isScalar },
|
|
586
591
|
// hyle's sandboxed Mermaid frame (ADR 0001). The renderer emits `sandbox` as ["allow-scripts"]; it is normalized below.
|
|
587
|
-
iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc }
|
|
592
|
+
iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc, dataLight: isRenderRef, dataDark: isRenderRef }
|
|
588
593
|
})
|
|
589
594
|
);
|
|
590
595
|
var isObject = (v) => typeof v === "object" && v !== null;
|
|
@@ -958,11 +963,17 @@ var en = {
|
|
|
958
963
|
caution: "Caution",
|
|
959
964
|
diagram: "Diagram",
|
|
960
965
|
diagramError: "This diagram could not be rendered.",
|
|
966
|
+
diagramLoading: "Loading the diagram",
|
|
967
|
+
diagramSource: "Diagram source",
|
|
961
968
|
contentError: "This content cannot be displayed.",
|
|
962
969
|
fallbackTitle: "Not translated into {language} yet.",
|
|
963
970
|
fallbackBody: "You are reading the original.",
|
|
971
|
+
readingTime: "{n} min read",
|
|
972
|
+
readingTimeLabel: "Reading time",
|
|
964
973
|
older: "Older posts",
|
|
965
974
|
viewAll: "View all",
|
|
975
|
+
moreInSection: "More in this section",
|
|
976
|
+
subPages: "In this section",
|
|
966
977
|
readAtSource: "Read at source",
|
|
967
978
|
emptyTitle: "Nothing published here yet",
|
|
968
979
|
emptyBody: "Documents published to this section will appear here, newest first.",
|
|
@@ -1004,11 +1015,17 @@ var fr = {
|
|
|
1004
1015
|
caution: "Danger",
|
|
1005
1016
|
diagram: "Sch\xE9ma",
|
|
1006
1017
|
diagramError: "Ce sch\xE9ma n'a pas pu \xEAtre affich\xE9.",
|
|
1018
|
+
diagramLoading: "Chargement du sch\xE9ma",
|
|
1019
|
+
diagramSource: "Source du sch\xE9ma",
|
|
1007
1020
|
contentError: "Ce contenu ne peut pas \xEAtre affich\xE9.",
|
|
1008
1021
|
fallbackTitle: "Pas encore traduit en {language}.",
|
|
1009
1022
|
fallbackBody: "Vous lisez l'original.",
|
|
1023
|
+
readingTime: "{n} min de lecture",
|
|
1024
|
+
readingTimeLabel: "Temps de lecture",
|
|
1010
1025
|
older: "Articles plus anciens",
|
|
1011
1026
|
viewAll: "Tout voir",
|
|
1027
|
+
moreInSection: "Plus dans cette section",
|
|
1028
|
+
subPages: "Dans cette section",
|
|
1012
1029
|
readAtSource: "Lire \xE0 la source",
|
|
1013
1030
|
emptyTitle: "Rien n'est encore publi\xE9 ici",
|
|
1014
1031
|
emptyBody: "Les documents publi\xE9s dans cette section appara\xEEtront ici, du plus r\xE9cent au plus ancien.",
|
|
@@ -1050,11 +1067,17 @@ var es = {
|
|
|
1050
1067
|
caution: "Peligro",
|
|
1051
1068
|
diagram: "Diagrama",
|
|
1052
1069
|
diagramError: "No se pudo mostrar este diagrama.",
|
|
1070
|
+
diagramLoading: "Cargando el diagrama",
|
|
1071
|
+
diagramSource: "C\xF3digo del diagrama",
|
|
1053
1072
|
contentError: "No se puede mostrar este contenido.",
|
|
1054
1073
|
fallbackTitle: "A\xFAn no est\xE1 traducida al {language}.",
|
|
1055
1074
|
fallbackBody: "Est\xE1s leyendo el original.",
|
|
1075
|
+
readingTime: "{n} min de lectura",
|
|
1076
|
+
readingTimeLabel: "Tiempo de lectura",
|
|
1056
1077
|
older: "Entradas anteriores",
|
|
1057
1078
|
viewAll: "Ver todo",
|
|
1079
|
+
moreInSection: "M\xE1s en esta secci\xF3n",
|
|
1080
|
+
subPages: "En esta secci\xF3n",
|
|
1058
1081
|
readAtSource: "Leer en la fuente",
|
|
1059
1082
|
emptyTitle: "A\xFAn no hay nada publicado aqu\xED",
|
|
1060
1083
|
emptyBody: "Los documentos publicados en esta secci\xF3n aparecer\xE1n aqu\xED, del m\xE1s reciente al m\xE1s antiguo.",
|
|
@@ -1117,7 +1140,12 @@ function buildComponents(c, s) {
|
|
|
1117
1140
|
}
|
|
1118
1141
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { href: url, rel: "noopener noreferrer", ...rest, children });
|
|
1119
1142
|
};
|
|
1120
|
-
|
|
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
|
+
};
|
|
1121
1149
|
const Pre = ({ children, ...rest }) => {
|
|
1122
1150
|
const code = import_react.Children.toArray(children).find(import_react.isValidElement);
|
|
1123
1151
|
const language = /(?:^|\s)language-([\w-]+)/.exec(code?.props.className ?? "")?.[1];
|
|
@@ -1141,12 +1169,18 @@ function buildComponents(c, s) {
|
|
|
1141
1169
|
] })
|
|
1142
1170
|
] });
|
|
1143
1171
|
};
|
|
1144
|
-
const Frame = (
|
|
1172
|
+
const Frame = (props) => {
|
|
1173
|
+
const { srcDoc } = props;
|
|
1145
1174
|
if (typeof srcDoc !== "string") return null;
|
|
1146
1175
|
const source = mermaidSource(srcDoc);
|
|
1147
1176
|
if (c.Mermaid) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(c.Mermaid, { srcDoc, source, title: s.diagram });
|
|
1148
|
-
if (source
|
|
1149
|
-
|
|
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 });
|
|
1150
1184
|
};
|
|
1151
1185
|
const Heading = (level) => function HyleHeading({ id, children, ...rest }) {
|
|
1152
1186
|
const Tag = `h${level}`;
|
|
@@ -1191,292 +1225,6 @@ var import_mermaid_diagram2 = require("./mermaid-diagram.cjs");
|
|
|
1191
1225
|
// src/react/pages.tsx
|
|
1192
1226
|
var import_comments = require("./comments.cjs");
|
|
1193
1227
|
|
|
1194
|
-
// src/react/seo.ts
|
|
1195
|
-
var BARE_HTTPS_ORIGIN = /^https:\/\/[^/]+$/;
|
|
1196
|
-
var bareOrigin = (origin) => origin && BARE_HTTPS_ORIGIN.test(origin) ? origin : void 0;
|
|
1197
|
-
var absoluteUrl = (origin, href) => origin + encodeURI(href);
|
|
1198
|
-
var modifiedAt = (pub) => pub.updated_at && Date.parse(pub.updated_at) > Date.parse(pub.published_at) ? pub.updated_at : void 0;
|
|
1199
|
-
function articleAuthor(article, jsonLd) {
|
|
1200
|
-
const given = jsonLd?.author?.(article);
|
|
1201
|
-
if (given && typeof given.name === "string" && given.name) return given;
|
|
1202
|
-
const fromFrontmatter = article.frontmatter.author;
|
|
1203
|
-
return typeof fromFrontmatter === "string" && fromFrontmatter ? { name: fromFrontmatter } : void 0;
|
|
1204
|
-
}
|
|
1205
|
-
var UNSAFE_URL = /[\u0000- \u007f\\]/;
|
|
1206
|
-
var positive = (n) => typeof n === "number" && Number.isInteger(n) && n > 0 ? n : void 0;
|
|
1207
|
-
function validOgImage(image, origin) {
|
|
1208
|
-
if (!image || typeof image.url !== "string" || UNSAFE_URL.test(image.url)) return void 0;
|
|
1209
|
-
const relative = image.url.startsWith("/") && !image.url.startsWith("//");
|
|
1210
|
-
const url = relative ? origin ? origin + image.url : void 0 : image.url;
|
|
1211
|
-
if (!url) return void 0;
|
|
1212
|
-
try {
|
|
1213
|
-
const parsed = new URL(url);
|
|
1214
|
-
if (parsed.protocol !== "https:" || relative && parsed.origin !== origin) return void 0;
|
|
1215
|
-
} catch {
|
|
1216
|
-
return void 0;
|
|
1217
|
-
}
|
|
1218
|
-
const width = positive(image.width);
|
|
1219
|
-
const height = positive(image.height);
|
|
1220
|
-
const type = typeof image.type === "string" && image.type ? image.type : "image/png";
|
|
1221
|
-
return { url, type, ...width ? { width } : {}, ...height ? { height } : {}, ...typeof image.alt === "string" && image.alt ? { alt: image.alt } : {} };
|
|
1222
|
-
}
|
|
1223
|
-
function hreflangLanguages(members, defaultLocale, selfUrl, url) {
|
|
1224
|
-
const defaultMember = members.find((m) => m.locale === defaultLocale);
|
|
1225
|
-
return { ...Object.fromEntries(members.map((m) => [m.locale, url(m)])), "x-default": defaultMember ? url(defaultMember) : selfUrl };
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
// src/react/jsonld.ts
|
|
1229
|
-
var script = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
|
|
1230
|
-
function articleJsonLd({ article, origin, href, jsonLd, imageUrl }) {
|
|
1231
|
-
const { publication: pub } = article;
|
|
1232
|
-
const url = (path) => absoluteUrl(origin, href(path, pub.locale));
|
|
1233
|
-
const canonical = url(pub.canonical_path);
|
|
1234
|
-
const id = (fragment) => ({ "@id": `${canonical}#${fragment}` });
|
|
1235
|
-
const full = jsonLd !== void 0;
|
|
1236
|
-
const author = articleAuthor(article, jsonLd);
|
|
1237
|
-
const publisher = jsonLd?.publisher;
|
|
1238
|
-
const website = jsonLd?.website?.(pub.locale);
|
|
1239
|
-
const modified = modifiedAt(pub);
|
|
1240
|
-
const root = jsonLd?.breadcrumbRoot;
|
|
1241
|
-
const graph = [
|
|
1242
|
-
...full ? [{
|
|
1243
|
-
"@type": "WebPage",
|
|
1244
|
-
...id("webpage"),
|
|
1245
|
-
url: canonical,
|
|
1246
|
-
name: pub.title,
|
|
1247
|
-
...pub.description ? { description: pub.description } : {},
|
|
1248
|
-
inLanguage: pub.locale,
|
|
1249
|
-
...website ? { isPartOf: { "@id": website.id } } : {},
|
|
1250
|
-
...publisher ? { publisher: { "@id": publisher.id } } : {},
|
|
1251
|
-
breadcrumb: id("breadcrumb"),
|
|
1252
|
-
mainEntity: id("article")
|
|
1253
|
-
}] : [],
|
|
1254
|
-
{
|
|
1255
|
-
"@type": "BlogPosting",
|
|
1256
|
-
...id("article"),
|
|
1257
|
-
headline: pub.title,
|
|
1258
|
-
...pub.description ? { description: pub.description } : {},
|
|
1259
|
-
datePublished: pub.published_at.slice(0, 10),
|
|
1260
|
-
...modified ? { dateModified: modified } : {},
|
|
1261
|
-
url: canonical,
|
|
1262
|
-
mainEntityOfPage: full ? id("webpage") : canonical,
|
|
1263
|
-
...author ? { author: author.id ? { "@id": author.id } : { "@type": "Person", name: author.name, ...author.url ? { url: author.url } : {} } } : {},
|
|
1264
|
-
...publisher ? { publisher: { "@id": publisher.id } } : {},
|
|
1265
|
-
inLanguage: pub.locale,
|
|
1266
|
-
...imageUrl ? { image: [imageUrl] } : {}
|
|
1267
|
-
},
|
|
1268
|
-
{
|
|
1269
|
-
"@type": "BreadcrumbList",
|
|
1270
|
-
...id("breadcrumb"),
|
|
1271
|
-
itemListElement: [...root ? [{ name: root.name, item: absoluteUrl(origin, href("/", pub.locale).replace(/(.)\/$/, "$1").replace(/^\/$/, "")) }] : [], ...article.breadcrumbs.map((b) => ({ name: b.title, item: url(b.canonical_path) }))].map((b, i) => ({ "@type": "ListItem", position: i + 1, ...b }))
|
|
1272
|
-
}
|
|
1273
|
-
];
|
|
1274
|
-
return script({ "@context": "https://schema.org", "@graph": graph });
|
|
1275
|
-
}
|
|
1276
|
-
function listJsonLd({ list, origin, href, path, locale, description }) {
|
|
1277
|
-
return script({
|
|
1278
|
-
"@context": "https://schema.org",
|
|
1279
|
-
"@type": "CollectionPage",
|
|
1280
|
-
url: absoluteUrl(origin, href(path)),
|
|
1281
|
-
name: list.section.title,
|
|
1282
|
-
...description ? { description } : {},
|
|
1283
|
-
inLanguage: locale,
|
|
1284
|
-
mainEntity: {
|
|
1285
|
-
"@type": "ItemList",
|
|
1286
|
-
itemListElement: list.items.map((item, i) => ({ "@type": "ListItem", position: i + 1, url: absoluteUrl(origin, href(item.canonical_path)), name: item.title }))
|
|
1287
|
-
}
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
// src/react/pages.tsx
|
|
1292
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1293
|
-
function Slot({ name, slots, tag: Tag = "div", className }) {
|
|
1294
|
-
const fill = slots?.[name];
|
|
1295
|
-
return fill ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Tag, { "data-slot": name, className, children: fill }) : null;
|
|
1296
|
-
}
|
|
1297
|
-
function Shell({ children }) {
|
|
1298
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "hyle", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "hyle-page", children }) });
|
|
1299
|
-
}
|
|
1300
|
-
function ctx(p, fallbackLocale) {
|
|
1301
|
-
const locale = p.locale ?? fallbackLocale;
|
|
1302
|
-
return { s: stringsFor(locale), locale, href: (path, linkLocale) => p.toHref ? p.toHref(path, linkLocale ?? locale) : path, Link: p.components?.Link ?? "a" };
|
|
1303
|
-
}
|
|
1304
|
-
function Pager({ prev, next, c }) {
|
|
1305
|
-
if (!prev && !next) return null;
|
|
1306
|
-
const { Link, s } = c;
|
|
1307
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("nav", { className: "hyle-pager", "aria-label": s.pager, children: [
|
|
1308
|
-
prev ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { href: c.href(prev.canonical_path), rel: "prev", children: [
|
|
1309
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dir", children: [
|
|
1310
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev-left" }),
|
|
1311
|
-
s.prev
|
|
1312
|
-
] }),
|
|
1313
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "ttl", children: prev.title })
|
|
1314
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "none", "aria-hidden": "true" }),
|
|
1315
|
-
next ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { href: c.href(next.canonical_path), rel: "next", className: "next", children: [
|
|
1316
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dir", children: [
|
|
1317
|
-
s.next,
|
|
1318
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev" })
|
|
1319
|
-
] }),
|
|
1320
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "ttl", children: next.title })
|
|
1321
|
-
] }) : null
|
|
1322
|
-
] });
|
|
1323
|
-
}
|
|
1324
|
-
function TocList({ toc }) {
|
|
1325
|
-
const groups = [];
|
|
1326
|
-
for (const entry of toc) {
|
|
1327
|
-
const last = groups.at(-1);
|
|
1328
|
-
if (entry.depth === 3 && last) last.subs.push(entry);
|
|
1329
|
-
else groups.push({ entry, subs: [] });
|
|
1330
|
-
}
|
|
1331
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { children: groups.map(({ entry, subs }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { children: [
|
|
1332
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: `#${scopeId(entry.id)}`, children: entry.text }),
|
|
1333
|
-
subs.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { children: subs.map((sub) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: `#${scopeId(sub.id)}`, children: sub.text }) }, sub.id)) }) : null
|
|
1334
|
-
] }, entry.id)) });
|
|
1335
|
-
}
|
|
1336
|
-
function Toc({ toc, c, aside }) {
|
|
1337
|
-
const entries = toc.filter((t) => t.depth === 2 || t.depth === 3);
|
|
1338
|
-
if (entries.length === 0 && !aside) return { narrow: null, wide: null };
|
|
1339
|
-
const { s } = c;
|
|
1340
|
-
return {
|
|
1341
|
-
narrow: entries.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("details", { className: "hyle-toc-m", children: [
|
|
1342
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("summary", { children: [
|
|
1343
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "file" }),
|
|
1344
|
-
s.toc,
|
|
1345
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev-down", className: "hyle-chev" })
|
|
1346
|
-
] }),
|
|
1347
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("nav", { className: "hyle-toc-list", "aria-label": s.toc, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TocList, { toc: entries }) })
|
|
1348
|
-
] }),
|
|
1349
|
-
wide: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("aside", { className: "hyle-toc-d", "aria-label": s.toc, children: [
|
|
1350
|
-
entries.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1351
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "hyle-toc-title", children: s.toc }),
|
|
1352
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("nav", { className: "hyle-toc-list", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TocList, { toc: entries }) })
|
|
1353
|
-
] }),
|
|
1354
|
-
aside
|
|
1355
|
-
] })
|
|
1356
|
-
};
|
|
1357
|
-
}
|
|
1358
|
-
function Body({ article, components, locale }) {
|
|
1359
|
-
const { content, publication } = article;
|
|
1360
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "hyle-body hyle-prose", lang: article.fallback ? void 0 : publication.locale, children: content.format === "hast" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(HastContent, { tree: content.tree, title: publication.title, description: publication.description, components: components ?? {}, locale }) : content.format === "html" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TrustedServerHtml, { html: content.html }) : null });
|
|
1361
|
-
}
|
|
1362
|
-
function Languages({ alternates, current, c }) {
|
|
1363
|
-
if (alternates.length < 2) return null;
|
|
1364
|
-
const { Link, s } = c;
|
|
1365
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("nav", { className: "hyle-langs", "aria-label": s.languages, children: [
|
|
1366
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: s.readIn }),
|
|
1367
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { children: alternates.map((a) => {
|
|
1368
|
-
const label = languageName(a.locale, a.locale);
|
|
1369
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: a.locale === current ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: c.href(a.canonical_path, a.locale), hrefLang: a.locale, lang: a.locale, "aria-current": "true", children: label }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Link, { href: c.href(a.canonical_path, a.locale), hrefLang: a.locale, lang: a.locale, children: label }) }, a.locale);
|
|
1370
|
-
}) })
|
|
1371
|
-
] });
|
|
1372
|
-
}
|
|
1373
|
-
function LdScript({ json: json2 }) {
|
|
1374
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("script", { type: "application/ld+json", dangerouslySetInnerHTML: { __html: json2 } });
|
|
1375
|
-
}
|
|
1376
|
-
function ArticlePage({ article, engagement, origin, jsonLd, imageUrl, ...base }) {
|
|
1377
|
-
const { publication: pub } = article;
|
|
1378
|
-
const c = ctx(base, pub.locale);
|
|
1379
|
-
const { s } = c;
|
|
1380
|
-
const jsonLdOrigin = bareOrigin(origin);
|
|
1381
|
-
const author = articleAuthor(article, jsonLd)?.name;
|
|
1382
|
-
const toc = Toc({ toc: article.toc, c, aside: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.aside", slots: base.slots, className: "hyle-slot-wrap" }) });
|
|
1383
|
-
const notTranslated = article.fallback ? s.fallbackTitle.replace("{language}", languageName(article.fallback.requested_locale, c.locale)) : void 0;
|
|
1384
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("article", { className: "hyle-article", "data-hyle-page": "article", lang: c.locale, children: [
|
|
1385
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "hyle-head", children: [
|
|
1386
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.before", slots: base.slots, className: "hyle-eyebrow" }),
|
|
1387
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h1", { className: "hyle-title", children: pub.title }),
|
|
1388
|
-
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
1389
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-meta", children: [
|
|
1390
|
-
author ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1391
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: author.slice(0, 2).toUpperCase() }),
|
|
1392
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1393
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "hyle-sr", children: [
|
|
1394
|
-
s.by,
|
|
1395
|
-
" "
|
|
1396
|
-
] }),
|
|
1397
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "by", children: author })
|
|
1398
|
-
] })
|
|
1399
|
-
] }) : null,
|
|
1400
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1401
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "calendar" }),
|
|
1402
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("time", { dateTime: pub.published_at, title: pub.published_at, children: formatDate(pub.published_at, c.locale) })
|
|
1403
|
-
] }),
|
|
1404
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1405
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "globe" }),
|
|
1406
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { lang: pub.locale, children: languageName(pub.locale, c.locale) })
|
|
1407
|
-
] }),
|
|
1408
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.meta", slots: base.slots, tag: "span" })
|
|
1409
|
-
] }),
|
|
1410
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Languages, { alternates: article.alternates, current: pub.locale, c }),
|
|
1411
|
-
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1412
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }),
|
|
1413
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
1414
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: notTranslated }),
|
|
1415
|
-
" ",
|
|
1416
|
-
s.fallbackBody
|
|
1417
|
-
] })
|
|
1418
|
-
] }) : null
|
|
1419
|
-
] }),
|
|
1420
|
-
toc.narrow,
|
|
1421
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
1422
|
-
engagement ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_comments.Comments, { path: pub.canonical_path, endpoint: engagement.endpoint ?? "/api/hyle/engage", signInHref: engagement.signInHref, locale: c.locale, labels: s.comments }) : null,
|
|
1423
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Pager, { prev: article.prev, next: article.next, c }),
|
|
1424
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "article.after", slots: base.slots, className: "hyle-after" }),
|
|
1425
|
-
toc.wide,
|
|
1426
|
-
jsonLdOrigin ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LdScript, { json: articleJsonLd({ article, origin: jsonLdOrigin, href: c.href, jsonLd, imageUrl }) }) : null
|
|
1427
|
-
] }) });
|
|
1428
|
-
}
|
|
1429
|
-
function ListPage({ list, olderHref, description, origin, path, ...base }) {
|
|
1430
|
-
const c = ctx(base, "en");
|
|
1431
|
-
const { s, Link } = c;
|
|
1432
|
-
const Row = base.slots?.["list.item"];
|
|
1433
|
-
const groups = /* @__PURE__ */ new Map();
|
|
1434
|
-
for (const item of list.items) groups.set(item.published_at.slice(0, 7), [...groups.get(item.published_at.slice(0, 7)) ?? [], item]);
|
|
1435
|
-
const notTranslated = list.fallback ? s.fallbackTitle.replace("{language}", languageName(list.fallback.requested_locale, c.locale)) : void 0;
|
|
1436
|
-
const jsonLdOrigin = bareOrigin(origin);
|
|
1437
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-listpage", "data-hyle-page": "list", lang: c.locale, children: [
|
|
1438
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "hyle-head", children: [
|
|
1439
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h1", { className: "hyle-title", children: list.section.title }),
|
|
1440
|
-
description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "hyle-desc", children: description }) : null,
|
|
1441
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "list.header", slots: base.slots, className: "hyle-slot-wrap" }),
|
|
1442
|
-
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1443
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }),
|
|
1444
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
1445
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: notTranslated }),
|
|
1446
|
-
" ",
|
|
1447
|
-
s.fallbackBody
|
|
1448
|
-
] })
|
|
1449
|
-
] }) : null
|
|
1450
|
-
] }),
|
|
1451
|
-
list.items.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-empty", "data-slot-state": "empty", children: [
|
|
1452
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "file" }),
|
|
1453
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { children: s.emptyTitle }),
|
|
1454
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: s.emptyBody }),
|
|
1455
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "list.empty", slots: base.slots })
|
|
1456
|
-
] }) : [...groups].map(([month, items]) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { "aria-label": formatDate(`${month}-01`, c.locale, { month: "long", year: "numeric" }), children: [
|
|
1457
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { className: "hyle-year", children: formatDate(`${month}-01`, c.locale, { month: "long", year: "numeric" }) }),
|
|
1458
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "hyle-items", children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: Row ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Row, { item, href: c.href(item.canonical_path), locale: c.locale }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { className: "hyle-item", href: c.href(item.canonical_path), children: [
|
|
1459
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("time", { dateTime: item.published_at, title: item.published_at, children: formatDate(item.published_at, c.locale) }),
|
|
1460
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
1461
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "t", children: item.title }),
|
|
1462
|
-
item.description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: item.description }) : null
|
|
1463
|
-
] })
|
|
1464
|
-
] }) }, item.canonical_path)) })
|
|
1465
|
-
] }, month)),
|
|
1466
|
-
olderHref ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("nav", { className: "hyle-pagination", "aria-label": s.pager, children: [
|
|
1467
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "sp" }),
|
|
1468
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Link, { className: "hyle-btn sm", href: olderHref, rel: "next", children: [
|
|
1469
|
-
s.older,
|
|
1470
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "chev" })
|
|
1471
|
-
] })
|
|
1472
|
-
] }) : null,
|
|
1473
|
-
jsonLdOrigin && path ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LdScript, { json: listJsonLd({ list, origin: jsonLdOrigin, href: c.href, path, locale: c.locale, description }) }) : null
|
|
1474
|
-
] }) });
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
// src/react/index.ts
|
|
1478
|
-
var import_comments2 = require("./comments.cjs");
|
|
1479
|
-
|
|
1480
1228
|
// src/react/comments-api.ts
|
|
1481
1229
|
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1482
1230
|
var count = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.trunc(v) : 0;
|
|
@@ -1581,8 +1329,8 @@ function buildThread(listing, localHeld) {
|
|
|
1581
1329
|
// src/react/comments-body.tsx
|
|
1582
1330
|
var import_hast_util_to_jsx_runtime2 = require("hast-util-to-jsx-runtime");
|
|
1583
1331
|
var import_react2 = require("react");
|
|
1332
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1584
1333
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1585
|
-
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1586
1334
|
var ALLOWED = /* @__PURE__ */ new Set(["p", "a", "em", "strong", "del", "code", "pre", "blockquote", "ul", "ol", "li", "br"]);
|
|
1587
1335
|
var LINK_REL = "nofollow ugc noopener noreferrer";
|
|
1588
1336
|
function narrow(node) {
|
|
@@ -1605,44 +1353,45 @@ function CommentBody({ tree }) {
|
|
|
1605
1353
|
if (error instanceof HastLimitError) return null;
|
|
1606
1354
|
throw error;
|
|
1607
1355
|
}
|
|
1608
|
-
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" }) });
|
|
1609
1357
|
}
|
|
1610
1358
|
|
|
1611
1359
|
// src/react/embed.tsx
|
|
1612
|
-
var
|
|
1613
|
-
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 }) {
|
|
1614
1362
|
const c = ctx(base, "en");
|
|
1615
1363
|
const { s, Link } = c;
|
|
1616
1364
|
const Row = base.slots?.["list.item"];
|
|
1617
1365
|
const Heading = `h${headingLevel}`;
|
|
1618
1366
|
const safe = items.filter((item) => item.canonical_path.startsWith("/"));
|
|
1619
|
-
if (safe.length === 0) return base.slots?.["list.empty"] ? /* @__PURE__ */ (0,
|
|
1620
|
-
return /* @__PURE__ */ (0,
|
|
1621
|
-
title ? /* @__PURE__ */ (0,
|
|
1622
|
-
/* @__PURE__ */ (0,
|
|
1623
|
-
/* @__PURE__ */ (0,
|
|
1624
|
-
/* @__PURE__ */ (0,
|
|
1625
|
-
/* @__PURE__ */ (0,
|
|
1626
|
-
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
|
|
1627
1375
|
] })
|
|
1628
1376
|
] }) }, item.canonical_path)) }),
|
|
1629
|
-
|
|
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
|
|
1630
1379
|
] });
|
|
1631
1380
|
}
|
|
1632
1381
|
function HyleArticleView({ article, headingLevel = 2, ...base }) {
|
|
1633
1382
|
const { publication: pub } = article;
|
|
1634
1383
|
const c = ctx(base, pub.locale);
|
|
1635
1384
|
const Heading = `h${headingLevel}`;
|
|
1636
|
-
return /* @__PURE__ */ (0,
|
|
1637
|
-
/* @__PURE__ */ (0,
|
|
1638
|
-
/* @__PURE__ */ (0,
|
|
1639
|
-
pub.description ? /* @__PURE__ */ (0,
|
|
1640
|
-
/* @__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) }) }) })
|
|
1641
1390
|
] }),
|
|
1642
|
-
/* @__PURE__ */ (0,
|
|
1643
|
-
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: [
|
|
1644
1393
|
c.s.readAtSource,
|
|
1645
|
-
/* @__PURE__ */ (0,
|
|
1394
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "hyle-sr", children: [
|
|
1646
1395
|
": ",
|
|
1647
1396
|
pub.title
|
|
1648
1397
|
] })
|
|
@@ -1651,35 +1400,35 @@ function HyleArticleView({ article, headingLevel = 2, ...base }) {
|
|
|
1651
1400
|
}
|
|
1652
1401
|
var initials = (name) => name.trim().split(/\s+/).slice(0, 2).map((w) => [...w][0] ?? "").join("").toUpperCase() || "?";
|
|
1653
1402
|
function StaticThread({ nodes, locale, s, level = 1 }) {
|
|
1654
|
-
return /* @__PURE__ */ (0,
|
|
1655
|
-
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;
|
|
1656
1405
|
if (node.status === "removed") {
|
|
1657
1406
|
const why = node.removedBy === "moderator" ? s.removedByModerator : node.removedBy === "author" ? s.removedByAuthor : s.removed;
|
|
1658
|
-
return /* @__PURE__ */ (0,
|
|
1659
|
-
/* @__PURE__ */ (0,
|
|
1660
|
-
/* @__PURE__ */ (0,
|
|
1661
|
-
/* @__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 }) }) })
|
|
1662
1411
|
] }),
|
|
1663
1412
|
kids
|
|
1664
1413
|
] }, node.id);
|
|
1665
1414
|
}
|
|
1666
|
-
return /* @__PURE__ */ (0,
|
|
1667
|
-
/* @__PURE__ */ (0,
|
|
1668
|
-
/* @__PURE__ */ (0,
|
|
1669
|
-
/* @__PURE__ */ (0,
|
|
1670
|
-
/* @__PURE__ */ (0,
|
|
1671
|
-
/* @__PURE__ */ (0,
|
|
1672
|
-
/* @__PURE__ */ (0,
|
|
1673
|
-
/* @__PURE__ */ (0,
|
|
1674
|
-
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: [
|
|
1675
1424
|
" ",
|
|
1676
|
-
/* @__PURE__ */ (0,
|
|
1425
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "aria-hidden": "true", children: "\xB7" }),
|
|
1677
1426
|
" ",
|
|
1678
|
-
/* @__PURE__ */ (0,
|
|
1427
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: s.edited })
|
|
1679
1428
|
] }) : null
|
|
1680
1429
|
] })
|
|
1681
1430
|
] }),
|
|
1682
|
-
/* @__PURE__ */ (0,
|
|
1431
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CommentBody, { tree: node.tree })
|
|
1683
1432
|
] })
|
|
1684
1433
|
] }),
|
|
1685
1434
|
kids
|
|
@@ -1690,63 +1439,399 @@ function HyleCommentsView({ listing, locale }) {
|
|
|
1690
1439
|
const thread = buildThread(listing, []);
|
|
1691
1440
|
if (thread.length === 0) return null;
|
|
1692
1441
|
const s = stringsFor(locale).comments;
|
|
1693
|
-
return /* @__PURE__ */ (0,
|
|
1694
|
-
/* @__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: [
|
|
1695
1444
|
s.heading,
|
|
1696
1445
|
" ",
|
|
1697
|
-
/* @__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 })
|
|
1698
1447
|
] }) }),
|
|
1699
|
-
/* @__PURE__ */ (0,
|
|
1700
|
-
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
|
|
1701
1450
|
] }) });
|
|
1702
1451
|
}
|
|
1703
1452
|
function HyleCommentsFallback({ locale }) {
|
|
1704
1453
|
const s = stringsFor(locale).comments;
|
|
1705
|
-
return /* @__PURE__ */ (0,
|
|
1706
|
-
/* @__PURE__ */ (0,
|
|
1707
|
-
/* @__PURE__ */ (0,
|
|
1708
|
-
/* @__PURE__ */ (0,
|
|
1709
|
-
/* @__PURE__ */ (0,
|
|
1710
|
-
/* @__PURE__ */ (0,
|
|
1711
|
-
/* @__PURE__ */ (0,
|
|
1712
|
-
/* @__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%" } })
|
|
1713
1462
|
] })
|
|
1714
1463
|
] }, i)) })
|
|
1715
1464
|
] }) }) });
|
|
1716
1465
|
}
|
|
1717
1466
|
|
|
1718
|
-
// src/react/
|
|
1719
|
-
var
|
|
1720
|
-
var
|
|
1721
|
-
var
|
|
1722
|
-
var
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
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;
|
|
1733
1487
|
}
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
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;
|
|
1739
1500
|
}
|
|
1740
|
-
|
|
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 } : {} };
|
|
1741
1505
|
}
|
|
1742
|
-
function
|
|
1743
|
-
const
|
|
1744
|
-
return
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
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
|
+
|
|
1803
|
+
// src/react/docs.tsx
|
|
1804
|
+
var import_docs_enhance = require("./docs-enhance.cjs");
|
|
1805
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1806
|
+
var ROOT_ID = "hyle-docs";
|
|
1807
|
+
var NAV_ID = "hyle-docs-nav";
|
|
1808
|
+
function navTreeOf(article) {
|
|
1809
|
+
if (article.nav && !article.nav.truncated && article.nav.items.length > 0) return article.nav.items;
|
|
1810
|
+
const { publication: pub } = article;
|
|
1811
|
+
const here = {
|
|
1812
|
+
slug: pub.slug,
|
|
1813
|
+
title: pub.title,
|
|
1814
|
+
canonical_path: pub.canonical_path,
|
|
1815
|
+
children: article.children.map((child) => ({ ...child, children: [] }))
|
|
1816
|
+
};
|
|
1817
|
+
return [article.ancestors.reduceRight((inner, a) => ({ ...a, children: [inner] }), here)];
|
|
1818
|
+
}
|
|
1819
|
+
function pathTo(nodes, path) {
|
|
1820
|
+
for (const node of nodes) {
|
|
1821
|
+
if (node.canonical_path === path) return [node.canonical_path];
|
|
1822
|
+
const below = pathTo(node.children, path);
|
|
1823
|
+
if (below.length > 0) return [node.canonical_path, ...below];
|
|
1824
|
+
}
|
|
1825
|
+
return [];
|
|
1826
|
+
}
|
|
1827
|
+
function Branch({ nodes, current, onPath, c }) {
|
|
1828
|
+
const { Link } = c;
|
|
1829
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { children: nodes.map((node) => {
|
|
1830
|
+
const link = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Link, { href: c.href(node.canonical_path), ...node.canonical_path === current ? { "aria-current": "page" } : {}, children: node.title });
|
|
1831
|
+
if (node.children.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { children: link }, node.canonical_path);
|
|
1832
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("details", { ...onPath.has(node.canonical_path) ? { open: true } : {}, children: [
|
|
1833
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("summary", { children: [
|
|
1834
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "chev" }),
|
|
1750
1835
|
link
|
|
1751
1836
|
] }),
|
|
1752
1837
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Branch, { nodes: node.children, current, onPath, c })
|
|
@@ -1873,6 +1958,12 @@ function fetchResolver(options) {
|
|
|
1873
1958
|
function resolverFor(options) {
|
|
1874
1959
|
return options.resolver ?? fetchResolver(options);
|
|
1875
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
|
+
}
|
|
1876
1967
|
var CURSOR = /^[A-Za-z0-9_-]{1,256}$/;
|
|
1877
1968
|
var validCursor = (value) => typeof value === "string" && CURSOR.test(value) ? value : void 0;
|
|
1878
1969
|
var LOCALE_TAG2 = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
|
|
@@ -1892,66 +1983,430 @@ function isRejectedRequest(error) {
|
|
|
1892
1983
|
return error instanceof Cp1ClientError && error.status >= 400 && error.status < 500 && ![401, 403, 429].includes(error.status);
|
|
1893
1984
|
}
|
|
1894
1985
|
|
|
1895
|
-
// src/next/
|
|
1896
|
-
var
|
|
1897
|
-
function hylePage(options) {
|
|
1898
|
-
const resolve = resolverFor(options);
|
|
1899
|
-
return async function HylePage({ params, searchParams }) {
|
|
1900
|
-
const { path, locale, toHref } = routeContext(options, await params ?? {});
|
|
1901
|
-
if (path === void 0) (0, import_navigation2.notFound)();
|
|
1902
|
-
try {
|
|
1903
|
-
const cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
1904
|
-
const result = await resolve(path, locale, options.listLimit, cursor, options.layout === "docs" ? "tree" : void 0);
|
|
1905
|
-
switch (result.kind) {
|
|
1906
|
-
case "article": {
|
|
1907
|
-
const image = validOgImage(options.ogImage?.(result), bareOrigin(options.siteOrigin));
|
|
1908
|
-
const props = { article: result, components: options.components, slots: options.slots, locale, toHref };
|
|
1909
|
-
return options.layout === "docs" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DocsPage, { ...props }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ArticlePage, { ...props, origin: options.siteOrigin, jsonLd: options.jsonLd, imageUrl: image?.url, ...options.engagement ? { engagement: options.engagement } : {} });
|
|
1910
|
-
}
|
|
1911
|
-
case "list": {
|
|
1912
|
-
const list = options.list?.title ? { ...result, section: { ...result.section, title: options.list.title } } : result;
|
|
1913
|
-
const next = options.paginate === "searchParams" ? validCursor(result.next_cursor) : void 0;
|
|
1914
|
-
const olderHref = next ? `${toHref(path)}?cursor=${next}` : void 0;
|
|
1915
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ListPage, { list, ...olderHref ? { olderHref } : {}, ...options.list?.description ? { description: options.list.description } : {}, components: options.components, slots: options.slots, locale, toHref, origin: options.siteOrigin, path });
|
|
1916
|
-
}
|
|
1917
|
-
case "redirect": {
|
|
1918
|
-
const to = safeRedirectTarget(result.to);
|
|
1919
|
-
if (to === void 0) throw new Cp1ClientError("INVALID_RESPONSE", "hyle returned an unsafe redirect target", 502, "");
|
|
1920
|
-
const target = safeRedirectTarget(toHref(to));
|
|
1921
|
-
if (target === void 0) throw new Cp1ClientError("INVALID_RESPONSE", "hyle returned an unsafe redirect target", 502, "");
|
|
1922
|
-
if (target === toHref(path)) (0, import_navigation2.notFound)();
|
|
1923
|
-
return result.status === 301 ? (0, import_navigation2.permanentRedirect)(target) : (0, import_navigation2.redirect)(target);
|
|
1924
|
-
}
|
|
1925
|
-
case "notfound":
|
|
1926
|
-
case "disabled":
|
|
1927
|
-
(0, import_navigation2.notFound)();
|
|
1928
|
-
}
|
|
1929
|
-
} catch (error) {
|
|
1930
|
-
if (isRejectedRequest(error)) (0, import_navigation2.notFound)();
|
|
1931
|
-
if (!options.onError) throw error;
|
|
1932
|
-
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
1933
|
-
return options.onError(error);
|
|
1934
|
-
}
|
|
1935
|
-
};
|
|
1936
|
-
}
|
|
1986
|
+
// src/next/embed.tsx
|
|
1987
|
+
var import_navigation2 = require("next/navigation");
|
|
1937
1988
|
|
|
1938
|
-
// src/next/
|
|
1939
|
-
var
|
|
1940
|
-
var
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
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": {
|
|
2367
|
+
const list = options.list?.title ? { ...result, section: { ...result.section, title: options.list.title } } : result;
|
|
2368
|
+
const next = options.paginate === "searchParams" ? validCursor(result.next_cursor) : void 0;
|
|
2369
|
+
const olderHref = next ? `${toHref(path)}?cursor=${next}` : void 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 });
|
|
2371
|
+
}
|
|
2372
|
+
case "redirect": {
|
|
2373
|
+
const to = safeRedirectTarget(result.to);
|
|
2374
|
+
if (to === void 0) throw new Cp1ClientError("INVALID_RESPONSE", "hyle returned an unsafe redirect target", 502, "");
|
|
2375
|
+
const target = safeRedirectTarget(toHref(to));
|
|
2376
|
+
if (target === void 0) throw new Cp1ClientError("INVALID_RESPONSE", "hyle returned an unsafe redirect target", 502, "");
|
|
2377
|
+
if (target === toHref(path)) (0, import_navigation3.notFound)();
|
|
2378
|
+
return result.status === 301 ? (0, import_navigation3.permanentRedirect)(target) : (0, import_navigation3.redirect)(target);
|
|
2379
|
+
}
|
|
2380
|
+
case "notfound":
|
|
2381
|
+
case "disabled":
|
|
2382
|
+
(0, import_navigation3.notFound)();
|
|
2383
|
+
}
|
|
2384
|
+
} catch (error) {
|
|
2385
|
+
if (isRejectedRequest(error)) (0, import_navigation3.notFound)();
|
|
2386
|
+
if (!options.onError) throw error;
|
|
2387
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2388
|
+
return options.onError(error);
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2393
|
+
// src/next/sitemap.ts
|
|
2394
|
+
var ISO_DATE = /^\d{4}-\d{2}-\d{2}T/;
|
|
2395
|
+
var isoTime = (value) => value && ISO_DATE.test(value) ? Date.parse(value) : NaN;
|
|
2396
|
+
function httpsOrigin(origin) {
|
|
2397
|
+
let url;
|
|
2398
|
+
try {
|
|
2399
|
+
url = new URL(origin);
|
|
2400
|
+
} catch {
|
|
2401
|
+
throw new TypeError("hyleSitemap: `origin` must be an https origin such as https://example.com");
|
|
2402
|
+
}
|
|
2403
|
+
if (url.protocol !== "https:" || url.origin !== origin.replace(/\/$/, "")) {
|
|
2404
|
+
throw new TypeError("hyleSitemap: `origin` must be an https origin with no path, query or credentials");
|
|
2405
|
+
}
|
|
2406
|
+
return url.origin;
|
|
2407
|
+
}
|
|
2408
|
+
async function hyleSitemap(options) {
|
|
2409
|
+
const origin = httpsOrigin(options.origin);
|
|
1955
2410
|
const resolve = resolverFor(options);
|
|
1956
2411
|
const locale = typeof options.locale === "string" ? options.locale : void 0;
|
|
1957
2412
|
const { basePath, toHref } = routeContext({ ...options, locale: () => locale }, {});
|
|
@@ -1976,27 +2431,81 @@ async function hyleSitemap(options) {
|
|
|
1976
2431
|
|
|
1977
2432
|
// src/next/metadata.ts
|
|
1978
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
|
+
}
|
|
1979
2467
|
function hyleMetadata(options) {
|
|
1980
2468
|
const resolve = resolverFor(options);
|
|
1981
2469
|
const origin = bareOrigin(options.siteOrigin);
|
|
1982
|
-
return async function generateMetadata({ params, searchParams }) {
|
|
2470
|
+
return async function generateMetadata({ params, searchParams }, parent) {
|
|
1983
2471
|
const { path, locale, toHref } = routeContext(options, await params ?? {});
|
|
1984
2472
|
if (path === void 0) return {};
|
|
1985
2473
|
const link = (sitePath, linkLocale) => {
|
|
1986
2474
|
const href = toHref(sitePath, linkLocale);
|
|
1987
2475
|
return origin ? absoluteUrl(origin, href) : href;
|
|
1988
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
|
+
};
|
|
1989
2486
|
try {
|
|
1990
2487
|
const cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
1991
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;
|
|
1992
2491
|
if (result.kind === "list") {
|
|
1993
2492
|
const title = (options.list?.title || result.section.title) + (cursor ? ` - ${stringsFor(locale).older}` : "");
|
|
1994
2493
|
const description2 = options.list?.description;
|
|
2494
|
+
const ogLocale = locale && options.ogLocale?.(locale) || locale;
|
|
2495
|
+
const canonical2 = link(path) + (cursor ? `?cursor=${cursor}` : "");
|
|
1995
2496
|
return {
|
|
1996
2497
|
title: titled(options.titleTemplate, title),
|
|
1997
2498
|
...description2 ? { description: description2 } : {},
|
|
1998
|
-
alternates: { canonical:
|
|
1999
|
-
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
|
+
}
|
|
2000
2509
|
};
|
|
2001
2510
|
}
|
|
2002
2511
|
if (result.kind !== "article") return {};
|
|
@@ -2005,16 +2514,24 @@ function hyleMetadata(options) {
|
|
|
2005
2514
|
const description = pub.description ?? void 0;
|
|
2006
2515
|
const author = articleAuthor(result, options.jsonLd)?.name;
|
|
2007
2516
|
const modified = modifiedAt(pub);
|
|
2008
|
-
const image =
|
|
2517
|
+
const image = articleImage(options, result);
|
|
2009
2518
|
const alternateLocale = options.ogLocale ? alternates.filter((a) => a.locale !== pub.locale).flatMap((a) => options.ogLocale?.(a.locale) ?? []) : [];
|
|
2010
2519
|
const { twitter } = options;
|
|
2520
|
+
const inherited = parentMeta?.robots;
|
|
2521
|
+
const section = result.breadcrumbs[0]?.title;
|
|
2522
|
+
const words = wordCountOf(pub);
|
|
2011
2523
|
return {
|
|
2012
2524
|
title: titled(options.titleTemplate, pub.title),
|
|
2013
2525
|
...description ? { description } : {},
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
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
|
+
),
|
|
2018
2535
|
openGraph: {
|
|
2019
2536
|
type: "article",
|
|
2020
2537
|
title: pub.title,
|
|
@@ -2025,9 +2542,12 @@ function hyleMetadata(options) {
|
|
|
2025
2542
|
...alternateLocale.length ? { alternateLocale } : {},
|
|
2026
2543
|
publishedTime: pub.published_at,
|
|
2027
2544
|
...modified ? { modifiedTime: modified } : {},
|
|
2545
|
+
...section ? { section } : {},
|
|
2028
2546
|
...author ? { authors: [author] } : {},
|
|
2029
|
-
...image ? { images: [image] } : {}
|
|
2547
|
+
...image ? { images: [image] } : parentImages?.length ? { images: parentImages } : {}
|
|
2030
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))) } } : {},
|
|
2031
2551
|
...image ? {
|
|
2032
2552
|
twitter: {
|
|
2033
2553
|
card: "summary_large_image",
|
|
@@ -2045,722 +2565,412 @@ function hyleMetadata(options) {
|
|
|
2045
2565
|
}
|
|
2046
2566
|
};
|
|
2047
2567
|
}
|
|
2048
|
-
|
|
2049
|
-
// src/next/feed.ts
|
|
2050
|
-
var
|
|
2051
|
-
var xml = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
2052
|
-
var tag = (name, value) => `<${name}>${xml(value)}</${name}>`;
|
|
2053
|
-
var response = (body, status, headers) => new Response(body, { status, ...headers ? { headers } : {} });
|
|
2054
|
-
async function hyleFeed(options) {
|
|
2055
|
-
const origin = options.siteOrigin;
|
|
2056
|
-
if (!origin || !BARE_HTTPS_ORIGIN.test(origin)) {
|
|
2057
|
-
console.error("hyle: hyleFeed needs `siteOrigin`, a bare https origin such as https://example.com");
|
|
2058
|
-
return response(null, 404);
|
|
2059
|
-
}
|
|
2060
|
-
const { path, locale, toHref } = routeContext(options, {});
|
|
2061
|
-
if (path === void 0) return response(null, 404);
|
|
2062
|
-
const url = (sitePath) => origin + encodeURI(toHref(sitePath));
|
|
2063
|
-
try {
|
|
2064
|
-
const result = await resolverFor(options)(path, locale, options.limit ?? 50);
|
|
2065
|
-
if (result.kind !== "list") return response(null, 503);
|
|
2066
|
-
const items = result.items.filter((item) => item.canonical_path.startsWith("/")).map((item) => {
|
|
2067
|
-
const link = url(item.canonical_path);
|
|
2068
|
-
const published = new Date(item.published_at);
|
|
2069
|
-
return `<item>${tag("title", item.title)}${tag("link", link)}<guid isPermaLink="true">${xml(link)}</guid>${Number.isNaN(published.getTime()) ? "" : tag("pubDate", published.toUTCString())}${item.description ? tag("description", item.description) : ""}</item>`;
|
|
2070
|
-
});
|
|
2071
|
-
const channel = [
|
|
2072
|
-
tag("title", options.list?.title || result.section.title),
|
|
2073
|
-
tag("link", url(path)),
|
|
2074
|
-
tag("description", options.list?.description ?? ""),
|
|
2075
|
-
locale ? tag("language", locale) : "",
|
|
2076
|
-
`<atom:link href="${xml(origin + encodeURI(options.feedPath ?? "/feed.xml"))}" rel="self" type="application/rss+xml"/>`,
|
|
2077
|
-
...items
|
|
2078
|
-
].join("");
|
|
2079
|
-
return response(
|
|
2080
|
-
`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel>${channel}</channel></rss>`,
|
|
2081
|
-
200,
|
|
2082
|
-
{ "content-type": "application/rss+xml; charset=utf-8" }
|
|
2083
|
-
);
|
|
2084
|
-
} catch (error) {
|
|
2085
|
-
(0,
|
|
2086
|
-
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2087
|
-
return response(null, 503);
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
|
-
// src/next/revalidate.ts
|
|
2092
|
-
var import_cache = require("next/cache");
|
|
2093
|
-
var isSwitchedOff = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
2094
|
-
function createRevalidateRoute(options) {
|
|
2095
|
-
let cached;
|
|
2096
|
-
return {
|
|
2097
|
-
async POST(req) {
|
|
2098
|
-
if (isSwitchedOff((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return new Response(null, { status: 404 });
|
|
2099
|
-
const workspaceId = options.workspaceId?.trim();
|
|
2100
|
-
const secrets = options.secrets.map((s) => s?.trim()).filter((s) => Boolean(s));
|
|
2101
|
-
if (!workspaceId && secrets.length === 0) return new Response(null, { status: 404 });
|
|
2102
|
-
if (!workspaceId || secrets.length === 0) return new Response(null, { status: 503 });
|
|
2103
|
-
const key = `${workspaceId}\0${secrets.join("\0")}`;
|
|
2104
|
-
if (cached?.key !== key) {
|
|
2105
|
-
cached = { key, route: createRevalidationCallbackRoute({ workspaceId, secrets, revalidateTag: (tag2) => (0, import_cache.revalidateTag)(tag2, { expire: 0 }) }) };
|
|
2106
|
-
}
|
|
2107
|
-
return cached.route.POST(req);
|
|
2108
|
-
}
|
|
2109
|
-
};
|
|
2110
|
-
}
|
|
2111
|
-
|
|
2112
|
-
// src/next/root.ts
|
|
2113
|
-
var import_navigation4 = require("next/navigation");
|
|
2114
|
-
|
|
2115
|
-
// src/next/mount-match.ts
|
|
2116
|
-
function activeMounts(mounts) {
|
|
2117
|
-
const out = [];
|
|
2118
|
-
for (const { prefix, default_section, name, locales } of mounts) {
|
|
2119
|
-
try {
|
|
2120
|
-
const normalized = normalizeBasePath(prefix);
|
|
2121
|
-
out.push({
|
|
2122
|
-
prefix: normalized,
|
|
2123
|
-
defaultSection: default_section,
|
|
2124
|
-
depth: normalized === "" ? 0 : normalized.split("/").length - 1,
|
|
2125
|
-
...name ? { name } : {},
|
|
2126
|
-
...locales ? { locales } : {}
|
|
2127
|
-
});
|
|
2128
|
-
} catch (error) {
|
|
2129
|
-
console.error(`hyle: ignoring a mount with an invalid prefix (${error instanceof Error ? error.name : "Error"})`);
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
return out;
|
|
2133
|
-
}
|
|
2134
|
-
var prefixMatches = (prefix, path) => prefix === "" || path === prefix || path.startsWith(`${prefix}/`);
|
|
2135
|
-
function isReserved(path, reserved) {
|
|
2136
|
-
return reserved.some((entry) => entry.endsWith("/*") ? prefixMatches(entry.slice(0, -2), path) : entry === path);
|
|
2137
|
-
}
|
|
2138
|
-
|
|
2139
|
-
// src/next/root.ts
|
|
2140
|
-
var MOUNTS_MAX_STALE_MS = 15 * 60 * 1e3;
|
|
2141
|
-
var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
2142
|
-
var NONE = { mounts: [], reserved: [], defaultLocale: "" };
|
|
2143
|
-
var lastKnownGood = /* @__PURE__ */ new Map();
|
|
2144
|
-
function mountsLoader(config) {
|
|
2145
|
-
if (!config.workspaceId) throw new TypeError("hyleRootPage: `workspaceId` is required for the fetch cache");
|
|
2146
|
-
const client = createHyleClient({ baseUrl: config.baseUrl, token: config.token });
|
|
2147
|
-
const init = { next: { revalidate: config.revalidate ?? DEFAULT_REVALIDATE, tags: workspaceTags(config.workspaceId).slice(0, 1) } };
|
|
2148
|
-
const key = `${new URL(config.baseUrl).origin}|${config.workspaceId}`;
|
|
2149
|
-
return async function load() {
|
|
2150
|
-
try {
|
|
2151
|
-
const result = await client.mounts({ init });
|
|
2152
|
-
if (result.kind !== "mounts") {
|
|
2153
|
-
lastKnownGood.delete(key);
|
|
2154
|
-
return NONE;
|
|
2155
|
-
}
|
|
2156
|
-
const loaded = { mounts: activeMounts(result.mounts), reserved: result.reserved, defaultLocale: result.default_locale };
|
|
2157
|
-
lastKnownGood.set(key, { loaded, at: Date.now() });
|
|
2158
|
-
return loaded;
|
|
2159
|
-
} catch (error) {
|
|
2160
|
-
if (isRejectedRequest(error)) {
|
|
2161
|
-
lastKnownGood.delete(key);
|
|
2162
|
-
return NONE;
|
|
2163
|
-
}
|
|
2164
|
-
if (error instanceof Cp1ClientError && (error.status === 401 || error.status === 403)) {
|
|
2165
|
-
lastKnownGood.delete(key);
|
|
2166
|
-
throw error;
|
|
2167
|
-
}
|
|
2168
|
-
const kept = lastKnownGood.get(key);
|
|
2169
|
-
if (kept && Date.now() - kept.at <= MOUNTS_MAX_STALE_MS) return kept.loaded;
|
|
2170
|
-
throw error;
|
|
2171
|
-
}
|
|
2172
|
-
};
|
|
2173
|
-
}
|
|
2174
|
-
var asArray = (options) => Array.isArray(options) ? options : [options];
|
|
2175
|
-
function setup(options) {
|
|
2176
|
-
const configs = asArray(options);
|
|
2177
|
-
if (configs.length === 0) throw new TypeError("hyleRootPage: pass at least one workspace config");
|
|
2178
|
-
const param = configs[0].param ?? "hyle";
|
|
2179
|
-
if (configs.some((c) => (c.param ?? "hyle") !== param)) throw new TypeError("hyleRootPage: every config must use the same `param`");
|
|
2180
|
-
return { configs, param, loaders: configs.map(mountsLoader) };
|
|
2181
|
-
}
|
|
2182
|
-
var sectionsOf = (config, mount) => [
|
|
2183
|
-
...config.sections ?? [],
|
|
2184
|
-
...SECTION_SLUG.test(mount.defaultSection) ? [mount.defaultSection] : []
|
|
2185
|
-
];
|
|
2186
|
-
function mountOptionsOf(config, mount) {
|
|
2187
|
-
const { mountOptions, ...rest } = config;
|
|
2188
|
-
return { ...rest, ...mountOptions?.[mount.prefix === "" ? "/" : mount.prefix], basePath: mount.prefix, sections: sectionsOf(config, mount) };
|
|
2189
|
-
}
|
|
2190
|
-
function rootMounts(options) {
|
|
2191
|
-
const { configs, param, loaders } = setup(options);
|
|
2192
|
-
return {
|
|
2193
|
-
param,
|
|
2194
|
-
async locate(path) {
|
|
2195
|
-
const loaded = await Promise.all(loaders.map((load) => load()));
|
|
2196
|
-
let best;
|
|
2197
|
-
loaded.forEach(({ mounts, reserved }, index2) => {
|
|
2198
|
-
if (isReserved(path, reserved)) return;
|
|
2199
|
-
for (const mount2 of mounts) if (prefixMatches(mount2.prefix, path) && (!best || mount2.depth > best.mount.depth)) best = { index: index2, mount: mount2 };
|
|
2200
|
-
});
|
|
2201
|
-
if (!best) return void 0;
|
|
2202
|
-
const { index, mount } = best;
|
|
2203
|
-
return { options: mountOptionsOf(configs[index], mount), mount, index };
|
|
2204
|
-
},
|
|
2205
|
-
async all() {
|
|
2206
|
-
const out = [];
|
|
2207
|
-
for (const [index, load] of loaders.entries()) {
|
|
2208
|
-
const { mounts, defaultLocale } = await load();
|
|
2209
|
-
for (const mount of mounts) out.push({ options: mountOptionsOf(configs[index], mount), mount, index, defaultLocale });
|
|
2210
|
-
}
|
|
2211
|
-
return out;
|
|
2212
|
-
}
|
|
2213
|
-
};
|
|
2214
|
-
}
|
|
2215
|
-
function createRouter(options, make) {
|
|
2216
|
-
const mounts = rootMounts(options);
|
|
2217
|
-
const handlers = /* @__PURE__ */ new Map();
|
|
2218
|
-
return async function route(params) {
|
|
2219
|
-
const raw = params[mounts.param];
|
|
2220
|
-
const segments = typeof raw === "string" ? [raw] : raw;
|
|
2221
|
-
const path = sitePathFrom("", segments);
|
|
2222
|
-
if (path === void 0 || path === "/" || !segments) return void 0;
|
|
2223
|
-
const hit = await mounts.locate(path);
|
|
2224
|
-
if (!hit) return void 0;
|
|
2225
|
-
const { mount, index } = hit;
|
|
2226
|
-
const id = `${index}|${mount.prefix}|${mount.defaultSection}`;
|
|
2227
|
-
let handler = handlers.get(id);
|
|
2228
|
-
if (!handler) {
|
|
2229
|
-
handler = make(hit.options);
|
|
2230
|
-
handlers.set(id, handler);
|
|
2231
|
-
}
|
|
2232
|
-
return { handler, params: { ...params, [mounts.param]: segments.slice(mount.depth) } };
|
|
2233
|
-
};
|
|
2234
|
-
}
|
|
2235
|
-
function hyleRootPage(options) {
|
|
2236
|
-
const route = createRouter(options, hylePage);
|
|
2237
|
-
return async function HyleRootPage({ params, searchParams }) {
|
|
2238
|
-
const hit = await route(await params ?? {});
|
|
2239
|
-
if (!hit) (0, import_navigation4.notFound)();
|
|
2240
|
-
return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
|
|
2241
|
-
};
|
|
2242
|
-
}
|
|
2243
|
-
function hyleRootMetadata(options) {
|
|
2244
|
-
const route = createRouter(options, hyleMetadata);
|
|
2245
|
-
return async function generateMetadata({ params }) {
|
|
2246
|
-
const hit = await route(await params ?? {});
|
|
2247
|
-
return hit ? hit.handler({ params: Promise.resolve(hit.params) }) : {};
|
|
2248
|
-
};
|
|
2249
|
-
}
|
|
2250
|
-
async function hyleRootSitemap(options, sitemap) {
|
|
2251
|
-
const entries = /* @__PURE__ */ new Map();
|
|
2252
|
-
for (const { options: mountOptions, mount, defaultLocale } of await rootMounts(options).all()) {
|
|
2253
|
-
for (const locale of mount.locales ?? [defaultLocale]) {
|
|
2254
|
-
for (const entry of await hyleSitemap({ ...mountOptions, ...sitemap, locale, defaultLocale })) entries.set(entry.url, entry);
|
|
2255
|
-
}
|
|
2568
|
+
|
|
2569
|
+
// src/next/feed.ts
|
|
2570
|
+
var import_navigation4 = require("next/navigation");
|
|
2571
|
+
var xml = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
2572
|
+
var tag = (name, value) => `<${name}>${xml(value)}</${name}>`;
|
|
2573
|
+
var response = (body, status, headers) => new Response(body, { status, ...headers ? { headers } : {} });
|
|
2574
|
+
async function hyleFeed(options) {
|
|
2575
|
+
const origin = options.siteOrigin;
|
|
2576
|
+
if (!origin || !BARE_HTTPS_ORIGIN.test(origin)) {
|
|
2577
|
+
console.error("hyle: hyleFeed needs `siteOrigin`, a bare https origin such as https://example.com");
|
|
2578
|
+
return response(null, 404);
|
|
2579
|
+
}
|
|
2580
|
+
const { path, locale, toHref } = routeContext(options, {});
|
|
2581
|
+
if (path === void 0) return response(null, 404);
|
|
2582
|
+
const url = (sitePath) => origin + encodeURI(toHref(sitePath));
|
|
2583
|
+
try {
|
|
2584
|
+
const result = await resolverFor(options)(path, locale, options.limit ?? 50);
|
|
2585
|
+
if (result.kind !== "list") return response(null, 503);
|
|
2586
|
+
const items = result.items.filter((item) => item.canonical_path.startsWith("/")).map((item) => {
|
|
2587
|
+
const link = url(item.canonical_path);
|
|
2588
|
+
const published = new Date(item.published_at);
|
|
2589
|
+
return `<item>${tag("title", item.title)}${tag("link", link)}<guid isPermaLink="true">${xml(link)}</guid>${Number.isNaN(published.getTime()) ? "" : tag("pubDate", published.toUTCString())}${item.description ? tag("description", item.description) : ""}</item>`;
|
|
2590
|
+
});
|
|
2591
|
+
const channel = [
|
|
2592
|
+
tag("title", options.list?.title || result.section.title),
|
|
2593
|
+
tag("link", url(path)),
|
|
2594
|
+
tag("description", options.list?.description ?? ""),
|
|
2595
|
+
locale ? tag("language", locale) : "",
|
|
2596
|
+
`<atom:link href="${xml(origin + encodeURI(options.feedPath ?? "/feed.xml"))}" rel="self" type="application/rss+xml"/>`,
|
|
2597
|
+
...items
|
|
2598
|
+
].join("");
|
|
2599
|
+
return response(
|
|
2600
|
+
`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel>${channel}</channel></rss>`,
|
|
2601
|
+
200,
|
|
2602
|
+
{ "content-type": "application/rss+xml; charset=utf-8" }
|
|
2603
|
+
);
|
|
2604
|
+
} catch (error) {
|
|
2605
|
+
(0, import_navigation4.unstable_rethrow)(error);
|
|
2606
|
+
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2607
|
+
return response(null, 503);
|
|
2256
2608
|
}
|
|
2257
|
-
return [...entries.values()];
|
|
2258
2609
|
}
|
|
2259
2610
|
|
|
2260
|
-
// src/next/
|
|
2261
|
-
var
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
}
|
|
2266
|
-
var reply = (body, status, headers = {}) => (
|
|
2267
|
-
// noindex on every answer: the .md twin must never compete with the page it mirrors.
|
|
2268
|
-
new Response(body, { status, headers: { "X-Robots-Tag": "noindex", ...headers } })
|
|
2269
|
-
);
|
|
2270
|
-
function createMarkdownRoute(options) {
|
|
2271
|
-
const mounts = rootMounts(options);
|
|
2611
|
+
// src/next/revalidate.ts
|
|
2612
|
+
var import_cache = require("next/cache");
|
|
2613
|
+
var isSwitchedOff2 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
2614
|
+
function createRevalidateRoute(options) {
|
|
2615
|
+
let cached;
|
|
2272
2616
|
return {
|
|
2273
|
-
async
|
|
2274
|
-
|
|
2275
|
-
const
|
|
2276
|
-
const
|
|
2277
|
-
if (
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
const result = await resolverFor(hit.options)(path, locale, void 0, void 0, void 0, "md");
|
|
2283
|
-
if (result.kind === "article" && result.content.format === "md") {
|
|
2284
|
-
const markdown = result.content.markdown.replaceAll("](/assets/", `](${ASSET_ROUTE_PREFIX}/`);
|
|
2285
|
-
return reply(markdown, 200, { "Content-Type": "text/markdown; charset=utf-8" });
|
|
2286
|
-
}
|
|
2287
|
-
if (result.kind === "redirect") {
|
|
2288
|
-
const to = safeRedirectTarget(result.to);
|
|
2289
|
-
const target = to === void 0 ? void 0 : safeRedirectTarget(toHref(to));
|
|
2290
|
-
if (target === void 0) return reply(null, 502);
|
|
2291
|
-
return target === toHref(path) ? reply(null, 404) : reply(null, result.status === 301 ? 308 : 307, { Location: `${target}.md` });
|
|
2292
|
-
}
|
|
2293
|
-
return reply(null, 404);
|
|
2294
|
-
} catch (error) {
|
|
2295
|
-
if (isRejectedRequest(error)) return reply(null, 404);
|
|
2296
|
-
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2297
|
-
return reply(null, 502);
|
|
2617
|
+
async POST(req) {
|
|
2618
|
+
if (isSwitchedOff2((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return new Response(null, { status: 404 });
|
|
2619
|
+
const workspaceId = options.workspaceId?.trim();
|
|
2620
|
+
const secrets = options.secrets.map((s) => s?.trim()).filter((s) => Boolean(s));
|
|
2621
|
+
if (!workspaceId && secrets.length === 0) return new Response(null, { status: 404 });
|
|
2622
|
+
if (!workspaceId || secrets.length === 0) return new Response(null, { status: 503 });
|
|
2623
|
+
const key = `${workspaceId}\0${secrets.join("\0")}`;
|
|
2624
|
+
if (cached?.key !== key) {
|
|
2625
|
+
cached = { key, route: createRevalidationCallbackRoute({ workspaceId, secrets, revalidateTag: (tag2) => (0, import_cache.revalidateTag)(tag2, { expire: 0 }) }) };
|
|
2298
2626
|
}
|
|
2627
|
+
return cached.route.POST(req);
|
|
2299
2628
|
}
|
|
2300
2629
|
};
|
|
2301
2630
|
}
|
|
2302
2631
|
|
|
2303
|
-
// src/next/
|
|
2632
|
+
// src/next/root.ts
|
|
2304
2633
|
var import_navigation5 = require("next/navigation");
|
|
2305
|
-
var oneLine = (text) => text.replace(/\s+/g, " ").trim();
|
|
2306
|
-
var linkTarget = (url) => url.replace(/[()]/g, (c) => c === "(" ? "%28" : "%29");
|
|
2307
|
-
function createLlmsTxtRoute(options, llms) {
|
|
2308
|
-
const origin = bareOrigin(llms.origin);
|
|
2309
|
-
if (!origin) throw new TypeError("createLlmsTxtRoute: `origin` must be a bare https origin such as https://example.com");
|
|
2310
|
-
const mounts = rootMounts(options);
|
|
2311
|
-
return {
|
|
2312
|
-
async GET() {
|
|
2313
|
-
try {
|
|
2314
|
-
const lines = [`# ${oneLine(llms.title ?? new URL(origin).host)}`, ...llms.description ? ["", `> ${oneLine(llms.description)}`] : []];
|
|
2315
|
-
for (const { options: mountOptions, mount, defaultLocale } of await mounts.all()) {
|
|
2316
|
-
if (mount.locales && !mount.locales.includes(defaultLocale)) continue;
|
|
2317
|
-
const { basePath, toHref } = routeContext({ ...mountOptions, locale: () => defaultLocale }, {});
|
|
2318
|
-
const resolve = resolverFor(mountOptions);
|
|
2319
|
-
const client = { resolve: ({ path, locale, limit, cursor }) => resolve(path, locale, limit, cursor) };
|
|
2320
|
-
const { paths } = await listPublicationPaths({ client, basePath, locale: defaultLocale });
|
|
2321
|
-
lines.push("", `## ${oneLine(mount.name ?? mount.defaultSection)}`, "");
|
|
2322
|
-
for (const { path, title, description } of paths) {
|
|
2323
|
-
lines.push(`- [${oneLine(title).replace(/[[\]]/g, "")}](${linkTarget(absoluteUrl(origin, toHref(path)))}.md)${description ? `: ${oneLine(description)}` : ""}`);
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
return new Response(`${lines.join("\n")}
|
|
2327
|
-
`, { headers: { "Content-Type": "text/plain; charset=utf-8" } });
|
|
2328
|
-
} catch (error) {
|
|
2329
|
-
(0, import_navigation5.unstable_rethrow)(error);
|
|
2330
|
-
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2331
|
-
return new Response(null, { status: 503 });
|
|
2332
|
-
}
|
|
2333
|
-
}
|
|
2334
|
-
};
|
|
2335
|
-
}
|
|
2336
2634
|
|
|
2337
|
-
// src/next/
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
var PARTIAL_CACHE_CONTROL = "no-store";
|
|
2342
|
-
var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
|
|
2343
|
-
var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
|
|
2344
|
-
var isSwitchedOff2 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
2345
|
-
function capped(body, max) {
|
|
2346
|
-
let seen = 0;
|
|
2347
|
-
return body.pipeThrough(
|
|
2348
|
-
new TransformStream({
|
|
2349
|
-
transform(chunk, controller) {
|
|
2350
|
-
seen += chunk.byteLength;
|
|
2351
|
-
if (seen > max) return controller.error(new Error("asset too large"));
|
|
2352
|
-
controller.enqueue(chunk);
|
|
2353
|
-
}
|
|
2354
|
-
})
|
|
2355
|
-
);
|
|
2356
|
-
}
|
|
2357
|
-
function createAssetRoute(options) {
|
|
2358
|
-
let client;
|
|
2359
|
-
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
2360
|
-
async function serve(req, ctx2, head) {
|
|
2361
|
-
if (isSwitchedOff2((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
|
|
2362
|
-
const file = (await ctx2.params).file;
|
|
2363
|
-
if (typeof file !== "string" || !ASSET_FILE.test(file)) return empty(404);
|
|
2364
|
-
try {
|
|
2365
|
-
client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
|
|
2366
|
-
} catch {
|
|
2367
|
-
return empty(404);
|
|
2368
|
-
}
|
|
2369
|
-
let upstream;
|
|
2635
|
+
// src/next/mount-match.ts
|
|
2636
|
+
function activeMounts(mounts) {
|
|
2637
|
+
const out = [];
|
|
2638
|
+
for (const { prefix, default_section, name, locales } of mounts) {
|
|
2370
2639
|
try {
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2640
|
+
const normalized = normalizeBasePath(prefix);
|
|
2641
|
+
out.push({
|
|
2642
|
+
prefix: normalized,
|
|
2643
|
+
defaultSection: default_section,
|
|
2644
|
+
depth: normalized === "" ? 0 : normalized.split("/").length - 1,
|
|
2645
|
+
...name ? { name } : {},
|
|
2646
|
+
...locales ? { locales } : {}
|
|
2374
2647
|
});
|
|
2375
|
-
} catch {
|
|
2376
|
-
|
|
2377
|
-
}
|
|
2378
|
-
const drop = () => void upstream.body?.cancel().catch(() => {
|
|
2379
|
-
});
|
|
2380
|
-
const etag = upstream.headers.get("etag");
|
|
2381
|
-
if (upstream.status === 304) {
|
|
2382
|
-
drop();
|
|
2383
|
-
return new Response(null, { status: 304, headers: { "Cache-Control": CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS, ...etag ? { ETag: etag } : {} } });
|
|
2384
|
-
}
|
|
2385
|
-
if (upstream.status === 404 || upstream.status === 416) {
|
|
2386
|
-
drop();
|
|
2387
|
-
const range = upstream.status === 416 ? upstream.headers.get("content-range") : null;
|
|
2388
|
-
return empty(upstream.status, range ? { "Content-Range": range } : {});
|
|
2389
|
-
}
|
|
2390
|
-
const type = upstream.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase();
|
|
2391
|
-
const length = Number(upstream.headers.get("content-length"));
|
|
2392
|
-
const expectedStatus = upstream.status === 200 || upstream.status === 206;
|
|
2393
|
-
if (!expectedStatus || !upstream.body || !type || !ASSET_CONTENT_TYPES.has(type) || Number.isFinite(length) && length > maxBytes) {
|
|
2394
|
-
drop();
|
|
2395
|
-
return empty(502);
|
|
2396
|
-
}
|
|
2397
|
-
const headers = new Headers({ "Content-Type": type, "Accept-Ranges": "bytes", "Cache-Control": upstream.status === 206 ? PARTIAL_CACHE_CONTROL : CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS });
|
|
2398
|
-
if (etag) headers.set("ETag", etag);
|
|
2399
|
-
const contentRange = upstream.headers.get("content-range");
|
|
2400
|
-
if (upstream.status === 206 && contentRange) headers.set("Content-Range", contentRange);
|
|
2401
|
-
if (!upstream.headers.get("content-encoding") && upstream.headers.get("content-length")) headers.set("Content-Length", String(length));
|
|
2402
|
-
if (head) {
|
|
2403
|
-
drop();
|
|
2404
|
-
return new Response(null, { status: upstream.status, headers });
|
|
2648
|
+
} catch (error) {
|
|
2649
|
+
console.error(`hyle: ignoring a mount with an invalid prefix (${error instanceof Error ? error.name : "Error"})`);
|
|
2405
2650
|
}
|
|
2406
|
-
return new Response(capped(upstream.body, maxBytes), { status: upstream.status, headers });
|
|
2407
2651
|
}
|
|
2408
|
-
return
|
|
2652
|
+
return out;
|
|
2409
2653
|
}
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
// src/next/engage.ts
|
|
2415
|
-
var ENGAGE_CSRF_HEADER = "x-hyle-engage";
|
|
2416
|
-
var DEFAULT_TIMEOUT_MS3 = 1e4;
|
|
2417
|
-
var DEFAULT_SHARE_MS = 3e3;
|
|
2418
|
-
var MAX_SHARED = 100;
|
|
2419
|
-
var MAX_SHARED_BYTES = 8 * 1024 * 1024;
|
|
2420
|
-
var MAX_SHARED_ENTRY_BYTES = 256 * 1024;
|
|
2421
|
-
var MAX_BODY_BYTES2 = 20 * 1024;
|
|
2422
|
-
var MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
2423
|
-
var MAX_COMMENT_CHARACTERS = 4e3;
|
|
2424
|
-
var MAX_PATH_LENGTH2 = 1024;
|
|
2425
|
-
var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
2426
|
-
var CONTROL = /[\u0000-\u001f\u007f\\]/;
|
|
2427
|
-
var HEADERS = { "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" };
|
|
2428
|
-
var isSwitchedOff3 = (value) => {
|
|
2429
|
-
const v = value?.trim().toLowerCase() ?? "";
|
|
2430
|
-
return v !== "" && v !== "1" && v !== "true";
|
|
2431
|
-
};
|
|
2432
|
-
var json = (status, body, extra = {}) => new Response(JSON.stringify(body), { status, headers: { ...HEADERS, "Content-Type": "application/json; charset=utf-8", ...extra } });
|
|
2433
|
-
var refuse = (status, code, extra = {}) => json(status, { error: { code } }, extra);
|
|
2434
|
-
function isSitePath2(value) {
|
|
2435
|
-
if (typeof value !== "string" || value.length > MAX_PATH_LENGTH2 || !value.startsWith("/") || value.startsWith("//")) return false;
|
|
2436
|
-
if (CONTROL.test(value) || /[?#]/.test(value)) return false;
|
|
2437
|
-
return !value.split("/").some((segment) => segment === "." || segment === "..");
|
|
2654
|
+
var prefixMatches = (prefix, path) => prefix === "" || path === prefix || path.startsWith(`${prefix}/`);
|
|
2655
|
+
function isReserved(path, reserved) {
|
|
2656
|
+
return reserved.some((entry) => entry.endsWith("/*") ? prefixMatches(entry.slice(0, -2), path) : entry === path);
|
|
2438
2657
|
}
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
return { upstream: "/comments", body: clean2 };
|
|
2658
|
+
|
|
2659
|
+
// src/next/root.ts
|
|
2660
|
+
var MOUNTS_MAX_STALE_MS = 15 * 60 * 1e3;
|
|
2661
|
+
var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
2662
|
+
var NONE = { mounts: [], reserved: [], defaultLocale: "" };
|
|
2663
|
+
var lastKnownGood = /* @__PURE__ */ new Map();
|
|
2664
|
+
function mountsLoader(config) {
|
|
2665
|
+
if (!config.workspaceId) throw new TypeError("hyleRootPage: `workspaceId` is required for the fetch cache");
|
|
2666
|
+
const client = createHyleClient({ baseUrl: config.baseUrl, token: config.token });
|
|
2667
|
+
const init = { next: { revalidate: config.revalidate ?? DEFAULT_REVALIDATE, tags: workspaceTags(config.workspaceId).slice(0, 1) } };
|
|
2668
|
+
const key = `${new URL(config.baseUrl).origin}|${config.workspaceId}`;
|
|
2669
|
+
return async function load() {
|
|
2670
|
+
try {
|
|
2671
|
+
const result = await client.mounts({ init });
|
|
2672
|
+
if (result.kind !== "mounts") {
|
|
2673
|
+
lastKnownGood.delete(key);
|
|
2674
|
+
return NONE;
|
|
2457
2675
|
}
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
if (method === "DELETE") return body === void 0 ? { upstream: `/comments/${b}` } : void 0;
|
|
2466
|
-
const clean2 = pick(body, ["body"], ["body"]);
|
|
2467
|
-
return clean2 && isCommentText(clean2.body) ? { upstream: `/comments/${b}`, body: clean2 } : void 0;
|
|
2676
|
+
const loaded = { mounts: activeMounts(result.mounts), reserved: result.reserved, defaultLocale: result.default_locale };
|
|
2677
|
+
lastKnownGood.set(key, { loaded, at: Date.now() });
|
|
2678
|
+
return loaded;
|
|
2679
|
+
} catch (error) {
|
|
2680
|
+
if (isRejectedRequest(error)) {
|
|
2681
|
+
lastKnownGood.delete(key);
|
|
2682
|
+
return NONE;
|
|
2468
2683
|
}
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
return {
|
|
2473
|
-
action: (m) => m === "PUT" ? "reactions.add" : "reactions.remove",
|
|
2474
|
-
methods: ["PUT", "DELETE"],
|
|
2475
|
-
rebuild: (_method, body) => {
|
|
2476
|
-
const type = body?.subject_type;
|
|
2477
|
-
const clean2 = type === "article" ? pick(body, ["subject_type", "path"], ["subject_type", "path"]) : type === "comment" ? pick(body, ["subject_type", "comment_id"], ["subject_type", "comment_id"]) : void 0;
|
|
2478
|
-
if (!clean2) return void 0;
|
|
2479
|
-
const valid = type === "article" ? isSitePath2(clean2.path) : typeof clean2.comment_id === "string" && UUID2.test(clean2.comment_id);
|
|
2480
|
-
return valid ? { upstream: "/reactions", body: clean2 } : void 0;
|
|
2684
|
+
if (error instanceof Cp1ClientError && (error.status === 401 || error.status === 403)) {
|
|
2685
|
+
lastKnownGood.delete(key);
|
|
2686
|
+
throw error;
|
|
2481
2687
|
}
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
}
|
|
2486
|
-
|
|
2487
|
-
if (!body || Object.keys(body).some((k) => !allowed.includes(k)) || !required.every((k) => k in body)) return void 0;
|
|
2488
|
-
return Object.fromEntries(allowed.filter((k) => k in body).map((k) => [k, body[k]]));
|
|
2688
|
+
const kept = lastKnownGood.get(key);
|
|
2689
|
+
if (kept && Date.now() - kept.at <= MOUNTS_MAX_STALE_MS) return kept.loaded;
|
|
2690
|
+
throw error;
|
|
2691
|
+
}
|
|
2692
|
+
};
|
|
2489
2693
|
}
|
|
2490
|
-
|
|
2491
|
-
|
|
2694
|
+
var asArray = (options) => Array.isArray(options) ? options : [options];
|
|
2695
|
+
function setup(options) {
|
|
2696
|
+
const configs = asArray(options);
|
|
2697
|
+
if (configs.length === 0) throw new TypeError("hyleRootPage: pass at least one workspace config");
|
|
2698
|
+
const param = configs[0].param ?? "hyle";
|
|
2699
|
+
if (configs.some((c) => (c.param ?? "hyle") !== param)) throw new TypeError("hyleRootPage: every config must use the same `param`");
|
|
2700
|
+
return { configs, param, loaders: configs.map(mountsLoader) };
|
|
2492
2701
|
}
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
try {
|
|
2501
|
-
parsed = new URL(origin);
|
|
2502
|
-
} catch {
|
|
2503
|
-
return true;
|
|
2504
|
-
}
|
|
2505
|
-
if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
|
|
2506
|
-
if (allowedOrigins) return !allowedOrigins.some((o) => safeOrigin(o) === parsed.origin);
|
|
2507
|
-
const host = req.headers.get("x-forwarded-host")?.split(",")[0]?.trim() || req.headers.get("host") || new URL(req.url).host;
|
|
2508
|
-
const proto = req.headers.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase();
|
|
2509
|
-
if (proto && proto !== parsed.protocol.slice(0, -1)) return true;
|
|
2510
|
-
return parsed.host !== host;
|
|
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) };
|
|
2511
2709
|
}
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
if (Number(req.headers.get("content-length")) > MAX_BODY_BYTES2) return { kind: "refused", response: refuse(413, "PAYLOAD_TOO_LARGE") };
|
|
2523
|
-
if (!req.body) return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
2524
|
-
const reader = req.body.getReader();
|
|
2525
|
-
const chunks = [];
|
|
2526
|
-
let total = 0;
|
|
2527
|
-
for (; ; ) {
|
|
2528
|
-
const { done, value } = await reader.read();
|
|
2529
|
-
if (done) break;
|
|
2530
|
-
total += value.byteLength;
|
|
2531
|
-
if (total > MAX_BODY_BYTES2) {
|
|
2532
|
-
await reader.cancel().catch(() => {
|
|
2710
|
+
function rootMounts(options) {
|
|
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 };
|
|
2533
2720
|
});
|
|
2534
|
-
|
|
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;
|
|
2535
2732
|
}
|
|
2536
|
-
|
|
2537
|
-
}
|
|
2538
|
-
try {
|
|
2539
|
-
const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
2540
|
-
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return { kind: "ok", body: parsed };
|
|
2541
|
-
} catch {
|
|
2542
|
-
}
|
|
2543
|
-
return { kind: "refused", response: refuse(400, "VALIDATION_ERROR") };
|
|
2733
|
+
};
|
|
2544
2734
|
}
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2735
|
+
function createRouter(options, make) {
|
|
2736
|
+
const mounts = rootMounts(options);
|
|
2737
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
2738
|
+
return async function route(params) {
|
|
2739
|
+
const raw = params[mounts.param];
|
|
2740
|
+
const segments = typeof raw === "string" ? [raw] : raw;
|
|
2741
|
+
const path = sitePathFrom("", segments);
|
|
2742
|
+
if (path === void 0 || path === "/" || !segments) return void 0;
|
|
2743
|
+
const hit = await mounts.locate(path);
|
|
2744
|
+
if (!hit) return void 0;
|
|
2745
|
+
const { mount, index } = hit;
|
|
2746
|
+
const id = `${index}|${mount.prefix}|${mount.defaultSection}`;
|
|
2747
|
+
let handler = handlers.get(id);
|
|
2748
|
+
if (!handler) {
|
|
2749
|
+
handler = make(hit.options);
|
|
2750
|
+
handlers.set(id, handler);
|
|
2751
|
+
}
|
|
2752
|
+
return { handler, params: { ...params, [mounts.param]: segments.slice(mount.depth) } };
|
|
2753
|
+
};
|
|
2551
2754
|
}
|
|
2552
|
-
function
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
return refuse(429, "RATE_LIMITED", { "Retry-After": String(seconds) });
|
|
2560
|
-
}
|
|
2561
|
-
return refuse(502, "UPSTREAM_ERROR");
|
|
2755
|
+
function hyleRootPage(options) {
|
|
2756
|
+
const route = createRouter(options, hylePage);
|
|
2757
|
+
return async function HyleRootPage({ params, searchParams }) {
|
|
2758
|
+
const hit = await route(await params ?? {});
|
|
2759
|
+
if (!hit) (0, import_navigation5.notFound)();
|
|
2760
|
+
return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
|
|
2761
|
+
};
|
|
2562
2762
|
}
|
|
2563
|
-
function
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
const clearCache = () => {
|
|
2569
|
-
cache.clear();
|
|
2570
|
-
cacheBytes = 0;
|
|
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) : {};
|
|
2571
2768
|
};
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
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
|
+
}
|
|
2578
2776
|
}
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
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
|
+
}
|
|
2587
2819
|
}
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
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
|
+
}
|
|
2600
2845
|
}
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
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);
|
|
2613
2887
|
try {
|
|
2614
|
-
|
|
2615
|
-
checkBaseUrl(baseUrl);
|
|
2616
|
-
if (!options.token?.trim() || !options.workspaceId?.trim() || !options.signingKey) throw new TypeError("not provisioned");
|
|
2617
|
-
ready = { base: baseUrl.replace(/\/+$/, ""), key: engagementSigningKey(options.signingKey.trim()) };
|
|
2888
|
+
client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
|
|
2618
2889
|
} catch {
|
|
2619
|
-
|
|
2890
|
+
return empty(404);
|
|
2620
2891
|
}
|
|
2621
|
-
|
|
2622
|
-
}
|
|
2623
|
-
async function reader(req, config) {
|
|
2892
|
+
let upstream;
|
|
2624
2893
|
try {
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
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
|
+
});
|
|
2630
2898
|
} catch {
|
|
2631
|
-
return
|
|
2899
|
+
return empty(502);
|
|
2632
2900
|
}
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
const
|
|
2636
|
-
if (
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
if (!config || !route) return refuse(404, "NOT_FOUND");
|
|
2640
|
-
if (!route.methods.includes(req.method)) return refuse(405, "METHOD_NOT_ALLOWED", { Allow: route.methods.join(", ") });
|
|
2641
|
-
const write = req.method !== "GET";
|
|
2642
|
-
if (sameOriginProblem(req, write, options.allowedOrigins)) return refuse(403, "FORBIDDEN");
|
|
2643
|
-
if (options.onRequest) {
|
|
2644
|
-
try {
|
|
2645
|
-
const early = await options.onRequest(req, { action: route.action(req.method) });
|
|
2646
|
-
if (early instanceof Response) {
|
|
2647
|
-
const headers = new Headers(early.headers);
|
|
2648
|
-
headers.set("cache-control", "no-store");
|
|
2649
|
-
return new Response(early.body, { status: early.status, headers });
|
|
2650
|
-
}
|
|
2651
|
-
} catch {
|
|
2652
|
-
return refuse(502, "UPSTREAM_ERROR");
|
|
2653
|
-
}
|
|
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 } : {} } });
|
|
2654
2907
|
}
|
|
2655
|
-
if (
|
|
2656
|
-
|
|
2657
|
-
|
|
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 } : {});
|
|
2658
2912
|
}
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
if (
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
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);
|
|
2666
2919
|
}
|
|
2667
|
-
const
|
|
2668
|
-
|
|
2669
|
-
const
|
|
2670
|
-
if (
|
|
2671
|
-
|
|
2672
|
-
if (
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
const target = `${config.base}/cp1/engage${built.upstream}${built.query ? `?${built.query}` : ""}`;
|
|
2676
|
-
const call = async (withAssertion = assertion) => {
|
|
2677
|
-
const headers = new Headers(baseHeaders);
|
|
2678
|
-
if (withAssertion) headers.set("hyle-reader-assertion", withAssertion);
|
|
2679
|
-
const res = await fetchImpl(target, {
|
|
2680
|
-
method: req.method,
|
|
2681
|
-
headers,
|
|
2682
|
-
...built.body ? { body: JSON.stringify(built.body) } : {},
|
|
2683
|
-
redirect: "error",
|
|
2684
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS3)
|
|
2685
|
-
});
|
|
2686
|
-
return { status: res.status, ok: res.ok, text: await readCapped(res, MAX_RESPONSE_BYTES), retryAfter: res.headers.get("retry-after"), throttle: res.headers.get("hyle-throttle") };
|
|
2687
|
-
};
|
|
2688
|
-
try {
|
|
2689
|
-
const out = route.action(req.method) === "comments.list" ? await shared(`${viewer?.reader.sub ?? ""}
|
|
2690
|
-
${built.query.toString()}`, () => listing(viewer, call)) : await call();
|
|
2691
|
-
if (!out.ok) return relayFailure(out.status, out.retryAfter);
|
|
2692
|
-
if (write) clearCache();
|
|
2693
|
-
const data = JSON.parse(out.text).data;
|
|
2694
|
-
return typeof data === "object" && data !== null ? json(out.status === 201 ? 201 : 200, { data }) : refuse(502, "UPSTREAM_ERROR");
|
|
2695
|
-
} catch {
|
|
2696
|
-
return refuse(502, "UPSTREAM_ERROR");
|
|
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 });
|
|
2697
2928
|
}
|
|
2929
|
+
return new Response(capped(upstream.body, maxBytes), { status: upstream.status, headers });
|
|
2698
2930
|
}
|
|
2699
|
-
return { GET:
|
|
2931
|
+
return { GET: (req, ctx2) => serve(req, ctx2, false), HEAD: (req, ctx2) => serve(req, ctx2, true) };
|
|
2700
2932
|
}
|
|
2701
2933
|
|
|
2702
|
-
// src/next/
|
|
2703
|
-
var
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
} catch (error) {
|
|
2708
|
-
if (isRejectedRequest(error)) return {};
|
|
2709
|
-
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2710
|
-
return { failure: options.onError ? options.onError(error) : null };
|
|
2711
|
-
}
|
|
2712
|
-
}
|
|
2713
|
-
async function HyleList({ options, limit = 5, locale, layout, title, headingLevel, moreHref }) {
|
|
2714
|
-
const resolve = resolverFor(options);
|
|
2715
|
-
const route = routeContext(locale ? { ...options, locale } : options, {});
|
|
2716
|
-
const path = sitePathFrom(route.basePath, void 0);
|
|
2717
|
-
if (path === void 0) return null;
|
|
2718
|
-
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale, limit));
|
|
2719
|
-
if (failure !== void 0) return failure;
|
|
2720
|
-
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HyleListView, { items: result?.kind === "list" ? result.items : [], layout, title, headingLevel, moreHref, components: options.components, slots: options.slots, locale: route.locale, toHref: route.toHref });
|
|
2721
|
-
}
|
|
2722
|
-
async function HyleArticle({ options, path, locale, headingLevel }) {
|
|
2723
|
-
if (!isSitePath2(path)) return null;
|
|
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) {
|
|
2724
2939
|
const resolve = resolverFor(options);
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
}
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
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
|
+
);
|
|
2751
2972
|
}
|
|
2752
|
-
|
|
2753
|
-
const date = Date.parse(res.headers.get("date") ?? "");
|
|
2754
|
-
fetchedAt = Number.isFinite(date) ? date : void 0;
|
|
2755
|
-
} catch (error) {
|
|
2756
|
-
(0, import_navigation6.unstable_rethrow)(error);
|
|
2757
|
-
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
2758
|
-
return null;
|
|
2759
|
-
}
|
|
2760
|
-
if (!listing) return null;
|
|
2761
|
-
if (!interactive) return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HyleCommentsView, { listing, locale });
|
|
2762
|
-
const config = interactive === true ? {} : interactive;
|
|
2763
|
-
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "hyle hyle-embed", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_comments2.Comments, { path, endpoint: config.endpoint ?? "/api/hyle/engage", signInHref: config.signInHref, locale, labels: stringsFor(locale).comments, initial: listing, initialAt: fetchedAt }) });
|
|
2973
|
+
};
|
|
2764
2974
|
}
|
|
2765
2975
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2766
2976
|
0 && (module.exports = {
|
|
@@ -2774,9 +2984,11 @@ async function HyleComments({ options, path, revalidate = 60, interactive }) {
|
|
|
2774
2984
|
createEngagementRoute,
|
|
2775
2985
|
createLlmsTxtRoute,
|
|
2776
2986
|
createMarkdownRoute,
|
|
2987
|
+
createOgImageRoute,
|
|
2777
2988
|
createRevalidateRoute,
|
|
2778
2989
|
fetchResolver,
|
|
2779
2990
|
hyleFeed,
|
|
2991
|
+
hyleFeedLink,
|
|
2780
2992
|
hyleMetadata,
|
|
2781
2993
|
hylePage,
|
|
2782
2994
|
hyleRootMetadata,
|