reroute-js 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +7 -3
- package/cli/bin.d.ts +1 -1
- package/cli/bin.js +1618 -958
- package/cli/bin.js.map +38 -35
- package/cli/index.d.ts +1 -1
- package/cli/index.js +628 -40
- package/cli/index.js.map +53 -5
- package/cli/src/cli.d.ts +1 -1
- package/cli/src/commands/analyze.d.ts +1 -1
- package/cli/src/commands/analyze.d.ts.map +1 -1
- package/cli/src/commands/build.d.ts +2 -2
- package/cli/src/commands/dev.d.ts +6 -6
- package/cli/src/commands/dev.d.ts.map +1 -1
- package/cli/src/commands/gen.d.ts +4 -1
- package/cli/src/commands/gen.d.ts.map +1 -1
- package/cli/src/commands/index.d.ts +1 -1
- package/cli/src/commands/init.d.ts +1 -1
- package/cli/src/commands/lib/assets.d.ts +1 -1
- package/cli/src/commands/lib/bundler.d.ts +7 -1
- package/cli/src/commands/lib/bundler.d.ts.map +1 -1
- package/cli/src/commands/lib/command.d.ts +1 -1
- package/cli/src/commands/lib/env.d.ts +1 -1
- package/cli/src/commands/lib/index.d.ts +1 -1
- package/cli/src/commands/lib/log.d.ts +1 -1
- package/cli/src/commands/lib/markdown/availability.d.ts +1 -1
- package/cli/src/commands/lib/markdown/index.d.ts +1 -1
- package/cli/src/commands/lib/markdown/processor.d.ts +1 -1
- package/cli/src/commands/lib/production.d.ts +1 -1
- package/cli/src/commands/lib/server.d.ts +2 -1
- package/cli/src/commands/lib/server.d.ts.map +1 -1
- package/cli/src/commands/lib/streaming/analyzer.d.ts +1 -1
- package/cli/src/commands/lib/streaming/suspense.d.ts +2 -2
- package/cli/src/commands/lib/streaming/suspense.d.ts.map +1 -1
- package/cli/src/commands/lib/terminal-ui.d.ts +2 -2
- package/cli/src/commands/lib/terminal-ui.d.ts.map +1 -1
- package/cli/src/commands/lib/theme.d.ts +7 -4
- package/cli/src/commands/lib/theme.d.ts.map +1 -1
- package/cli/src/commands/lib/version.d.ts +1 -1
- package/cli/src/commands/lib/watch.d.ts +26 -0
- package/cli/src/commands/lib/watch.d.ts.map +1 -0
- package/cli/src/commands/og.d.ts +1 -1
- package/cli/src/commands/og.d.ts.map +1 -1
- package/cli/src/commands/start.d.ts +2 -2
- package/cli/src/commands/start.d.ts.map +1 -1
- package/cli/src/index.d.ts +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +712 -279
- package/core/index.js.map +25 -23
- package/core/src/app-paths.d.ts +32 -0
- package/core/src/app-paths.d.ts.map +1 -0
- package/core/src/bundler/hash.d.ts +1 -1
- package/core/src/bundler/index.d.ts +1 -1
- package/core/src/config.d.ts +51 -7
- package/core/src/config.d.ts.map +1 -1
- package/core/src/content/discovery.d.ts +1 -1
- package/core/src/content/index.d.ts +1 -1
- package/core/src/content/metadata.d.ts +1 -1
- package/core/src/i18n/catalog.d.ts +1 -1
- package/core/src/i18n/discover.d.ts +1 -1
- package/core/src/i18n/index.d.ts +1 -1
- package/core/src/i18n/messages.d.ts +1 -1
- package/core/src/i18n/negotiate.d.ts +1 -1
- package/core/src/i18n/pathname.d.ts +1 -1
- package/core/src/i18n/resolve.d.ts +4 -3
- package/core/src/i18n/resolve.d.ts.map +1 -1
- package/core/src/i18n/types.d.ts +5 -1
- package/core/src/i18n/types.d.ts.map +1 -1
- package/core/src/index.d.ts +2 -1
- package/core/src/index.d.ts.map +1 -1
- package/core/src/llms/discovery.d.ts +35 -0
- package/core/src/llms/discovery.d.ts.map +1 -0
- package/core/src/llms/extractor.d.ts +6 -1
- package/core/src/llms/extractor.d.ts.map +1 -1
- package/core/src/llms/formatter.d.ts +1 -1
- package/core/src/llms/formatter.d.ts.map +1 -1
- package/core/src/llms/full-generator.d.ts +3 -1
- package/core/src/llms/full-generator.d.ts.map +1 -1
- package/core/src/llms/index-generator.d.ts +6 -3
- package/core/src/llms/index-generator.d.ts.map +1 -1
- package/core/src/llms/index.d.ts +5 -2
- package/core/src/llms/index.d.ts.map +1 -1
- package/core/src/og/discovery.d.ts +1 -1
- package/core/src/og/index.d.ts +1 -1
- package/core/src/og/meta.d.ts +1 -1
- package/core/src/og/render.d.ts +1 -1
- package/core/src/og/types.d.ts +1 -1
- package/core/src/robots/discovery.d.ts +1 -1
- package/core/src/robots/generator.d.ts +1 -1
- package/core/src/robots/generator.d.ts.map +1 -1
- package/core/src/robots/index.d.ts +1 -1
- package/core/src/robots/policies.d.ts +1 -1
- package/core/src/rss/discovery.d.ts +2 -2
- package/core/src/rss/discovery.d.ts.map +1 -1
- package/core/src/rss/generator.d.ts +1 -1
- package/core/src/rss/index.d.ts +1 -1
- package/core/src/sitemap/discovery.d.ts +7 -2
- package/core/src/sitemap/discovery.d.ts.map +1 -1
- package/core/src/sitemap/generator.d.ts +1 -1
- package/core/src/sitemap/index.d.ts +1 -1
- package/core/src/ssr/index.d.ts +1 -1
- package/core/src/ssr/lib/cache.d.ts +1 -1
- package/core/src/ssr/lib/cleanup.d.ts +1 -1
- package/core/src/ssr/lib/collections.d.ts +17 -1
- package/core/src/ssr/lib/collections.d.ts.map +1 -1
- package/core/src/ssr/lib/compression.d.ts +1 -1
- package/core/src/ssr/lib/compute/content.d.ts +1 -1
- package/core/src/ssr/lib/compute/index.d.ts +1 -1
- package/core/src/ssr/lib/compute/layouts.d.ts +1 -1
- package/core/src/ssr/lib/compute/routes.d.ts +1 -1
- package/core/src/ssr/lib/content-path.d.ts +1 -1
- package/core/src/ssr/lib/data.d.ts +1 -1
- package/core/src/ssr/lib/html.d.ts +1 -1
- package/core/src/ssr/lib/imports.d.ts +8 -3
- package/core/src/ssr/lib/imports.d.ts.map +1 -1
- package/core/src/ssr/lib/index.d.ts +1 -1
- package/core/src/ssr/lib/layouts.d.ts +1 -1
- package/core/src/ssr/lib/metadata.d.ts +1 -1
- package/core/src/ssr/lib/mime.d.ts +1 -1
- package/core/src/ssr/lib/modules.d.ts +1 -1
- package/core/src/ssr/lib/path.d.ts +1 -1
- package/core/src/ssr/lib/preload.d.ts +1 -1
- package/core/src/ssr/lib/route-match.d.ts +1 -1
- package/core/src/ssr/lib/scripts/collections.d.ts +2 -2
- package/core/src/ssr/lib/scripts/collections.d.ts.map +1 -1
- package/core/src/ssr/lib/scripts/data.d.ts +1 -1
- package/core/src/ssr/lib/scripts/escape.d.ts +1 -1
- package/core/src/ssr/lib/scripts/feeds.d.ts +1 -1
- package/core/src/ssr/lib/scripts/index.d.ts +1 -1
- package/core/src/ssr/lib/seed.d.ts +6 -1
- package/core/src/ssr/lib/seed.d.ts.map +1 -1
- package/core/src/ssr/lib/serialize.d.ts +1 -1
- package/core/src/ssr/lib/setup.d.ts +2 -2
- package/core/src/ssr/lib/setup.d.ts.map +1 -1
- package/core/src/ssr/lib/styles.d.ts +5 -4
- package/core/src/ssr/lib/styles.d.ts.map +1 -1
- package/core/src/ssr/lib/template.d.ts +1 -1
- package/core/src/ssr/lib/types.d.ts +15 -1
- package/core/src/ssr/lib/types.d.ts.map +1 -1
- package/core/src/ssr/render.d.ts +1 -1
- package/core/src/ssr/render.d.ts.map +1 -1
- package/core/src/ssr/stream.d.ts +1 -1
- package/core/src/ssr/stream.d.ts.map +1 -1
- package/elysia/index.d.ts +1 -1
- package/elysia/index.js +971 -432
- package/elysia/index.js.map +38 -33
- package/elysia/src/index.d.ts +1 -1
- package/elysia/src/libs/assets.d.ts +1 -1
- package/elysia/src/libs/cache.d.ts +6 -1
- package/elysia/src/libs/cache.d.ts.map +1 -1
- package/elysia/src/libs/caching.d.ts +1 -1
- package/elysia/src/libs/http.d.ts +1 -1
- package/elysia/src/libs/i18n.d.ts +2 -2
- package/elysia/src/libs/i18n.d.ts.map +1 -1
- package/elysia/src/libs/image.d.ts +1 -1
- package/elysia/src/libs/index.d.ts +1 -1
- package/elysia/src/libs/llms.d.ts +1 -1
- package/elysia/src/libs/response.d.ts +1 -1
- package/elysia/src/libs/serving.d.ts +1 -1
- package/elysia/src/plugin.d.ts +1 -1
- package/elysia/src/plugin.d.ts.map +1 -1
- package/elysia/src/routes/artifacts.d.ts +1 -1
- package/elysia/src/routes/artifacts.d.ts.map +1 -1
- package/elysia/src/routes/content.d.ts +2 -2
- package/elysia/src/routes/content.d.ts.map +1 -1
- package/elysia/src/routes/image.d.ts +1 -1
- package/elysia/src/routes/index.d.ts +1 -1
- package/elysia/src/routes/internal.d.ts +1 -1
- package/elysia/src/routes/internal.d.ts.map +1 -1
- package/elysia/src/routes/liveReloadClient.d.ts +16 -0
- package/elysia/src/routes/liveReloadClient.d.ts.map +1 -0
- package/elysia/src/routes/llms.d.ts +1 -1
- package/elysia/src/routes/llms.d.ts.map +1 -1
- package/elysia/src/routes/og.d.ts +1 -1
- package/elysia/src/routes/redirects.d.ts +1 -1
- package/elysia/src/routes/robots.d.ts +3 -1
- package/elysia/src/routes/robots.d.ts.map +1 -1
- package/elysia/src/routes/rss.d.ts +1 -1
- package/elysia/src/routes/search.d.ts +1 -1
- package/elysia/src/routes/sitemap.d.ts +3 -1
- package/elysia/src/routes/sitemap.d.ts.map +1 -1
- package/elysia/src/routes/ssr.d.ts +4 -2
- package/elysia/src/routes/ssr.d.ts.map +1 -1
- package/elysia/src/routes/static.d.ts +1 -1
- package/elysia/src/routes/themeCssRefresh.d.ts +17 -0
- package/elysia/src/routes/themeCssRefresh.d.ts.map +1 -0
- package/elysia/src/types.d.ts +1 -1
- package/package.json +1 -1
- package/react/index.d.ts +1 -1
- package/react/index.js +203 -107
- package/react/index.js.map +8 -7
- package/react/src/components/ClientOnly.d.ts +1 -1
- package/react/src/components/ContentRoute.d.ts +1 -1
- package/react/src/components/Image.d.ts +1 -1
- package/react/src/components/LazyRoute.d.ts +1 -1
- package/react/src/components/Link.d.ts +1 -1
- package/react/src/components/Markdown.d.ts +1 -1
- package/react/src/components/Outlet.d.ts +1 -1
- package/react/src/components/index.d.ts +1 -1
- package/react/src/hooks/index.d.ts +1 -1
- package/react/src/hooks/useContent.d.ts +1 -1
- package/react/src/hooks/useContent.d.ts.map +1 -1
- package/react/src/hooks/useData.d.ts +1 -1
- package/react/src/hooks/useFeed.d.ts +1 -1
- package/react/src/hooks/useLayoutData.d.ts +1 -1
- package/react/src/hooks/useLlms.d.ts +1 -1
- package/react/src/hooks/useNavigate.d.ts +1 -1
- package/react/src/hooks/useParams.d.ts +1 -1
- package/react/src/hooks/useRouter.d.ts +1 -1
- package/react/src/hooks/useSearch.d.ts +1 -1
- package/react/src/hooks/useSearchParams.d.ts +1 -1
- package/react/src/hooks/useToc.d.ts +1 -1
- package/react/src/i18n/LocaleProvider.d.ts +1 -1
- package/react/src/i18n/LocaleProvider.d.ts.map +1 -1
- package/react/src/i18n/helpers.d.ts +1 -1
- package/react/src/i18n/index.d.ts +1 -1
- package/react/src/index.d.ts +1 -1
- package/react/src/lib/bundle.d.ts +27 -0
- package/react/src/lib/bundle.d.ts.map +1 -0
- package/react/src/lib/collection.d.ts +1 -1
- package/react/src/lib/content.d.ts +1 -1
- package/react/src/lib/head.d.ts +1 -1
- package/react/src/lib/index.d.ts +2 -1
- package/react/src/lib/index.d.ts.map +1 -1
- package/react/src/lib/lazy-route.d.ts +7 -21
- package/react/src/lib/lazy-route.d.ts.map +1 -1
- package/react/src/lib/route-loader.d.ts +1 -1
- package/react/src/providers/ContentProvider.d.ts +1 -1
- package/react/src/providers/RerouteProvider.d.ts +2 -2
- package/react/src/providers/RerouteProvider.d.ts.map +1 -1
- package/react/src/providers/RouterProvider.d.ts +1 -1
- package/react/src/providers/index.d.ts +1 -1
- package/react/src/types/any.d.ts +1 -1
- package/react/src/types/index.d.ts +1 -1
- package/react/src/types/router.d.ts +1 -1
- package/telemetry/react.d.ts +1 -1
- package/telemetry/react.js +16 -16
- package/telemetry/react.js.map +2 -2
- package/telemetry/server.d.ts +1 -1
- package/telemetry/server.js +60 -228
- package/telemetry/server.js.map +20 -16
- package/telemetry/src/react/api.d.ts +1 -1
- package/telemetry/src/react/context.d.ts +1 -1
- package/telemetry/src/react/index.d.ts +1 -1
- package/telemetry/src/react/telemetry.d.ts +1 -1
- package/telemetry/src/server/context.d.ts +1 -1
- package/telemetry/src/server/headers/extractor.d.ts +1 -1
- package/telemetry/src/server/headers/index.d.ts +1 -1
- package/telemetry/src/server/headers/presets.d.ts +1 -1
- package/telemetry/src/server/index.d.ts +1 -1
- package/telemetry/src/server/instrumentation.d.ts +1 -1
- package/telemetry/src/server/plugin.d.ts +1 -1
- package/telemetry/src/server/sourcemap.d.ts +1 -1
package/elysia/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* reroute-js v1.0.0-alpha.
|
|
2
|
+
* reroute-js v1.0.0-alpha.21
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2026 stewones <hi@stewan.io>
|
|
@@ -25,6 +25,31 @@ var __export = (target, all) => {
|
|
|
25
25
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
26
26
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
27
27
|
|
|
28
|
+
// packages/core/src/app-paths.ts
|
|
29
|
+
import { posix } from "node:path";
|
|
30
|
+
function toPosix(p) {
|
|
31
|
+
return p.replace(/\\/g, "/");
|
|
32
|
+
}
|
|
33
|
+
function resolveAppPaths(config = {}) {
|
|
34
|
+
const src = config.app?.src ?? DEFAULT_APP_SRC;
|
|
35
|
+
const server = config.app?.server ?? DEFAULT_APP_SERVER;
|
|
36
|
+
const clientDir = toPosix(posix.dirname(src));
|
|
37
|
+
return {
|
|
38
|
+
src,
|
|
39
|
+
clientDir,
|
|
40
|
+
routesDir: toPosix(posix.join(clientDir, "routes")),
|
|
41
|
+
cssEntry: toPosix(posix.join(clientDir, "index.css")),
|
|
42
|
+
assetsDir: toPosix(posix.join(clientDir, "assets")),
|
|
43
|
+
server
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function importFromReroute(relPath) {
|
|
47
|
+
const cleaned = toPosix(relPath).replace(/^\.\//, "").replace(/\.(tsx|ts|jsx|js)$/, "");
|
|
48
|
+
return `../${cleaned}`;
|
|
49
|
+
}
|
|
50
|
+
var DEFAULT_APP_SRC = "./src/client/App", DEFAULT_APP_SERVER = "./src/index.ts";
|
|
51
|
+
var init_app_paths = () => {};
|
|
52
|
+
|
|
28
53
|
// packages/core/src/bundler/hash.ts
|
|
29
54
|
async function generateContentHash(content) {
|
|
30
55
|
const data = new TextEncoder().encode(content);
|
|
@@ -390,14 +415,14 @@ var init_negotiate = () => {};
|
|
|
390
415
|
// packages/core/src/i18n/pathname.ts
|
|
391
416
|
var exports_pathname = {};
|
|
392
417
|
__export(exports_pathname, {
|
|
393
|
-
|
|
394
|
-
parseContentPath: () => parseContentPath,
|
|
395
|
-
normalizePathname: () => normalizePathname,
|
|
396
|
-
looksLikeLocale: () => looksLikeLocale,
|
|
397
|
-
localizeHref: () => localizeHref,
|
|
398
|
-
localizeContentHref: () => localizeContentHref,
|
|
418
|
+
contentKey: () => contentKey,
|
|
399
419
|
hreflangTags: () => hreflangTags,
|
|
400
|
-
|
|
420
|
+
localizeContentHref: () => localizeContentHref,
|
|
421
|
+
localizeHref: () => localizeHref,
|
|
422
|
+
looksLikeLocale: () => looksLikeLocale,
|
|
423
|
+
normalizePathname: () => normalizePathname,
|
|
424
|
+
parseContentPath: () => parseContentPath,
|
|
425
|
+
toOgLocale: () => toOgLocale
|
|
401
426
|
});
|
|
402
427
|
function looksLikeLocale(segment) {
|
|
403
428
|
return /^[a-z]{2}(?:-[A-Za-z0-9]{2,8})*$/i.test(segment);
|
|
@@ -480,9 +505,30 @@ function hreflangTags(baseUrl, collection, name, locales, defaultLocale) {
|
|
|
480
505
|
var init_pathname = () => {};
|
|
481
506
|
|
|
482
507
|
// packages/core/src/i18n/resolve.ts
|
|
508
|
+
function canonicalLocale(value, availableLocales) {
|
|
509
|
+
return availableLocales.find((l) => l.toLowerCase() === value.toLowerCase()) || value;
|
|
510
|
+
}
|
|
511
|
+
function parseLangParam(search, isAvailable, availableLocales) {
|
|
512
|
+
if (!search)
|
|
513
|
+
return;
|
|
514
|
+
const params = new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
|
|
515
|
+
const raw = params.get("lang") ?? undefined;
|
|
516
|
+
if (!isAvailable(raw))
|
|
517
|
+
return;
|
|
518
|
+
return canonicalLocale(raw, availableLocales);
|
|
519
|
+
}
|
|
520
|
+
function stripLangParam(search) {
|
|
521
|
+
if (!search)
|
|
522
|
+
return "";
|
|
523
|
+
const params = new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
|
|
524
|
+
params.delete("lang");
|
|
525
|
+
const rest = params.toString();
|
|
526
|
+
return rest ? `?${rest}` : "";
|
|
527
|
+
}
|
|
483
528
|
function resolveLocale(input) {
|
|
484
529
|
const {
|
|
485
530
|
pathname,
|
|
531
|
+
search,
|
|
486
532
|
cookieHeader,
|
|
487
533
|
acceptLanguage,
|
|
488
534
|
availableLocales,
|
|
@@ -493,14 +539,32 @@ function resolveLocale(input) {
|
|
|
493
539
|
const parsed = parseContentPath(pathname, availableLocales, collections);
|
|
494
540
|
const availableLower = new Set(availableLocales.map((l) => l.toLowerCase()));
|
|
495
541
|
const isAvailable = (locale) => !!locale && availableLower.has(locale.toLowerCase());
|
|
542
|
+
const routingPathname = parsed?.routingPathname ?? pathname.split("?")[0];
|
|
543
|
+
const restSearch = stripLangParam(search);
|
|
544
|
+
const queryLocale = parseLangParam(search, isAvailable, availableLocales);
|
|
545
|
+
if (queryLocale) {
|
|
546
|
+
const target = parsed ? localizeContentHref(parsed.collection, parsed.name, queryLocale, defaultLocale) : routingPathname;
|
|
547
|
+
return {
|
|
548
|
+
locale: queryLocale,
|
|
549
|
+
routingPathname,
|
|
550
|
+
fromPath: false,
|
|
551
|
+
fromQuery: true,
|
|
552
|
+
redirectTo: `${target}${restSearch}`,
|
|
553
|
+
parsed: parsed ? {
|
|
554
|
+
...parsed,
|
|
555
|
+
locale: queryLocale === defaultLocale ? undefined : queryLocale
|
|
556
|
+
} : undefined
|
|
557
|
+
};
|
|
558
|
+
}
|
|
496
559
|
if (parsed?.locale && isAvailable(parsed.locale)) {
|
|
497
|
-
const locale =
|
|
560
|
+
const locale = canonicalLocale(parsed.locale, availableLocales);
|
|
498
561
|
if (locale === defaultLocale && parsed.pathname !== parsed.routingPathname) {
|
|
499
562
|
return {
|
|
500
563
|
locale,
|
|
501
564
|
routingPathname: parsed.routingPathname,
|
|
502
565
|
fromPath: true,
|
|
503
|
-
|
|
566
|
+
fromQuery: false,
|
|
567
|
+
redirectTo: `${parsed.routingPathname}${restSearch}`,
|
|
504
568
|
parsed: { ...parsed, locale }
|
|
505
569
|
};
|
|
506
570
|
}
|
|
@@ -508,17 +572,18 @@ function resolveLocale(input) {
|
|
|
508
572
|
locale,
|
|
509
573
|
routingPathname: parsed.routingPathname,
|
|
510
574
|
fromPath: true,
|
|
575
|
+
fromQuery: false,
|
|
511
576
|
parsed: { ...parsed, locale }
|
|
512
577
|
};
|
|
513
578
|
}
|
|
514
|
-
const routingPathname = parsed?.routingPathname ?? pathname.split("?")[0];
|
|
515
579
|
const cookieLocale = parseCookieValue(cookieHeader, cookieName);
|
|
516
580
|
if (isAvailable(cookieLocale)) {
|
|
517
|
-
const locale =
|
|
581
|
+
const locale = canonicalLocale(cookieLocale, availableLocales);
|
|
518
582
|
return {
|
|
519
583
|
locale,
|
|
520
584
|
routingPathname,
|
|
521
585
|
fromPath: false,
|
|
586
|
+
fromQuery: false,
|
|
522
587
|
parsed: parsed ? { ...parsed, locale: undefined } : undefined
|
|
523
588
|
};
|
|
524
589
|
}
|
|
@@ -527,13 +592,14 @@ function resolveLocale(input) {
|
|
|
527
592
|
locale: negotiated,
|
|
528
593
|
routingPathname,
|
|
529
594
|
fromPath: false,
|
|
595
|
+
fromQuery: false,
|
|
530
596
|
parsed: parsed ? { ...parsed, locale: undefined } : undefined
|
|
531
597
|
};
|
|
532
598
|
}
|
|
533
599
|
function contentNegotiateRedirect(resolution, defaultLocale, enabled) {
|
|
534
600
|
if (!enabled)
|
|
535
601
|
return;
|
|
536
|
-
if (resolution.fromPath)
|
|
602
|
+
if (resolution.fromPath || resolution.fromQuery)
|
|
537
603
|
return;
|
|
538
604
|
if (resolution.locale === defaultLocale)
|
|
539
605
|
return;
|
|
@@ -1049,11 +1115,39 @@ function cleanupPathScopedSSRData(pathname) {
|
|
|
1049
1115
|
}
|
|
1050
1116
|
|
|
1051
1117
|
// packages/core/src/ssr/lib/imports.ts
|
|
1118
|
+
import { copyFile, realpath, stat as stat3, unlink } from "node:fs/promises";
|
|
1119
|
+
import { basename as basename2, dirname, extname as extname2, join as join3 } from "node:path";
|
|
1052
1120
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
1121
|
+
function clearWatchImportCache() {
|
|
1122
|
+
watchImportCache.clear();
|
|
1123
|
+
}
|
|
1124
|
+
function bustCopyPath(absolutePath) {
|
|
1125
|
+
const dir = dirname(absolutePath);
|
|
1126
|
+
const ext = extname2(absolutePath);
|
|
1127
|
+
const base = basename2(absolutePath, ext);
|
|
1128
|
+
const token = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
1129
|
+
return join3(dir, `${base}.bust-${token}${ext}`);
|
|
1130
|
+
}
|
|
1053
1131
|
async function dynamicImport(absolutePath, isWatchMode) {
|
|
1054
1132
|
const href = pathToFileURL3(absolutePath).href;
|
|
1055
|
-
|
|
1056
|
-
|
|
1133
|
+
if (!isWatchMode) {
|
|
1134
|
+
return await import(href);
|
|
1135
|
+
}
|
|
1136
|
+
const resolved = await realpath(absolutePath);
|
|
1137
|
+
const mtimeMs = (await stat3(resolved)).mtimeMs;
|
|
1138
|
+
const cached = watchImportCache.get(resolved);
|
|
1139
|
+
if (cached && cached.mtimeMs === mtimeMs) {
|
|
1140
|
+
return cached.mod;
|
|
1141
|
+
}
|
|
1142
|
+
const tmp = bustCopyPath(resolved);
|
|
1143
|
+
await copyFile(resolved, tmp);
|
|
1144
|
+
try {
|
|
1145
|
+
const mod = await import(pathToFileURL3(tmp).href);
|
|
1146
|
+
watchImportCache.set(resolved, { mtimeMs, mod });
|
|
1147
|
+
return mod;
|
|
1148
|
+
} finally {
|
|
1149
|
+
await unlink(tmp).catch(() => {});
|
|
1150
|
+
}
|
|
1057
1151
|
}
|
|
1058
1152
|
function isThenable(value) {
|
|
1059
1153
|
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
@@ -1061,7 +1155,10 @@ function isThenable(value) {
|
|
|
1061
1155
|
function toPromise(input) {
|
|
1062
1156
|
return input instanceof Promise ? input : Promise.resolve(input);
|
|
1063
1157
|
}
|
|
1064
|
-
var
|
|
1158
|
+
var watchImportCache;
|
|
1159
|
+
var init_imports = __esm(() => {
|
|
1160
|
+
watchImportCache = new Map;
|
|
1161
|
+
});
|
|
1065
1162
|
|
|
1066
1163
|
// packages/core/src/ssr/lib/collections.ts
|
|
1067
1164
|
async function loadCollections(cwd, isWatchMode) {
|
|
@@ -1078,6 +1175,21 @@ function setGlobalCollections(byCollectionForSSR) {
|
|
|
1078
1175
|
globalThis.__REROUTE_COLLECTIONS__ = byCollectionForSSR;
|
|
1079
1176
|
} catch {}
|
|
1080
1177
|
}
|
|
1178
|
+
function resetSSRContentResults() {
|
|
1179
|
+
try {
|
|
1180
|
+
globalThis.__REROUTE_SSR_RESULTS__ = {};
|
|
1181
|
+
} catch {}
|
|
1182
|
+
}
|
|
1183
|
+
function takeSSRContentResults() {
|
|
1184
|
+
try {
|
|
1185
|
+
const g = globalThis;
|
|
1186
|
+
const results = g.__REROUTE_SSR_RESULTS__;
|
|
1187
|
+
g.__REROUTE_SSR_RESULTS__ = {};
|
|
1188
|
+
return results;
|
|
1189
|
+
} catch {
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1081
1193
|
var init_collections = __esm(() => {
|
|
1082
1194
|
init_imports();
|
|
1083
1195
|
});
|
|
@@ -1851,7 +1963,7 @@ var init_compute = __esm(() => {
|
|
|
1851
1963
|
});
|
|
1852
1964
|
|
|
1853
1965
|
// packages/core/src/ssr/lib/modules.ts
|
|
1854
|
-
import { readdir as readdir3, stat as
|
|
1966
|
+
import { readdir as readdir3, stat as stat4 } from "node:fs/promises";
|
|
1855
1967
|
async function importContentModuleForPath(pathname, clientDir, cwd, isWatchMode) {
|
|
1856
1968
|
try {
|
|
1857
1969
|
const resolved = resolveContentPathParts(pathname);
|
|
@@ -1909,7 +2021,7 @@ async function tryChunkImport(collection, name, cwd, isWatchMode) {
|
|
|
1909
2021
|
let latestM = 0;
|
|
1910
2022
|
for (const f of matches) {
|
|
1911
2023
|
try {
|
|
1912
|
-
const s = await
|
|
2024
|
+
const s = await stat4(join(chunkDir, f));
|
|
1913
2025
|
if (s.mtimeMs >= latestM) {
|
|
1914
2026
|
latestM = s.mtimeMs;
|
|
1915
2027
|
latest = f;
|
|
@@ -1966,6 +2078,16 @@ function touchModule(key) {
|
|
|
1966
2078
|
evictLRUModule();
|
|
1967
2079
|
}
|
|
1968
2080
|
}
|
|
2081
|
+
function clearSSRModuleStores() {
|
|
2082
|
+
const g = globalThis;
|
|
2083
|
+
if (g.__REROUTE_SSR_MODULES__) {
|
|
2084
|
+
g.__REROUTE_SSR_MODULES__ = {};
|
|
2085
|
+
}
|
|
2086
|
+
if (g.__REROUTE_SSR_EXPORTS__) {
|
|
2087
|
+
g.__REROUTE_SSR_EXPORTS__ = {};
|
|
2088
|
+
}
|
|
2089
|
+
moduleAccessOrder.length = 0;
|
|
2090
|
+
}
|
|
1969
2091
|
async function seedSSRModuleForPath(pathname, clientDir, cwd, isWatchMode) {
|
|
1970
2092
|
try {
|
|
1971
2093
|
const resolved = resolveContentPathParts(pathname);
|
|
@@ -2950,7 +3072,7 @@ var init_metadata2 = __esm(() => {
|
|
|
2950
3072
|
});
|
|
2951
3073
|
|
|
2952
3074
|
// packages/core/src/ssr/lib/preload.ts
|
|
2953
|
-
import { readdir as readdir5, stat as
|
|
3075
|
+
import { readdir as readdir5, stat as stat5 } from "node:fs/promises";
|
|
2954
3076
|
async function preloadContentModule(pathname, clientDir, cwd, isWatchMode) {
|
|
2955
3077
|
let extraHead = "";
|
|
2956
3078
|
let hydrationScript = "";
|
|
@@ -2984,14 +3106,14 @@ async function isContentCollection(clientDir, collection) {
|
|
|
2984
3106
|
if (isProduction) {
|
|
2985
3107
|
const collectionFile = join(clientDir, "collections", `${collection}.js`);
|
|
2986
3108
|
try {
|
|
2987
|
-
const s2 = await
|
|
3109
|
+
const s2 = await stat5(collectionFile);
|
|
2988
3110
|
return s2?.isFile() ?? false;
|
|
2989
3111
|
} catch {
|
|
2990
3112
|
return false;
|
|
2991
3113
|
}
|
|
2992
3114
|
}
|
|
2993
3115
|
const maybeDir = join(clientDir, "routes", collection, "content");
|
|
2994
|
-
const s = await
|
|
3116
|
+
const s = await stat5(maybeDir);
|
|
2995
3117
|
return typeof s?.isDirectory === "function" ? s.isDirectory() : true;
|
|
2996
3118
|
} catch {
|
|
2997
3119
|
return false;
|
|
@@ -3002,7 +3124,7 @@ async function findLatestCandidate(chunkDir, candidates) {
|
|
|
3002
3124
|
let latestM = 0;
|
|
3003
3125
|
for (const candidateName of candidates) {
|
|
3004
3126
|
try {
|
|
3005
|
-
const s = await
|
|
3127
|
+
const s = await stat5(join(chunkDir, candidateName));
|
|
3006
3128
|
if (s.mtimeMs >= latestM) {
|
|
3007
3129
|
latestM = s.mtimeMs;
|
|
3008
3130
|
latest = candidateName;
|
|
@@ -3188,23 +3310,34 @@ function parseAccessTracking(accessedCollections) {
|
|
|
3188
3310
|
}
|
|
3189
3311
|
return usage;
|
|
3190
3312
|
}
|
|
3191
|
-
function
|
|
3313
|
+
function processCapturedResults(capturedResults, byCollectionForSSR) {
|
|
3192
3314
|
const subset = {};
|
|
3193
3315
|
const partial = {};
|
|
3194
3316
|
try {
|
|
3195
3317
|
const g = globalThis;
|
|
3196
|
-
const ssrResults = g.__REROUTE_SSR_RESULTS__;
|
|
3197
|
-
if (ssrResults
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3318
|
+
const ssrResults = capturedResults ?? g.__REROUTE_SSR_RESULTS__;
|
|
3319
|
+
if (!ssrResults || typeof ssrResults !== "object")
|
|
3320
|
+
return;
|
|
3321
|
+
for (const [collection, items] of Object.entries(ssrResults)) {
|
|
3322
|
+
if (Array.isArray(items) && items.length > 0) {
|
|
3323
|
+
subset[collection] = items;
|
|
3324
|
+
const full = byCollectionForSSR?.[collection] || [];
|
|
3325
|
+
partial[collection] = items.length < full.length;
|
|
3204
3326
|
}
|
|
3205
|
-
return { subset, partial };
|
|
3206
3327
|
}
|
|
3207
|
-
} catch {
|
|
3328
|
+
} catch {
|
|
3329
|
+
return;
|
|
3330
|
+
}
|
|
3331
|
+
if (Object.keys(subset).length === 0)
|
|
3332
|
+
return;
|
|
3333
|
+
return { subset, partial };
|
|
3334
|
+
}
|
|
3335
|
+
function processCollections(accessedCollections, byCollectionForSSR, capturedResults) {
|
|
3336
|
+
const captured = processCapturedResults(capturedResults, byCollectionForSSR);
|
|
3337
|
+
if (captured)
|
|
3338
|
+
return captured;
|
|
3339
|
+
const subset = {};
|
|
3340
|
+
const partial = {};
|
|
3208
3341
|
const sortByDate = (order) => (a, b) => {
|
|
3209
3342
|
const da = a?.meta?.date ? Date.parse(String(a.meta.date)) : 0;
|
|
3210
3343
|
const db = b?.meta?.date ? Date.parse(String(b.meta.date)) : 0;
|
|
@@ -3251,7 +3384,7 @@ function createI18nScript(i18n) {
|
|
|
3251
3384
|
}
|
|
3252
3385
|
}
|
|
3253
3386
|
function createContentCaptureScript() {
|
|
3254
|
-
return `<script>(function(){try{var w=window;w.__REROUTE_INITIAL_HYDRATION__=true;var h={};document.querySelectorAll('[data-reroute-key]').forEach(function(el){var k=el.getAttribute('data-reroute-key');if(k)h[k]=el.innerHTML;});w.__REROUTE_CONTENT_HTML__=h;var r=document.querySelector('[data-reroute-route="ssr"]');if(r)w.__REROUTE_ROUTE_HTML__=r.innerHTML;}catch(e){}})();</script>`;
|
|
3387
|
+
return `<script>(function(){try{var w=window;w.__REROUTE_INITIAL_HYDRATION__=true;var h={};document.querySelectorAll('[data-reroute-key]').forEach(function(el){var k=el.getAttribute('data-reroute-key');if(k)h[k]=el.innerHTML;});w.__REROUTE_CONTENT_HTML__=h;var r=document.querySelector('[data-reroute-route="ssr"]');if(r){w.__REROUTE_ROUTE_HTML__=r.innerHTML;}else{var root=document.getElementById('root');if(root)w.__REROUTE_ROUTE_HTML__=root.innerHTML;}}catch(e){}})();</script>`;
|
|
3255
3388
|
}
|
|
3256
3389
|
function createSSRExportsScript(pathname) {
|
|
3257
3390
|
try {
|
|
@@ -3388,43 +3521,73 @@ var init_scripts = __esm(() => {
|
|
|
3388
3521
|
});
|
|
3389
3522
|
|
|
3390
3523
|
// packages/core/src/ssr/lib/styles.ts
|
|
3391
|
-
|
|
3524
|
+
import { createHash } from "node:crypto";
|
|
3525
|
+
import { readdirSync } from "node:fs";
|
|
3526
|
+
function themeCssHash(css) {
|
|
3527
|
+
return createHash("sha1").update(css).digest("hex").slice(0, 8);
|
|
3528
|
+
}
|
|
3529
|
+
function themeCssFileName(css) {
|
|
3530
|
+
return `index.${themeCssHash(css)}.css`;
|
|
3531
|
+
}
|
|
3532
|
+
function themeLink(href) {
|
|
3533
|
+
return `<link rel="stylesheet" href="${href}" data-reroute="theme">`;
|
|
3534
|
+
}
|
|
3535
|
+
function bundlesDirs(clientDir) {
|
|
3536
|
+
return [
|
|
3537
|
+
join(clientDir, "..", ".reroute", "bundles"),
|
|
3538
|
+
join(clientDir, "..", "..", ".reroute", "bundles"),
|
|
3539
|
+
join(clientDir, "..", "..", "..", ".reroute", "bundles"),
|
|
3540
|
+
join(clientDir, "..", "..", "..", "..", ".reroute", "bundles")
|
|
3541
|
+
];
|
|
3542
|
+
}
|
|
3543
|
+
async function readFileIfExists(path) {
|
|
3544
|
+
if (!await Bun.file(path).exists())
|
|
3545
|
+
return "";
|
|
3546
|
+
const { readFileSync } = await import("node:fs");
|
|
3547
|
+
return readFileSync(path, "utf-8");
|
|
3548
|
+
}
|
|
3549
|
+
async function readThemeFromBundles(clientDir) {
|
|
3550
|
+
for (const dir of bundlesDirs(clientDir)) {
|
|
3551
|
+
try {
|
|
3552
|
+
const hashed = readdirSync(dir).find((name) => HASHED_THEME_RE.test(name));
|
|
3553
|
+
if (hashed) {
|
|
3554
|
+
const css2 = await readFileIfExists(join(dir, hashed));
|
|
3555
|
+
if (css2)
|
|
3556
|
+
return { css: css2, href: `/bundles/${hashed}` };
|
|
3557
|
+
}
|
|
3558
|
+
const css = await readFileIfExists(join(dir, "index.css"));
|
|
3559
|
+
if (css)
|
|
3560
|
+
return { css, href: `/bundles/${themeCssFileName(css)}` };
|
|
3561
|
+
} catch {}
|
|
3562
|
+
}
|
|
3563
|
+
return null;
|
|
3564
|
+
}
|
|
3565
|
+
function bundledThemeCss() {
|
|
3566
|
+
return globalThis.__REROUTE_THEME_CSS__ || "";
|
|
3567
|
+
}
|
|
3568
|
+
async function inlineThemeCSS(clientDir, isWatchMode = false) {
|
|
3392
3569
|
try {
|
|
3393
|
-
const bundledCss = globalThis.__REROUTE_THEME_CSS__;
|
|
3394
|
-
if (bundledCss) {
|
|
3395
|
-
const css2 = minify ? minifyCSS(bundledCss) : bundledCss;
|
|
3396
|
-
return `<style data-reroute="theme">${css2}</style>`;
|
|
3397
|
-
}
|
|
3398
3570
|
if (isWatchMode) {
|
|
3399
|
-
|
|
3400
|
-
return `<link rel="stylesheet" href="/.reroute/index.css?t=${timestamp}" data-reroute="theme">`;
|
|
3401
|
-
}
|
|
3402
|
-
const candidates = [
|
|
3403
|
-
join(clientDir, "..", ".reroute", "index.css"),
|
|
3404
|
-
join(clientDir, "..", "..", ".reroute", "index.css"),
|
|
3405
|
-
join(clientDir, "..", "..", "..", ".reroute", "index.css"),
|
|
3406
|
-
join(clientDir, "..", "..", "..", "..", ".reroute", "index.css")
|
|
3407
|
-
];
|
|
3408
|
-
let cssPath = "";
|
|
3409
|
-
for (const p of candidates) {
|
|
3410
|
-
if (await Bun.file(p).exists()) {
|
|
3411
|
-
cssPath = p;
|
|
3412
|
-
break;
|
|
3413
|
-
}
|
|
3571
|
+
return themeLink(`${THEME_CSS_WATCH_HREF}?t=${Date.now()}`);
|
|
3414
3572
|
}
|
|
3415
|
-
|
|
3573
|
+
const fromDisk = await readThemeFromBundles(clientDir);
|
|
3574
|
+
const css = bundledThemeCss() || fromDisk?.css;
|
|
3575
|
+
if (!css)
|
|
3416
3576
|
return "";
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3577
|
+
if (bundledThemeCss()) {
|
|
3578
|
+
return themeLink(`/bundles/${themeCssFileName(css)}`);
|
|
3579
|
+
}
|
|
3580
|
+
if (fromDisk)
|
|
3581
|
+
return themeLink(fromDisk.href);
|
|
3582
|
+
return "";
|
|
3420
3583
|
} catch {
|
|
3421
3584
|
return "";
|
|
3422
3585
|
}
|
|
3423
3586
|
}
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
}
|
|
3427
|
-
|
|
3587
|
+
var THEME_CSS_WATCH_HREF = "/bundles/index.css", HASHED_THEME_RE;
|
|
3588
|
+
var init_styles = __esm(() => {
|
|
3589
|
+
HASHED_THEME_RE = /^index\.[a-z0-9]{8,}\.css$/i;
|
|
3590
|
+
});
|
|
3428
3591
|
|
|
3429
3592
|
// packages/core/src/ssr/lib/setup.ts
|
|
3430
3593
|
async function performSSRSetup(options, streaming = false) {
|
|
@@ -3493,6 +3656,7 @@ async function performSSRSetupInternal(options, streaming, timeoutState) {
|
|
|
3493
3656
|
});
|
|
3494
3657
|
assertNotTimedOut();
|
|
3495
3658
|
resetSSRAccessTracking();
|
|
3659
|
+
resetSSRContentResults();
|
|
3496
3660
|
const bundlePreload = createBundlePreload(bundleUrl);
|
|
3497
3661
|
const preloadResult = await withSpan("ssr.preload", async (span) => {
|
|
3498
3662
|
span.setAttribute("pathname", pathname);
|
|
@@ -3529,7 +3693,7 @@ async function performSSRSetupInternal(options, streaming, timeoutState) {
|
|
|
3529
3693
|
setGlobalCollections(byCollectionForSSR);
|
|
3530
3694
|
const usingCachedCSS = !!options.cachedThemeCSS;
|
|
3531
3695
|
const inlineStyleTag = await withSpan("ssr.inline.css", async (span) => {
|
|
3532
|
-
const css = options.cachedThemeCSS ? options.cachedThemeCSS : await inlineThemeCSS(clientDir,
|
|
3696
|
+
const css = options.cachedThemeCSS ? options.cachedThemeCSS : await inlineThemeCSS(clientDir, isWatchMode);
|
|
3533
3697
|
span.setAttributes({
|
|
3534
3698
|
"reroute.cached": usingCachedCSS,
|
|
3535
3699
|
"reroute.css.size": css.length
|
|
@@ -3568,12 +3732,12 @@ async function performSSRSetupInternal(options, streaming, timeoutState) {
|
|
|
3568
3732
|
pending: computeResult.pending
|
|
3569
3733
|
};
|
|
3570
3734
|
}
|
|
3571
|
-
function generateCollectionScripts(byCollectionForSSR) {
|
|
3735
|
+
function generateCollectionScripts(byCollectionForSSR, capturedResults) {
|
|
3572
3736
|
try {
|
|
3573
3737
|
const g = globalThis;
|
|
3574
3738
|
const acc = g.__REROUTE_SSR_ACCESSED__;
|
|
3575
3739
|
if (acc) {
|
|
3576
|
-
const { subset, partial } = processCollections(acc, byCollectionForSSR);
|
|
3740
|
+
const { subset, partial } = processCollections(acc, byCollectionForSSR, capturedResults);
|
|
3577
3741
|
if (Object.keys(subset).length > 0) {
|
|
3578
3742
|
return createCollectionScript(subset, partial);
|
|
3579
3743
|
}
|
|
@@ -3725,13 +3889,16 @@ async function renderSSRDocument(options) {
|
|
|
3725
3889
|
}, false);
|
|
3726
3890
|
const duplicatedData = duplicateQueryParamData(setup2.ssrData);
|
|
3727
3891
|
setGlobalSSRData(duplicatedData);
|
|
3892
|
+
let capturedResults;
|
|
3728
3893
|
const appHtml = await withSpan("ssr.render.react", async (span) => {
|
|
3729
3894
|
const componentWithPathname = cloneElement(rootComponent, {
|
|
3730
3895
|
pathname,
|
|
3731
3896
|
searchParams
|
|
3732
3897
|
});
|
|
3733
3898
|
span.setAttribute("reroute.pathname", pathname);
|
|
3899
|
+
resetSSRContentResults();
|
|
3734
3900
|
const html3 = renderToString(componentWithPathname);
|
|
3901
|
+
capturedResults = takeSSRContentResults();
|
|
3735
3902
|
span.setAttribute("reroute.html.final.size", html3.length);
|
|
3736
3903
|
return html3;
|
|
3737
3904
|
});
|
|
@@ -3740,7 +3907,7 @@ async function renderSSRDocument(options) {
|
|
|
3740
3907
|
span.setAttribute("reroute.template.size", template2.length);
|
|
3741
3908
|
return template2;
|
|
3742
3909
|
});
|
|
3743
|
-
const collectionScripts = generateCollectionScripts(setup2.byCollectionForSSR);
|
|
3910
|
+
const collectionScripts = generateCollectionScripts(setup2.byCollectionForSSR, capturedResults);
|
|
3744
3911
|
const config = await loadConfig(cwd);
|
|
3745
3912
|
const browserTelemetryConfigRaw = config.telemetry?.browser;
|
|
3746
3913
|
const { serializeBrowserTelemetryConfig: serializeBrowserTelemetryConfig2 } = await Promise.resolve().then(() => exports_serialize);
|
|
@@ -3758,7 +3925,7 @@ async function renderSSRDocument(options) {
|
|
|
3758
3925
|
if (setup2.metadataResult.statusOverride !== undefined) {
|
|
3759
3926
|
statusOverride = setup2.metadataResult.statusOverride;
|
|
3760
3927
|
}
|
|
3761
|
-
const extraHead = setup2.bundlePreload + setup2.preloadExtraHead;
|
|
3928
|
+
const extraHead = appendLlmsAlternateHead(setup2.bundlePreload + setup2.preloadExtraHead, pathname, statusOverride || 200, config.llms);
|
|
3762
3929
|
const combinedHead = dedent([
|
|
3763
3930
|
dedent(head) || "",
|
|
3764
3931
|
dedent(extraHead),
|
|
@@ -3788,14 +3955,24 @@ async function renderSSRDocument(options) {
|
|
|
3788
3955
|
var init_render = __esm(() => {
|
|
3789
3956
|
init_server2();
|
|
3790
3957
|
init_config();
|
|
3958
|
+
init_discovery3();
|
|
3791
3959
|
init_lib();
|
|
3792
3960
|
init_html();
|
|
3793
3961
|
});
|
|
3794
3962
|
|
|
3795
3963
|
// packages/core/src/llms/formatter.ts
|
|
3964
|
+
function leadingTitleLine(text) {
|
|
3965
|
+
const first = text.trimStart().split(/\r?\n/, 1)[0]?.trim();
|
|
3966
|
+
if (!first)
|
|
3967
|
+
return;
|
|
3968
|
+
return first.replace(/^#\s+/, "").trim();
|
|
3969
|
+
}
|
|
3970
|
+
function hasLeadingTitle(text, title) {
|
|
3971
|
+
return leadingTitleLine(text) === title.trim();
|
|
3972
|
+
}
|
|
3796
3973
|
function formatAsText(content) {
|
|
3797
3974
|
const parts = [];
|
|
3798
|
-
if (content.title) {
|
|
3975
|
+
if (content.title && !hasLeadingTitle(content.body, content.title)) {
|
|
3799
3976
|
parts.push(content.title);
|
|
3800
3977
|
parts.push("");
|
|
3801
3978
|
}
|
|
@@ -3805,7 +3982,7 @@ function formatAsText(content) {
|
|
|
3805
3982
|
}
|
|
3806
3983
|
function formatAsMarkdown(content) {
|
|
3807
3984
|
const parts = [];
|
|
3808
|
-
if (content.title) {
|
|
3985
|
+
if (content.title && !hasLeadingTitle(content.markdown, content.title)) {
|
|
3809
3986
|
parts.push(`# ${content.title}`);
|
|
3810
3987
|
parts.push("");
|
|
3811
3988
|
}
|
|
@@ -3934,6 +4111,9 @@ Formats: .txt | .md | Accept: text/plain | Accept: text/markdown`;
|
|
|
3934
4111
|
// packages/core/src/llms/extractor.ts
|
|
3935
4112
|
import { pathToFileURL as pathToFileURL5 } from "node:url";
|
|
3936
4113
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
4114
|
+
function stripLayoutChrome(html2) {
|
|
4115
|
+
return html2.replace(/<nav[\s\S]*?<\/nav>/gi, "").replace(/<header[\s\S]*?<\/header>/gi, "").replace(/<aside[\s\S]*?<\/aside>/gi, "");
|
|
4116
|
+
}
|
|
3937
4117
|
function shouldExcludeRoute(pathname, excludeRoutes) {
|
|
3938
4118
|
if (!excludeRoutes || excludeRoutes.length === 0) {
|
|
3939
4119
|
return false;
|
|
@@ -4056,10 +4236,7 @@ async function extractSSRContent(pathname, rootComponent, clientDir, cwd, isWatc
|
|
|
4056
4236
|
if (appDivMatch) {
|
|
4057
4237
|
contentHtml = appDivMatch[1];
|
|
4058
4238
|
}
|
|
4059
|
-
contentHtml = contentHtml
|
|
4060
|
-
contentHtml = contentHtml.replace(/<footer[\s\S]*?<\/footer>/gi, "");
|
|
4061
|
-
contentHtml = contentHtml.replace(/<header[\s\S]*?<\/header>/gi, "");
|
|
4062
|
-
contentHtml = contentHtml.replace(/<aside[\s\S]*?<\/aside>/gi, "");
|
|
4239
|
+
contentHtml = stripLayoutChrome(contentHtml);
|
|
4063
4240
|
return {
|
|
4064
4241
|
title: extractTitle(html2),
|
|
4065
4242
|
body: stripHtmlTags(contentHtml),
|
|
@@ -4092,37 +4269,154 @@ async function extractContentForLLMs(options) {
|
|
|
4092
4269
|
throw new Error("Content not found");
|
|
4093
4270
|
}
|
|
4094
4271
|
if (format === "md") {
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
}
|
|
4100
|
-
parts2.push(content.markdown);
|
|
4101
|
-
return parts2.join(`
|
|
4102
|
-
`);
|
|
4103
|
-
}
|
|
4104
|
-
const parts = [];
|
|
4105
|
-
if (content.title) {
|
|
4106
|
-
parts.push(content.title);
|
|
4107
|
-
parts.push("");
|
|
4272
|
+
return formatAsMarkdown({
|
|
4273
|
+
title: content.title,
|
|
4274
|
+
markdown: content.markdown
|
|
4275
|
+
});
|
|
4108
4276
|
}
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4277
|
+
return formatAsText({
|
|
4278
|
+
title: content.title,
|
|
4279
|
+
body: content.body
|
|
4280
|
+
});
|
|
4112
4281
|
}
|
|
4113
4282
|
var init_extractor = __esm(() => {
|
|
4114
4283
|
init_render();
|
|
4115
4284
|
});
|
|
4116
4285
|
|
|
4286
|
+
// packages/core/src/llms/discovery.ts
|
|
4287
|
+
function yesNo(value) {
|
|
4288
|
+
return value === false ? "no" : "yes";
|
|
4289
|
+
}
|
|
4290
|
+
function formatContentSignal(policy, whenUndefined = "omit") {
|
|
4291
|
+
if (policy === false)
|
|
4292
|
+
return;
|
|
4293
|
+
if (policy === undefined && whenUndefined === "omit")
|
|
4294
|
+
return;
|
|
4295
|
+
const resolved = {
|
|
4296
|
+
search: true,
|
|
4297
|
+
aiInput: true,
|
|
4298
|
+
aiTrain: true,
|
|
4299
|
+
...policy
|
|
4300
|
+
};
|
|
4301
|
+
return `ai-train=${yesNo(resolved.aiTrain)}, search=${yesNo(resolved.search)}, ai-input=${yesNo(resolved.aiInput)}`;
|
|
4302
|
+
}
|
|
4303
|
+
function markdownTwinPath(pathname) {
|
|
4304
|
+
const path2 = pathname.split("?")[0];
|
|
4305
|
+
if (path2 === "/" || path2 === "")
|
|
4306
|
+
return "/index.md";
|
|
4307
|
+
return `${path2.replace(/\/$/, "")}.md`;
|
|
4308
|
+
}
|
|
4309
|
+
function shouldAdvertiseMarkdownTwin(pathname, llmsConfig) {
|
|
4310
|
+
if (!llmsConfig?.enabled)
|
|
4311
|
+
return false;
|
|
4312
|
+
if (llmsConfig.enableMarkdownExtension === false)
|
|
4313
|
+
return false;
|
|
4314
|
+
if (shouldExcludeRoute(pathname, llmsConfig.excludeRoutes))
|
|
4315
|
+
return false;
|
|
4316
|
+
return true;
|
|
4317
|
+
}
|
|
4318
|
+
function llmsAlternateLinkTag(pathname, llmsConfig) {
|
|
4319
|
+
if (!shouldAdvertiseMarkdownTwin(pathname, llmsConfig))
|
|
4320
|
+
return "";
|
|
4321
|
+
return `<link rel="alternate" type="text/markdown" href="${markdownTwinPath(pathname)}" />`;
|
|
4322
|
+
}
|
|
4323
|
+
function mergeVary(existing, token) {
|
|
4324
|
+
const parts = (existing ?? "").split(",").map((part) => part.trim()).filter(Boolean);
|
|
4325
|
+
if (!parts.some((part) => part.toLowerCase() === token.toLowerCase())) {
|
|
4326
|
+
parts.push(token);
|
|
4327
|
+
}
|
|
4328
|
+
return parts.join(", ");
|
|
4329
|
+
}
|
|
4330
|
+
function appendLinkValues(existing, values) {
|
|
4331
|
+
const current = (existing ?? "").split(",").map((part) => part.trim()).filter(Boolean);
|
|
4332
|
+
for (const value of values) {
|
|
4333
|
+
if (!current.includes(value))
|
|
4334
|
+
current.push(value);
|
|
4335
|
+
}
|
|
4336
|
+
return current.join(", ");
|
|
4337
|
+
}
|
|
4338
|
+
function buildLlmsDiscovery(pathname, llmsConfig) {
|
|
4339
|
+
if (!llmsConfig?.enabled)
|
|
4340
|
+
return null;
|
|
4341
|
+
const linkValues = [];
|
|
4342
|
+
if (shouldAdvertiseMarkdownTwin(pathname, llmsConfig)) {
|
|
4343
|
+
linkValues.push(`<${markdownTwinPath(pathname)}>; rel="alternate"; type="text/markdown"`);
|
|
4344
|
+
}
|
|
4345
|
+
if (llmsConfig.enableIndex !== false) {
|
|
4346
|
+
linkValues.push('</llms.txt>; rel="llms-txt"');
|
|
4347
|
+
}
|
|
4348
|
+
const contentSignal = formatContentSignal(llmsConfig.contentSignal, "default");
|
|
4349
|
+
const vary = llmsConfig.enableContentNegotiation !== false ? "Accept" : undefined;
|
|
4350
|
+
if (linkValues.length === 0 && !contentSignal && !vary)
|
|
4351
|
+
return null;
|
|
4352
|
+
return { linkValues, contentSignal, vary };
|
|
4353
|
+
}
|
|
4354
|
+
function writeHeader(headers2, canonical, value) {
|
|
4355
|
+
const lower = canonical.toLowerCase();
|
|
4356
|
+
if (headers2[lower] !== undefined)
|
|
4357
|
+
headers2[lower] = value;
|
|
4358
|
+
if (headers2[canonical] !== undefined || headers2[lower] === undefined) {
|
|
4359
|
+
headers2[canonical] = value;
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4362
|
+
function readHeader(headers2, canonical) {
|
|
4363
|
+
return headers2[canonical] ?? headers2[canonical.toLowerCase()];
|
|
4364
|
+
}
|
|
4365
|
+
function applyLlmsDiscoveryHeaders(headers2, pathname, llmsConfig, status = 200) {
|
|
4366
|
+
if (status < 200 || status >= 300)
|
|
4367
|
+
return;
|
|
4368
|
+
const discovery2 = buildLlmsDiscovery(pathname, llmsConfig);
|
|
4369
|
+
if (!discovery2)
|
|
4370
|
+
return;
|
|
4371
|
+
if (discovery2.linkValues.length > 0) {
|
|
4372
|
+
writeHeader(headers2, "Link", appendLinkValues(readHeader(headers2, "Link"), discovery2.linkValues));
|
|
4373
|
+
}
|
|
4374
|
+
if (discovery2.contentSignal) {
|
|
4375
|
+
writeHeader(headers2, "Content-Signal", discovery2.contentSignal);
|
|
4376
|
+
}
|
|
4377
|
+
if (discovery2.vary) {
|
|
4378
|
+
writeHeader(headers2, "Vary", mergeVary(readHeader(headers2, "Vary"), discovery2.vary));
|
|
4379
|
+
}
|
|
4380
|
+
}
|
|
4381
|
+
function appendLlmsAlternateHead(extraHead, pathname, status, llmsConfig) {
|
|
4382
|
+
if (status !== 200)
|
|
4383
|
+
return extraHead;
|
|
4384
|
+
const tag = llmsAlternateLinkTag(pathname, llmsConfig);
|
|
4385
|
+
return tag ? `${extraHead}
|
|
4386
|
+
${tag}` : extraHead;
|
|
4387
|
+
}
|
|
4388
|
+
var init_discovery3 = __esm(() => {
|
|
4389
|
+
init_extractor();
|
|
4390
|
+
});
|
|
4391
|
+
|
|
4117
4392
|
// packages/core/src/llms/index-generator.ts
|
|
4118
4393
|
var exports_index_generator = {};
|
|
4119
4394
|
__export(exports_index_generator, {
|
|
4120
|
-
|
|
4121
|
-
discoverStaticRoutes: () => discoverStaticRoutes,
|
|
4395
|
+
discoverCollectionRoutes: () => discoverCollectionRoutes,
|
|
4122
4396
|
discoverSSRDataRoutes: () => discoverSSRDataRoutes,
|
|
4123
|
-
|
|
4397
|
+
discoverStaticRoutes: () => discoverStaticRoutes,
|
|
4398
|
+
generateLLMsIndex: () => generateLLMsIndex
|
|
4124
4399
|
});
|
|
4125
4400
|
import { pathToFileURL as pathToFileURL6 } from "node:url";
|
|
4401
|
+
function oneLine(value) {
|
|
4402
|
+
return value.replace(/\s+/g, " ").trim();
|
|
4403
|
+
}
|
|
4404
|
+
function stringField(record, key) {
|
|
4405
|
+
const value = record?.[key];
|
|
4406
|
+
if (typeof value !== "string")
|
|
4407
|
+
return;
|
|
4408
|
+
const trimmed = oneLine(value);
|
|
4409
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
4410
|
+
}
|
|
4411
|
+
function metaFromUnknown(meta) {
|
|
4412
|
+
if (!meta || typeof meta !== "object")
|
|
4413
|
+
return {};
|
|
4414
|
+
const record = meta;
|
|
4415
|
+
return {
|
|
4416
|
+
title: stringField(record, "title") ?? stringField(record, "name"),
|
|
4417
|
+
description: stringField(record, "description") ?? stringField(record, "excerpt")
|
|
4418
|
+
};
|
|
4419
|
+
}
|
|
4126
4420
|
async function discoverStaticRoutes(cwd, isWatchMode) {
|
|
4127
4421
|
const routes = [];
|
|
4128
4422
|
try {
|
|
@@ -4139,8 +4433,11 @@ async function discoverStaticRoutes(cwd, isWatchMode) {
|
|
|
4139
4433
|
if (pattern.includes("[404]") || pattern.includes("[layout]") || pattern.includes("[skeleton]") || pattern.includes(":")) {
|
|
4140
4434
|
continue;
|
|
4141
4435
|
}
|
|
4436
|
+
const { title, description } = metaFromUnknown(route?.meta);
|
|
4142
4437
|
routes.push({
|
|
4143
|
-
path: pattern
|
|
4438
|
+
path: pattern,
|
|
4439
|
+
title,
|
|
4440
|
+
description
|
|
4144
4441
|
});
|
|
4145
4442
|
}
|
|
4146
4443
|
}
|
|
@@ -4163,11 +4460,13 @@ function createRouteEntriesFromItems(items, collection) {
|
|
|
4163
4460
|
for (const item of items) {
|
|
4164
4461
|
const href = String(item.href || "");
|
|
4165
4462
|
if (href) {
|
|
4166
|
-
const
|
|
4463
|
+
const fromMeta = metaFromUnknown(item.meta);
|
|
4464
|
+
const title = fromMeta.title || (typeof item.name === "string" ? item.name : undefined);
|
|
4167
4465
|
routes.push({
|
|
4168
4466
|
path: href,
|
|
4169
4467
|
section: collection,
|
|
4170
|
-
title
|
|
4468
|
+
title,
|
|
4469
|
+
description: fromMeta.description
|
|
4171
4470
|
});
|
|
4172
4471
|
}
|
|
4173
4472
|
}
|
|
@@ -4208,7 +4507,7 @@ async function discoverCollectionRoutes(cwd, collections2, isWatchMode, llmsConf
|
|
|
4208
4507
|
}
|
|
4209
4508
|
async function loadRouteModule(cwd, routePath, isWatchMode) {
|
|
4210
4509
|
try {
|
|
4211
|
-
const abs = join(cwd,
|
|
4510
|
+
const abs = join(cwd, resolveAppPaths(await loadConfig(cwd)).routesDir, routePath);
|
|
4212
4511
|
const modUrl = `${pathToFileURL6(abs).href}${isWatchMode ? `?t=${Date.now()}` : ""}`;
|
|
4213
4512
|
return await import(modUrl);
|
|
4214
4513
|
} catch {
|
|
@@ -4233,9 +4532,13 @@ function createEntriesFromArray(array, routePath) {
|
|
|
4233
4532
|
continue;
|
|
4234
4533
|
const identifier = extractIdentifier(item);
|
|
4235
4534
|
if (identifier) {
|
|
4535
|
+
const fromItem = metaFromUnknown(item);
|
|
4536
|
+
const fromMeta = metaFromUnknown(item.meta);
|
|
4236
4537
|
entries.push({
|
|
4237
4538
|
path: `${routePath}/${identifier}`,
|
|
4238
|
-
section: routePath.split("/").filter(Boolean)[0]
|
|
4539
|
+
section: routePath.split("/").filter(Boolean)[0],
|
|
4540
|
+
title: fromItem.title ?? fromMeta.title,
|
|
4541
|
+
description: fromItem.description ?? fromMeta.description
|
|
4239
4542
|
});
|
|
4240
4543
|
}
|
|
4241
4544
|
}
|
|
@@ -4341,13 +4644,21 @@ function formatRouteUrl(routePath, baseUrl) {
|
|
|
4341
4644
|
function getRouteTitle(route) {
|
|
4342
4645
|
return route.title || (route.path === "/" ? "Home" : route.path.split("/").pop() || "Page");
|
|
4343
4646
|
}
|
|
4344
|
-
function
|
|
4345
|
-
|
|
4647
|
+
function formatIndexLine(route, url, summaries) {
|
|
4648
|
+
const link = `- [${getRouteTitle(route)}](${url})`;
|
|
4649
|
+
if (!(summaries && route.description))
|
|
4650
|
+
return link;
|
|
4651
|
+
return `${link}: ${route.description}`;
|
|
4652
|
+
}
|
|
4653
|
+
function summariesEnabled(llmsConfig) {
|
|
4654
|
+
return llmsConfig?.indexSummaries !== false;
|
|
4655
|
+
}
|
|
4656
|
+
function addRootRoutes(parts, rootRoutes, baseUrl, isScoped, llmsConfig) {
|
|
4657
|
+
if (isScoped || rootRoutes.length === 0)
|
|
4346
4658
|
return;
|
|
4659
|
+
const summaries = summariesEnabled(llmsConfig);
|
|
4347
4660
|
for (const route of rootRoutes) {
|
|
4348
|
-
|
|
4349
|
-
const url = formatRouteUrl(route.path, baseUrl);
|
|
4350
|
-
parts.push(`- [${title}](${url})`);
|
|
4661
|
+
parts.push(formatIndexLine(route, formatRouteUrl(route.path, baseUrl), summaries));
|
|
4351
4662
|
}
|
|
4352
4663
|
parts.push("");
|
|
4353
4664
|
}
|
|
@@ -4358,19 +4669,18 @@ function addCollectionSection(parts, collection, routes, baseUrl, llmsConfig) {
|
|
|
4358
4669
|
const sectionName = collection.charAt(0).toUpperCase() + collection.slice(1);
|
|
4359
4670
|
parts.push(`## ${sectionName}`);
|
|
4360
4671
|
parts.push("");
|
|
4672
|
+
const summaries = summariesEnabled(llmsConfig);
|
|
4361
4673
|
for (const route of filteredRoutes) {
|
|
4362
|
-
|
|
4363
|
-
const url = `${baseUrl}${route.path}.txt`;
|
|
4364
|
-
parts.push(`- [${title}](${url})`);
|
|
4674
|
+
parts.push(formatIndexLine(route, `${baseUrl}${route.path}.txt`, summaries));
|
|
4365
4675
|
}
|
|
4366
4676
|
parts.push("");
|
|
4367
4677
|
}
|
|
4368
|
-
function shouldIncludeSection(section,
|
|
4369
|
-
return !
|
|
4678
|
+
function shouldIncludeSection(section, isScoped, targetCollection) {
|
|
4679
|
+
return !isScoped || section === targetCollection;
|
|
4370
4680
|
}
|
|
4371
|
-
function addSSRDataSection(parts, routePattern, routes, baseUrl,
|
|
4681
|
+
function addSSRDataSection(parts, routePattern, routes, baseUrl, isScoped, targetCollection, llmsConfig) {
|
|
4372
4682
|
const routeSection = routePattern.split("/").filter(Boolean)[0];
|
|
4373
|
-
if (!shouldIncludeSection(routeSection,
|
|
4683
|
+
if (!shouldIncludeSection(routeSection, isScoped, targetCollection)) {
|
|
4374
4684
|
return;
|
|
4375
4685
|
}
|
|
4376
4686
|
const filteredRoutes = routes.filter((r) => !shouldExcludeRoute(r.path, llmsConfig?.excludeRoutes));
|
|
@@ -4379,15 +4689,14 @@ function addSSRDataSection(parts, routePattern, routes, baseUrl, isSingleCollect
|
|
|
4379
4689
|
const sectionName = routeSection?.charAt(0).toUpperCase() + routeSection?.slice(1) || "Content";
|
|
4380
4690
|
parts.push(`## ${sectionName}`);
|
|
4381
4691
|
parts.push("");
|
|
4692
|
+
const summaries = summariesEnabled(llmsConfig);
|
|
4382
4693
|
for (const route of filteredRoutes) {
|
|
4383
|
-
|
|
4384
|
-
const url = `${baseUrl}${route.path}.txt`;
|
|
4385
|
-
parts.push(`- [${title}](${url})`);
|
|
4694
|
+
parts.push(formatIndexLine(route, `${baseUrl}${route.path}.txt`, summaries));
|
|
4386
4695
|
}
|
|
4387
4696
|
parts.push("");
|
|
4388
4697
|
}
|
|
4389
|
-
function addStaticSection(parts, section, routes, baseUrl,
|
|
4390
|
-
if (!shouldIncludeSection(section,
|
|
4698
|
+
function addStaticSection(parts, section, routes, baseUrl, isScoped, targetCollection, collectionsMap, llmsConfig) {
|
|
4699
|
+
if (!shouldIncludeSection(section, isScoped, targetCollection)) {
|
|
4391
4700
|
return;
|
|
4392
4701
|
}
|
|
4393
4702
|
const filteredRoutes = routes.filter((r) => !shouldExcludeRoute(r.path, llmsConfig?.excludeRoutes));
|
|
@@ -4396,24 +4705,23 @@ function addStaticSection(parts, section, routes, baseUrl, isSingleCollection, t
|
|
|
4396
4705
|
const sectionName = section.charAt(0).toUpperCase() + section.slice(1);
|
|
4397
4706
|
parts.push(`## ${sectionName}`);
|
|
4398
4707
|
parts.push("");
|
|
4708
|
+
const summaries = summariesEnabled(llmsConfig);
|
|
4399
4709
|
for (const route of filteredRoutes) {
|
|
4400
|
-
|
|
4401
|
-
const url = `${baseUrl}${route.path}.txt`;
|
|
4402
|
-
parts.push(`- [${title}](${url})`);
|
|
4710
|
+
parts.push(formatIndexLine(route, `${baseUrl}${route.path}.txt`, summaries));
|
|
4403
4711
|
}
|
|
4404
4712
|
parts.push("");
|
|
4405
4713
|
}
|
|
4406
4714
|
async function generateLLMsIndex(options) {
|
|
4407
4715
|
const { cwd, collections: collections2, baseUrl, isWatchMode, llmsConfig } = options;
|
|
4716
|
+
const targetCollection = options.targetCollection ?? null;
|
|
4717
|
+
const isScoped = targetCollection !== null;
|
|
4408
4718
|
const parts = [];
|
|
4409
4719
|
addIndexHeader(parts, llmsConfig);
|
|
4410
4720
|
const staticRoutes = await discoverStaticRoutes(cwd, isWatchMode);
|
|
4411
4721
|
const collectionsMap = await discoverCollectionRoutes(cwd, collections2, isWatchMode, llmsConfig);
|
|
4412
4722
|
const ssrDataRoutes = await discoverSSRDataRoutes(cwd, staticRoutes, isWatchMode);
|
|
4413
|
-
const isSingleCollection = collections2.length === 1;
|
|
4414
|
-
const targetCollection = isSingleCollection ? collections2[0] : null;
|
|
4415
4723
|
const { sections, rootRoutes } = groupStaticRoutes(staticRoutes, llmsConfig);
|
|
4416
|
-
addRootRoutes(parts, rootRoutes, baseUrl,
|
|
4724
|
+
addRootRoutes(parts, rootRoutes, baseUrl, isScoped, llmsConfig);
|
|
4417
4725
|
for (const [collection, routes] of collectionsMap.entries()) {
|
|
4418
4726
|
if (routes.length > 0) {
|
|
4419
4727
|
addCollectionSection(parts, collection, routes, baseUrl, llmsConfig);
|
|
@@ -4421,12 +4729,12 @@ async function generateLLMsIndex(options) {
|
|
|
4421
4729
|
}
|
|
4422
4730
|
for (const [routePattern, routes] of ssrDataRoutes.entries()) {
|
|
4423
4731
|
if (routes.length > 0) {
|
|
4424
|
-
addSSRDataSection(parts, routePattern, routes, baseUrl,
|
|
4732
|
+
addSSRDataSection(parts, routePattern, routes, baseUrl, isScoped, targetCollection, llmsConfig);
|
|
4425
4733
|
}
|
|
4426
4734
|
}
|
|
4427
4735
|
for (const [section, routes] of sections.entries()) {
|
|
4428
4736
|
if (routes.length > 0) {
|
|
4429
|
-
addStaticSection(parts, section, routes, baseUrl,
|
|
4737
|
+
addStaticSection(parts, section, routes, baseUrl, isScoped, targetCollection, collectionsMap, llmsConfig);
|
|
4430
4738
|
}
|
|
4431
4739
|
}
|
|
4432
4740
|
parts.push("---");
|
|
@@ -4436,6 +4744,8 @@ async function generateLLMsIndex(options) {
|
|
|
4436
4744
|
`);
|
|
4437
4745
|
}
|
|
4438
4746
|
var init_index_generator = __esm(() => {
|
|
4747
|
+
init_app_paths();
|
|
4748
|
+
init_config();
|
|
4439
4749
|
init_extractor();
|
|
4440
4750
|
});
|
|
4441
4751
|
|
|
@@ -4489,6 +4799,9 @@ async function discoverAllRoutes(cwd, collections2, isWatchMode, llmsConfig) {
|
|
|
4489
4799
|
}
|
|
4490
4800
|
return allRoutes;
|
|
4491
4801
|
}
|
|
4802
|
+
function routeBelongsToCollection(path2, collection) {
|
|
4803
|
+
return path2 === `/${collection}` || path2.startsWith(`/${collection}/`);
|
|
4804
|
+
}
|
|
4492
4805
|
function formatContentBlock(content, routePath, baseUrl) {
|
|
4493
4806
|
const parts = [];
|
|
4494
4807
|
const lines = content.split(`
|
|
@@ -4558,7 +4871,9 @@ function buildFooter(parts) {
|
|
|
4558
4871
|
async function generateLLMsFullContent(options) {
|
|
4559
4872
|
const { cwd, collections: collections2, baseUrl, isWatchMode, llmsConfig } = options;
|
|
4560
4873
|
const parts = buildHeader(baseUrl, llmsConfig);
|
|
4561
|
-
const
|
|
4874
|
+
const discovered = await discoverAllRoutes(cwd, collections2, isWatchMode, llmsConfig);
|
|
4875
|
+
const targetCollection = options.targetCollection;
|
|
4876
|
+
const allRoutes = targetCollection ? discovered.filter((route) => routeBelongsToCollection(route.path, targetCollection)) : discovered;
|
|
4562
4877
|
const maxItems = llmsConfig?.maxItems || 1e4;
|
|
4563
4878
|
const routesToProcess = allRoutes.slice(0, maxItems);
|
|
4564
4879
|
const extracted = await extractRouteContents(routesToProcess, options);
|
|
@@ -4578,6 +4893,7 @@ var init_full_generator = __esm(() => {
|
|
|
4578
4893
|
|
|
4579
4894
|
// packages/core/src/llms/index.ts
|
|
4580
4895
|
var init_llms = __esm(() => {
|
|
4896
|
+
init_discovery3();
|
|
4581
4897
|
init_extractor();
|
|
4582
4898
|
init_full_generator();
|
|
4583
4899
|
init_index_generator();
|
|
@@ -4744,7 +5060,7 @@ async function discoverRobotsData(cwd, isWatchMode, robotsConfig, sitemapConfig,
|
|
|
4744
5060
|
redirectSourcePaths
|
|
4745
5061
|
};
|
|
4746
5062
|
}
|
|
4747
|
-
var
|
|
5063
|
+
var init_discovery4 = () => {};
|
|
4748
5064
|
|
|
4749
5065
|
// packages/core/src/robots/generator.ts
|
|
4750
5066
|
function getEffectivePolicies(policies) {
|
|
@@ -4757,10 +5073,13 @@ function getEffectivePolicies(policies) {
|
|
|
4757
5073
|
}
|
|
4758
5074
|
];
|
|
4759
5075
|
}
|
|
5076
|
+
function robotsDisallowPath(path2) {
|
|
5077
|
+
return path2 === "/" ? "/$" : path2;
|
|
5078
|
+
}
|
|
4760
5079
|
function getAutoDisallows(discovery2) {
|
|
4761
5080
|
return new Set([
|
|
4762
|
-
...discovery2.sitemapExcludedRoutes,
|
|
4763
|
-
...discovery2.redirectSourcePaths
|
|
5081
|
+
...discovery2.sitemapExcludedRoutes.map(robotsDisallowPath),
|
|
5082
|
+
...discovery2.redirectSourcePaths.map(robotsDisallowPath)
|
|
4764
5083
|
]);
|
|
4765
5084
|
}
|
|
4766
5085
|
function addAllowDirectives(lines, policy) {
|
|
@@ -4787,8 +5106,16 @@ function addDisallowDirectives(lines, policy, autoDisallows) {
|
|
|
4787
5106
|
}
|
|
4788
5107
|
}
|
|
4789
5108
|
}
|
|
4790
|
-
function
|
|
5109
|
+
function addContentSignalLine(lines, policy, robotsConfig) {
|
|
5110
|
+
if (policy.userAgent !== "*")
|
|
5111
|
+
return;
|
|
5112
|
+
const value = formatContentSignal(robotsConfig.contentSignal);
|
|
5113
|
+
if (value)
|
|
5114
|
+
lines.push(`Content-Signal: ${value}`);
|
|
5115
|
+
}
|
|
5116
|
+
function addPolicyBlock(lines, policy, autoDisallows, robotsConfig) {
|
|
4791
5117
|
lines.push(`User-agent: ${policy.userAgent}`);
|
|
5118
|
+
addContentSignalLine(lines, policy, robotsConfig);
|
|
4792
5119
|
addAllowDirectives(lines, policy);
|
|
4793
5120
|
addDisallowDirectives(lines, policy, autoDisallows);
|
|
4794
5121
|
if (policy.crawlDelay !== undefined) {
|
|
@@ -4814,7 +5141,7 @@ function generateRobots(discovery2, robotsConfig, sitemapEnabled) {
|
|
|
4814
5141
|
const effectivePolicies = getEffectivePolicies(policies);
|
|
4815
5142
|
const autoDisallows = getAutoDisallows(discovery2);
|
|
4816
5143
|
for (const policy of effectivePolicies) {
|
|
4817
|
-
addPolicyBlock(lines, policy, autoDisallows);
|
|
5144
|
+
addPolicyBlock(lines, policy, autoDisallows, robotsConfig);
|
|
4818
5145
|
}
|
|
4819
5146
|
addGlobalCrawlDelay(lines, crawlDelay, effectivePolicies);
|
|
4820
5147
|
if (customRules) {
|
|
@@ -4826,6 +5153,9 @@ function generateRobots(discovery2, robotsConfig, sitemapEnabled) {
|
|
|
4826
5153
|
`).trim()}
|
|
4827
5154
|
`;
|
|
4828
5155
|
}
|
|
5156
|
+
var init_generator = __esm(() => {
|
|
5157
|
+
init_discovery3();
|
|
5158
|
+
});
|
|
4829
5159
|
|
|
4830
5160
|
// packages/core/src/robots/policies.ts
|
|
4831
5161
|
function blockAICrawlers(crawlers) {
|
|
@@ -4896,17 +5226,20 @@ var init_policies = __esm(() => {
|
|
|
4896
5226
|
|
|
4897
5227
|
// packages/core/src/robots/index.ts
|
|
4898
5228
|
var init_robots = __esm(() => {
|
|
4899
|
-
|
|
5229
|
+
init_discovery4();
|
|
5230
|
+
init_generator();
|
|
4900
5231
|
init_policies();
|
|
4901
5232
|
});
|
|
4902
5233
|
|
|
4903
5234
|
// packages/core/src/sitemap/discovery.ts
|
|
4904
5235
|
var exports_discovery = {};
|
|
4905
5236
|
__export(exports_discovery, {
|
|
4906
|
-
|
|
4907
|
-
|
|
5237
|
+
buildSitemapLoc: () => buildSitemapLoc,
|
|
5238
|
+
discoverCollectionContent: () => discoverCollectionContent,
|
|
5239
|
+
discoverDynamicSitemapRoutes: () => discoverDynamicSitemapRoutes,
|
|
4908
5240
|
discoverRoutes: () => discoverRoutes,
|
|
4909
|
-
|
|
5241
|
+
discoverSSRDataRoutes: () => discoverSSRDataRoutes2,
|
|
5242
|
+
discoverSitemapData: () => discoverSitemapData
|
|
4910
5243
|
});
|
|
4911
5244
|
async function loadRoutesModule2(cwd, isWatchMode) {
|
|
4912
5245
|
let routes = globalThis.__REROUTE_ROUTES__;
|
|
@@ -5170,7 +5503,7 @@ function extractIdentifierFromItem(item, routePattern, sitemapConfig) {
|
|
|
5170
5503
|
console.warn("[reroute/sitemap] extractUrl failed:", error);
|
|
5171
5504
|
}
|
|
5172
5505
|
}
|
|
5173
|
-
const identifier = item.version || item.slug || item.id || item.name || item.key;
|
|
5506
|
+
const identifier = item.version || item.slug || item.id || item.name || item.key || item.username;
|
|
5174
5507
|
return identifier ? identifier : null;
|
|
5175
5508
|
}
|
|
5176
5509
|
function extractLastmodFromItem(item, sitemapConfig) {
|
|
@@ -5195,14 +5528,41 @@ function extractLastmodFromItem(item, sitemapConfig) {
|
|
|
5195
5528
|
}
|
|
5196
5529
|
return;
|
|
5197
5530
|
}
|
|
5531
|
+
function buildSitemapLoc(baseUrl, routePattern, identifier) {
|
|
5532
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
5533
|
+
const dynamicParams = routePattern.match(/:[^/]+/g) ?? [];
|
|
5534
|
+
if (dynamicParams.length === 0) {
|
|
5535
|
+
return `${base}${routePattern}/${identifier}`;
|
|
5536
|
+
}
|
|
5537
|
+
if (identifier.startsWith("/")) {
|
|
5538
|
+
return `${base}${identifier}`;
|
|
5539
|
+
}
|
|
5540
|
+
if (dynamicParams.length === 1) {
|
|
5541
|
+
return `${base}${routePattern.replace(/:[^/]+/, identifier)}`;
|
|
5542
|
+
}
|
|
5543
|
+
return `${base}${routePattern.replace(/:[^/]+/, identifier)}`;
|
|
5544
|
+
}
|
|
5545
|
+
function resolveItemLoc(item, baseUrl, routePattern, identifier) {
|
|
5546
|
+
if (typeof item.loc === "string") {
|
|
5547
|
+
if (item.loc.startsWith("http://") || item.loc.startsWith("https://")) {
|
|
5548
|
+
return item.loc;
|
|
5549
|
+
}
|
|
5550
|
+
if (item.loc.startsWith("/")) {
|
|
5551
|
+
return `${baseUrl.replace(/\/$/, "")}${item.loc}`;
|
|
5552
|
+
}
|
|
5553
|
+
}
|
|
5554
|
+
if (typeof item.href === "string" && item.href.startsWith("/")) {
|
|
5555
|
+
return `${baseUrl.replace(/\/$/, "")}${item.href}`;
|
|
5556
|
+
}
|
|
5557
|
+
return buildSitemapLoc(baseUrl, routePattern, identifier);
|
|
5558
|
+
}
|
|
5198
5559
|
function createEntryFromItem(item, routePattern, baseUrl, sitemapConfig) {
|
|
5199
5560
|
const identifier = extractIdentifierFromItem(item, routePattern, sitemapConfig);
|
|
5200
5561
|
if (!identifier) {
|
|
5201
5562
|
return null;
|
|
5202
5563
|
}
|
|
5203
|
-
const url = `${baseUrl}${routePattern}/${identifier}`;
|
|
5204
5564
|
const entry = {
|
|
5205
|
-
loc:
|
|
5565
|
+
loc: resolveItemLoc(item, baseUrl, routePattern, identifier),
|
|
5206
5566
|
changefreq: sitemapConfig?.changefreq || "weekly",
|
|
5207
5567
|
priority: sitemapConfig?.priority !== undefined ? sitemapConfig.priority : 0.6
|
|
5208
5568
|
};
|
|
@@ -5212,6 +5572,50 @@ function createEntryFromItem(item, routePattern, baseUrl, sitemapConfig) {
|
|
|
5212
5572
|
}
|
|
5213
5573
|
return entry;
|
|
5214
5574
|
}
|
|
5575
|
+
async function loadRouteSitemapFn(cwd, route, isWatchMode) {
|
|
5576
|
+
const bundledRoutes = globalThis.__REROUTE_ROUTES__;
|
|
5577
|
+
if (bundledRoutes && Array.isArray(bundledRoutes)) {
|
|
5578
|
+
const bundledRoute = bundledRoutes.find((r) => r?.pattern === route.pattern);
|
|
5579
|
+
const sitemapFn = bundledRoute?.ssr?.sitemap;
|
|
5580
|
+
return typeof sitemapFn === "function" ? sitemapFn : null;
|
|
5581
|
+
}
|
|
5582
|
+
try {
|
|
5583
|
+
const routeModulePath = join(cwd, "src", "client", "routes", route.path);
|
|
5584
|
+
const mod = await import(Bun.pathToFileURL(routeModulePath).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
5585
|
+
const sitemapFn = mod?.ssr?.sitemap;
|
|
5586
|
+
return typeof sitemapFn === "function" ? sitemapFn : null;
|
|
5587
|
+
} catch {
|
|
5588
|
+
return null;
|
|
5589
|
+
}
|
|
5590
|
+
}
|
|
5591
|
+
async function discoverDynamicSitemapRoutes(cwd, dynamicRoutes, isWatchMode, baseUrl, sitemapConfig) {
|
|
5592
|
+
const sitemapRoutes = new Map;
|
|
5593
|
+
const routePromises = dynamicRoutes.map(async (route) => {
|
|
5594
|
+
if (sitemapConfig?.excludeDiscovery?.some((excluded) => route.pattern.startsWith(excluded))) {
|
|
5595
|
+
return null;
|
|
5596
|
+
}
|
|
5597
|
+
const sitemapFn = await loadRouteSitemapFn(cwd, route, isWatchMode);
|
|
5598
|
+
if (!sitemapFn)
|
|
5599
|
+
return null;
|
|
5600
|
+
try {
|
|
5601
|
+
const result = await sitemapFn();
|
|
5602
|
+
const entries = extractEntriesFromData(result, route.pattern, baseUrl, sitemapConfig);
|
|
5603
|
+
if (entries.length > 0) {
|
|
5604
|
+
return { pattern: route.pattern, entries };
|
|
5605
|
+
}
|
|
5606
|
+
} catch (error) {
|
|
5607
|
+
console.warn(`[reroute/sitemap] ssr.sitemap failed for ${route.pattern}:`, error);
|
|
5608
|
+
}
|
|
5609
|
+
return null;
|
|
5610
|
+
});
|
|
5611
|
+
const results = await Promise.all(routePromises);
|
|
5612
|
+
for (const result of results) {
|
|
5613
|
+
if (result) {
|
|
5614
|
+
sitemapRoutes.set(result.pattern, result.entries);
|
|
5615
|
+
}
|
|
5616
|
+
}
|
|
5617
|
+
return sitemapRoutes;
|
|
5618
|
+
}
|
|
5215
5619
|
async function discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig) {
|
|
5216
5620
|
const { staticRoutes, dynamicRoutes } = await discoverRoutes(cwd, isWatchMode);
|
|
5217
5621
|
const collectionsMap = new Map;
|
|
@@ -5222,6 +5626,10 @@ async function discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, site
|
|
|
5222
5626
|
}
|
|
5223
5627
|
}
|
|
5224
5628
|
const ssrDataRoutes = await discoverSSRDataRoutes2(cwd, staticRoutes, isWatchMode, baseUrl, sitemapConfig);
|
|
5629
|
+
const dynamicSitemapRoutes = await discoverDynamicSitemapRoutes(cwd, dynamicRoutes, isWatchMode, baseUrl, sitemapConfig);
|
|
5630
|
+
for (const [pattern, entries] of dynamicSitemapRoutes.entries()) {
|
|
5631
|
+
ssrDataRoutes.set(pattern, entries);
|
|
5632
|
+
}
|
|
5225
5633
|
return {
|
|
5226
5634
|
staticRoutes,
|
|
5227
5635
|
dynamicRoutes,
|
|
@@ -5229,7 +5637,7 @@ async function discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, site
|
|
|
5229
5637
|
ssrDataRoutes
|
|
5230
5638
|
};
|
|
5231
5639
|
}
|
|
5232
|
-
var
|
|
5640
|
+
var init_discovery5 = () => {};
|
|
5233
5641
|
|
|
5234
5642
|
// packages/core/src/rss/discovery.ts
|
|
5235
5643
|
import { pathToFileURL as pathToFileURL7 } from "node:url";
|
|
@@ -5345,7 +5753,7 @@ async function discoverCollectionFeedItems(cwd, collection, isWatchMode, baseUrl
|
|
|
5345
5753
|
async function discoverSSRDataFeedItems(cwd, routePattern, routePath, isWatchMode, baseUrl, rssConfig) {
|
|
5346
5754
|
const items = [];
|
|
5347
5755
|
try {
|
|
5348
|
-
const abs = join(cwd,
|
|
5756
|
+
const abs = join(cwd, resolveAppPaths(await loadConfig(cwd)).routesDir, routePath);
|
|
5349
5757
|
const mod = await import(pathToFileURL7(abs).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
5350
5758
|
const ssr = mod?.ssr;
|
|
5351
5759
|
const dataFn = ssr?.data;
|
|
@@ -5497,7 +5905,7 @@ async function discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfi
|
|
|
5497
5905
|
}
|
|
5498
5906
|
const ssrDataFeeds = new Map;
|
|
5499
5907
|
const bundledRoutes = globalThis.__REROUTE_ROUTES__;
|
|
5500
|
-
const { discoverRoutes: discoverRoutes2 } = await Promise.resolve().then(() => (
|
|
5908
|
+
const { discoverRoutes: discoverRoutes2 } = await Promise.resolve().then(() => (init_discovery5(), exports_discovery));
|
|
5501
5909
|
const { staticRoutes } = await discoverRoutes2(cwd, isWatchMode);
|
|
5502
5910
|
if (bundledRoutes && Array.isArray(bundledRoutes)) {
|
|
5503
5911
|
const routePromises = staticRoutes.map(async (route) => {
|
|
@@ -5554,7 +5962,10 @@ async function discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfi
|
|
|
5554
5962
|
ssrDataFeeds
|
|
5555
5963
|
};
|
|
5556
5964
|
}
|
|
5557
|
-
var
|
|
5965
|
+
var init_discovery6 = __esm(() => {
|
|
5966
|
+
init_app_paths();
|
|
5967
|
+
init_config();
|
|
5968
|
+
});
|
|
5558
5969
|
|
|
5559
5970
|
// packages/core/src/rss/generator.ts
|
|
5560
5971
|
function generateRSSXML(feed, options = {}) {
|
|
@@ -5667,7 +6078,7 @@ function escapeXml(unsafe) {
|
|
|
5667
6078
|
|
|
5668
6079
|
// packages/core/src/rss/index.ts
|
|
5669
6080
|
var init_rss = __esm(() => {
|
|
5670
|
-
|
|
6081
|
+
init_discovery6();
|
|
5671
6082
|
});
|
|
5672
6083
|
|
|
5673
6084
|
// packages/core/src/sitemap/generator.ts
|
|
@@ -5812,12 +6223,12 @@ function escapeXml2(unsafe) {
|
|
|
5812
6223
|
return unsafe.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
5813
6224
|
}
|
|
5814
6225
|
var DEFAULT_MAX_URLS = 50000;
|
|
5815
|
-
var
|
|
6226
|
+
var init_generator2 = () => {};
|
|
5816
6227
|
|
|
5817
6228
|
// packages/core/src/sitemap/index.ts
|
|
5818
6229
|
var init_sitemap = __esm(() => {
|
|
5819
|
-
|
|
5820
|
-
|
|
6230
|
+
init_discovery5();
|
|
6231
|
+
init_generator2();
|
|
5821
6232
|
});
|
|
5822
6233
|
|
|
5823
6234
|
// packages/core/src/ssr/stream.ts
|
|
@@ -5895,15 +6306,16 @@ async function renderSSRDocumentStream(options) {
|
|
|
5895
6306
|
const newAttrs = hasLang ? attrs.replace(/lang\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/i, `lang="${pageLang}"`) : `${attrs} lang="${pageLang}"`;
|
|
5896
6307
|
return `<html${newAttrs}>`;
|
|
5897
6308
|
});
|
|
5898
|
-
const
|
|
5899
|
-
if (/<title[\s\S]*?<\/title>/i.test(
|
|
6309
|
+
const extraHeadBase = setup2.bundlePreload + setup2.preloadExtraHead + setup2.metadataResult.perPageHead;
|
|
6310
|
+
if (/<title[\s\S]*?<\/title>/i.test(extraHeadBase)) {
|
|
5900
6311
|
headWithLang = headWithLang.replace(/<title[\s\S]*?<\/title>/i, "");
|
|
5901
6312
|
}
|
|
5902
|
-
if (/<meta\s+name\s*=\s*['"]description['"][^>]*>/i.test(
|
|
6313
|
+
if (/<meta\s+name\s*=\s*['"]description['"][^>]*>/i.test(extraHeadBase)) {
|
|
5903
6314
|
headWithLang = headWithLang.replace(/<meta\s+name\s*=\s*['"]description['"][^>]*>/i, "");
|
|
5904
6315
|
}
|
|
5905
|
-
headWithLang = removeOverriddenMetaTags(headWithLang,
|
|
6316
|
+
headWithLang = removeOverriddenMetaTags(headWithLang, extraHeadBase);
|
|
5906
6317
|
const config = await loadConfig(cwd);
|
|
6318
|
+
const extraHead = appendLlmsAlternateHead(extraHeadBase, pathname, statusOverride || 200, config.llms);
|
|
5907
6319
|
const browserTelemetryConfigRaw = config.telemetry?.browser;
|
|
5908
6320
|
const { serializeBrowserTelemetryConfig: serializeBrowserTelemetryConfig2 } = await Promise.resolve().then(() => exports_serialize);
|
|
5909
6321
|
const browserTelemetryConfig = serializeBrowserTelemetryConfig2(browserTelemetryConfigRaw);
|
|
@@ -6161,6 +6573,7 @@ function unescapeHtmlEntities(str) {
|
|
|
6161
6573
|
var init_stream = __esm(() => {
|
|
6162
6574
|
init_server2();
|
|
6163
6575
|
init_config();
|
|
6576
|
+
init_discovery3();
|
|
6164
6577
|
init_lib();
|
|
6165
6578
|
init_html();
|
|
6166
6579
|
init_imports();
|
|
@@ -6175,6 +6588,7 @@ var init_ssr = __esm(() => {
|
|
|
6175
6588
|
|
|
6176
6589
|
// packages/core/src/index.ts
|
|
6177
6590
|
var init_src = __esm(() => {
|
|
6591
|
+
init_app_paths();
|
|
6178
6592
|
init_bundler();
|
|
6179
6593
|
init_config();
|
|
6180
6594
|
init_content();
|
|
@@ -6190,137 +6604,156 @@ var init_src = __esm(() => {
|
|
|
6190
6604
|
// packages/core/index.ts
|
|
6191
6605
|
var exports_core = {};
|
|
6192
6606
|
__export(exports_core, {
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
stripStart: () => stripStart,
|
|
6197
|
-
stripHtmlTags: () => stripHtmlTags,
|
|
6198
|
-
stripEnd: () => stripEnd,
|
|
6199
|
-
statusCache: () => statusCache,
|
|
6200
|
-
ssrCache: () => ssrCache,
|
|
6201
|
-
splitTemplate: () => splitTemplate,
|
|
6202
|
-
shouldExcludeRoute: () => shouldExcludeRoute,
|
|
6203
|
-
setGlobalSSRData: () => setGlobalSSRData,
|
|
6204
|
-
setGlobalCollections: () => setGlobalCollections,
|
|
6205
|
-
seedSSRModuleForPath: () => seedSSRModuleForPath,
|
|
6206
|
-
resolveLocale: () => resolveLocale,
|
|
6207
|
-
resetSSRAccessTracking: () => resetSSRAccessTracking,
|
|
6208
|
-
renderSSRDocumentStream: () => renderSSRDocumentStream,
|
|
6209
|
-
renderSSRDocument: () => renderSSRDocument,
|
|
6210
|
-
renderOGImageToPNG: () => renderOGImageToPNG,
|
|
6211
|
-
removeOverriddenMetaTags: () => removeOverriddenMetaTags,
|
|
6212
|
-
processCollections: () => processCollections,
|
|
6213
|
-
preloadContentModule: () => preloadContentModule,
|
|
6214
|
-
performSSRSetup: () => performSSRSetup,
|
|
6215
|
-
parseCookieValue: () => parseCookieValue,
|
|
6216
|
-
parseContentPath: () => parseContentPath,
|
|
6217
|
-
normalizePathname: () => normalizePathname,
|
|
6218
|
-
negotiateLocale: () => negotiateLocale,
|
|
6219
|
-
mergeLayoutData: () => mergeLayoutData,
|
|
6220
|
-
matchRoutes: () => matchRoutes,
|
|
6221
|
-
matchRoutePattern: () => matchRoutePattern,
|
|
6222
|
-
lookupMessage: () => lookupMessage,
|
|
6223
|
-
looksLikeLocale: () => looksLikeLocale,
|
|
6224
|
-
localizeHref: () => localizeHref,
|
|
6225
|
-
localizeContentHref: () => localizeContentHref,
|
|
6226
|
-
loadRoutesModule: () => loadRoutesModule,
|
|
6227
|
-
loadOGImageComponent: () => loadOGImageComponent,
|
|
6228
|
-
loadIndexHtml: () => loadIndexHtml,
|
|
6229
|
-
loadConfig: () => loadConfig,
|
|
6230
|
-
loadCollections: () => loadCollections,
|
|
6231
|
-
listContentFiles: () => listContentFiles,
|
|
6232
|
-
join: () => join,
|
|
6233
|
-
isThenable: () => isThenable,
|
|
6234
|
-
isCompressible: () => isCompressible,
|
|
6235
|
-
inlineThemeCSS: () => inlineThemeCSS,
|
|
6236
|
-
importContentModuleForPath: () => importContentModuleForPath,
|
|
6237
|
-
htmlToMarkdown: () => htmlToMarkdown,
|
|
6238
|
-
hreflangTags: () => hreflangTags,
|
|
6239
|
-
gzipIfAccepted: () => gzipIfAccepted,
|
|
6240
|
-
getSitemapExcludedRoutes: () => getSitemapExcludedRoutes,
|
|
6241
|
-
getRedirectSourcePaths: () => getRedirectSourcePaths,
|
|
6242
|
-
getPatternDepth: () => getPatternDepth,
|
|
6243
|
-
getMimeType: () => getMimeType,
|
|
6244
|
-
getMessage: () => getMessage,
|
|
6245
|
-
getMatchingLayouts: () => getMatchingLayouts,
|
|
6246
|
-
getContentMeta: () => getContentMeta,
|
|
6247
|
-
generateSitemapXML: () => generateSitemapXML,
|
|
6248
|
-
generateSitemapIndexXML: () => generateSitemapIndexXML,
|
|
6249
|
-
generateSitemap: () => generateSitemap,
|
|
6250
|
-
generateRobots: () => generateRobots,
|
|
6251
|
-
generateRSSXML: () => generateRSSXML,
|
|
6252
|
-
generateOGImageMetaTags: () => generateOGImageMetaTags,
|
|
6253
|
-
generateLLMsIndex: () => generateLLMsIndex,
|
|
6254
|
-
generateLLMsFullContent: () => generateLLMsFullContent,
|
|
6255
|
-
generateLLMsFooter: () => generateLLMsFooter,
|
|
6256
|
-
generateHydrationScripts: () => generateHydrationScripts,
|
|
6257
|
-
generateFeed: () => generateFeed,
|
|
6258
|
-
generateContentHash: () => generateContentHash,
|
|
6259
|
-
generateCollectionScripts: () => generateCollectionScripts,
|
|
6260
|
-
generateAtomXML: () => generateAtomXML,
|
|
6261
|
-
formatMessage: () => formatMessage,
|
|
6262
|
-
formatAsText: () => formatAsText,
|
|
6263
|
-
formatAsMarkdown: () => formatAsMarkdown,
|
|
6264
|
-
findOGImageForPath: () => findOGImageForPath,
|
|
6265
|
-
extractTitle: () => extractTitle,
|
|
6266
|
-
extractParamsFromPath: () => extractParamsFromPath,
|
|
6267
|
-
extractPageMetadata: () => extractPageMetadata,
|
|
6268
|
-
extractContentForLLMs: () => extractContentForLLMs,
|
|
6269
|
-
extname: () => extname,
|
|
6270
|
-
escapeXml: () => escapeXml2,
|
|
6271
|
-
escapeJsonForScript: () => escapeJsonForScript,
|
|
6272
|
-
dynamicImport: () => dynamicImport,
|
|
6273
|
-
duplicateQueryParamData: () => duplicateQueryParamData,
|
|
6274
|
-
discoverSitemapData: () => discoverSitemapData,
|
|
6275
|
-
discoverSSRDataRoutes: () => discoverSSRDataRoutes2,
|
|
6276
|
-
discoverSSRDataFeedItems: () => discoverSSRDataFeedItems,
|
|
6277
|
-
discoverRoutesForRobots: () => discoverRoutesForRobots,
|
|
6278
|
-
discoverRoutes: () => discoverRoutes,
|
|
6279
|
-
discoverRobotsData: () => discoverRobotsData,
|
|
6280
|
-
discoverRSSData: () => discoverRSSData,
|
|
6281
|
-
discoverI18n: () => discoverI18n,
|
|
6282
|
-
discoverCollections: () => discoverCollections,
|
|
6283
|
-
discoverCollectionContent: () => discoverCollectionContent,
|
|
6284
|
-
defineConfig: () => defineConfig,
|
|
6285
|
-
deduplicateMetaTags: () => deduplicateMetaTags,
|
|
6286
|
-
createTranslator: () => createTranslator,
|
|
6287
|
-
createLlmsScript: () => createLlmsScript,
|
|
6288
|
-
createLayoutDataKey: () => createLayoutDataKey,
|
|
6289
|
-
createLayoutCacheKey: () => createLayoutCacheKey,
|
|
6290
|
-
createFeedsScript: () => createFeedsScript,
|
|
6291
|
-
createDataScript: () => createDataScript,
|
|
6292
|
-
createCollectionScript: () => createCollectionScript,
|
|
6293
|
-
createBundlePreload: () => createBundlePreload,
|
|
6294
|
-
contentNegotiateRedirect: () => contentNegotiateRedirect,
|
|
6295
|
-
contentKey: () => contentKey,
|
|
6296
|
-
computeSSRDataForPath: () => computeSSRDataForPath,
|
|
6297
|
-
computeSSRData: () => computeSSRData,
|
|
6298
|
-
computeRouteData: () => computeRouteData,
|
|
6299
|
-
computeLayoutData: () => computeLayoutData,
|
|
6300
|
-
computeContentData: () => computeContentData,
|
|
6301
|
-
compressStreamIfAccepted: () => compressStreamIfAccepted,
|
|
6302
|
-
compareRouteSpecificity: () => compareRouteSpecificity,
|
|
6303
|
-
cleanupPathScopedSSRData: () => cleanupPathScopedSSRData,
|
|
6304
|
-
buildLocaleCookie: () => buildLocaleCookie,
|
|
6305
|
-
buildHeadFromMeta: () => buildHeadFromMeta,
|
|
6306
|
-
blockSearchCrawlers: () => blockSearchCrawlers,
|
|
6307
|
-
blockAITrainingCrawlers: () => blockAITrainingCrawlers,
|
|
6308
|
-
blockAICrawlers: () => blockAICrawlers,
|
|
6309
|
-
basename: () => basename,
|
|
6310
|
-
applyIndexTemplate: () => applyIndexTemplate,
|
|
6311
|
-
allowSearchCrawlers: () => allowSearchCrawlers,
|
|
6312
|
-
allowAICrawlers: () => allowAICrawlers,
|
|
6313
|
-
acceptsGzip: () => acceptsGzip,
|
|
6314
|
-
acceptsBrotli: () => acceptsBrotli,
|
|
6315
|
-
TTLCache: () => TTLCache,
|
|
6316
|
-
SSRDataCache: () => SSRDataCache,
|
|
6317
|
-
SEARCH_CRAWLERS: () => SEARCH_CRAWLERS,
|
|
6318
|
-
LRUCache: () => LRUCache,
|
|
6319
|
-
DefaultOGTemplate: () => DefaultOGTemplate,
|
|
6320
|
-
DEFAULT_LOCALES_DIR: () => DEFAULT_LOCALES_DIR,
|
|
6321
|
-
DEFAULT_LOCALE: () => DEFAULT_LOCALE,
|
|
6607
|
+
AI_CRAWLERS: () => AI_CRAWLERS,
|
|
6608
|
+
DEFAULT_APP_SERVER: () => DEFAULT_APP_SERVER,
|
|
6609
|
+
DEFAULT_APP_SRC: () => DEFAULT_APP_SRC,
|
|
6322
6610
|
DEFAULT_COOKIE: () => DEFAULT_COOKIE,
|
|
6323
|
-
|
|
6611
|
+
DEFAULT_LOCALE: () => DEFAULT_LOCALE,
|
|
6612
|
+
DEFAULT_LOCALES_DIR: () => DEFAULT_LOCALES_DIR,
|
|
6613
|
+
DefaultOGTemplate: () => DefaultOGTemplate,
|
|
6614
|
+
LRUCache: () => LRUCache,
|
|
6615
|
+
SEARCH_CRAWLERS: () => SEARCH_CRAWLERS,
|
|
6616
|
+
SSRDataCache: () => SSRDataCache,
|
|
6617
|
+
TTLCache: () => TTLCache,
|
|
6618
|
+
acceptsBrotli: () => acceptsBrotli,
|
|
6619
|
+
acceptsGzip: () => acceptsGzip,
|
|
6620
|
+
allowAICrawlers: () => allowAICrawlers,
|
|
6621
|
+
allowSearchCrawlers: () => allowSearchCrawlers,
|
|
6622
|
+
appendLlmsAlternateHead: () => appendLlmsAlternateHead,
|
|
6623
|
+
applyIndexTemplate: () => applyIndexTemplate,
|
|
6624
|
+
applyLlmsDiscoveryHeaders: () => applyLlmsDiscoveryHeaders,
|
|
6625
|
+
basename: () => basename,
|
|
6626
|
+
blockAICrawlers: () => blockAICrawlers,
|
|
6627
|
+
blockAITrainingCrawlers: () => blockAITrainingCrawlers,
|
|
6628
|
+
blockSearchCrawlers: () => blockSearchCrawlers,
|
|
6629
|
+
buildHeadFromMeta: () => buildHeadFromMeta,
|
|
6630
|
+
buildLlmsDiscovery: () => buildLlmsDiscovery,
|
|
6631
|
+
buildLocaleCookie: () => buildLocaleCookie,
|
|
6632
|
+
buildSitemapLoc: () => buildSitemapLoc,
|
|
6633
|
+
cleanupPathScopedSSRData: () => cleanupPathScopedSSRData,
|
|
6634
|
+
clearSSRModuleStores: () => clearSSRModuleStores,
|
|
6635
|
+
clearWatchImportCache: () => clearWatchImportCache,
|
|
6636
|
+
compareRouteSpecificity: () => compareRouteSpecificity,
|
|
6637
|
+
compressStreamIfAccepted: () => compressStreamIfAccepted,
|
|
6638
|
+
computeContentData: () => computeContentData,
|
|
6639
|
+
computeLayoutData: () => computeLayoutData,
|
|
6640
|
+
computeRouteData: () => computeRouteData,
|
|
6641
|
+
computeSSRData: () => computeSSRData,
|
|
6642
|
+
computeSSRDataForPath: () => computeSSRDataForPath,
|
|
6643
|
+
contentKey: () => contentKey,
|
|
6644
|
+
contentNegotiateRedirect: () => contentNegotiateRedirect,
|
|
6645
|
+
createBundlePreload: () => createBundlePreload,
|
|
6646
|
+
createCollectionScript: () => createCollectionScript,
|
|
6647
|
+
createDataScript: () => createDataScript,
|
|
6648
|
+
createFeedsScript: () => createFeedsScript,
|
|
6649
|
+
createLayoutCacheKey: () => createLayoutCacheKey,
|
|
6650
|
+
createLayoutDataKey: () => createLayoutDataKey,
|
|
6651
|
+
createLlmsScript: () => createLlmsScript,
|
|
6652
|
+
createTranslator: () => createTranslator,
|
|
6653
|
+
deduplicateMetaTags: () => deduplicateMetaTags,
|
|
6654
|
+
defineConfig: () => defineConfig,
|
|
6655
|
+
discoverCollectionContent: () => discoverCollectionContent,
|
|
6656
|
+
discoverCollections: () => discoverCollections,
|
|
6657
|
+
discoverDynamicSitemapRoutes: () => discoverDynamicSitemapRoutes,
|
|
6658
|
+
discoverI18n: () => discoverI18n,
|
|
6659
|
+
discoverRSSData: () => discoverRSSData,
|
|
6660
|
+
discoverRobotsData: () => discoverRobotsData,
|
|
6661
|
+
discoverRoutes: () => discoverRoutes,
|
|
6662
|
+
discoverRoutesForRobots: () => discoverRoutesForRobots,
|
|
6663
|
+
discoverSSRDataFeedItems: () => discoverSSRDataFeedItems,
|
|
6664
|
+
discoverSSRDataRoutes: () => discoverSSRDataRoutes2,
|
|
6665
|
+
discoverSitemapData: () => discoverSitemapData,
|
|
6666
|
+
duplicateQueryParamData: () => duplicateQueryParamData,
|
|
6667
|
+
dynamicImport: () => dynamicImport,
|
|
6668
|
+
escapeJsonForScript: () => escapeJsonForScript,
|
|
6669
|
+
escapeXml: () => escapeXml2,
|
|
6670
|
+
extname: () => extname,
|
|
6671
|
+
extractContentForLLMs: () => extractContentForLLMs,
|
|
6672
|
+
extractPageMetadata: () => extractPageMetadata,
|
|
6673
|
+
extractParamsFromPath: () => extractParamsFromPath,
|
|
6674
|
+
extractTitle: () => extractTitle,
|
|
6675
|
+
findOGImageForPath: () => findOGImageForPath,
|
|
6676
|
+
formatAsMarkdown: () => formatAsMarkdown,
|
|
6677
|
+
formatAsText: () => formatAsText,
|
|
6678
|
+
formatContentSignal: () => formatContentSignal,
|
|
6679
|
+
formatMessage: () => formatMessage,
|
|
6680
|
+
generateAtomXML: () => generateAtomXML,
|
|
6681
|
+
generateCollectionScripts: () => generateCollectionScripts,
|
|
6682
|
+
generateContentHash: () => generateContentHash,
|
|
6683
|
+
generateFeed: () => generateFeed,
|
|
6684
|
+
generateHydrationScripts: () => generateHydrationScripts,
|
|
6685
|
+
generateLLMsFooter: () => generateLLMsFooter,
|
|
6686
|
+
generateLLMsFullContent: () => generateLLMsFullContent,
|
|
6687
|
+
generateLLMsIndex: () => generateLLMsIndex,
|
|
6688
|
+
generateOGImageMetaTags: () => generateOGImageMetaTags,
|
|
6689
|
+
generateRSSXML: () => generateRSSXML,
|
|
6690
|
+
generateRobots: () => generateRobots,
|
|
6691
|
+
generateSitemap: () => generateSitemap,
|
|
6692
|
+
generateSitemapIndexXML: () => generateSitemapIndexXML,
|
|
6693
|
+
generateSitemapXML: () => generateSitemapXML,
|
|
6694
|
+
getContentMeta: () => getContentMeta,
|
|
6695
|
+
getMatchingLayouts: () => getMatchingLayouts,
|
|
6696
|
+
getMessage: () => getMessage,
|
|
6697
|
+
getMimeType: () => getMimeType,
|
|
6698
|
+
getPatternDepth: () => getPatternDepth,
|
|
6699
|
+
getRedirectSourcePaths: () => getRedirectSourcePaths,
|
|
6700
|
+
getSitemapExcludedRoutes: () => getSitemapExcludedRoutes,
|
|
6701
|
+
gzipIfAccepted: () => gzipIfAccepted,
|
|
6702
|
+
hreflangTags: () => hreflangTags,
|
|
6703
|
+
htmlToMarkdown: () => htmlToMarkdown,
|
|
6704
|
+
importContentModuleForPath: () => importContentModuleForPath,
|
|
6705
|
+
importFromReroute: () => importFromReroute,
|
|
6706
|
+
inlineThemeCSS: () => inlineThemeCSS,
|
|
6707
|
+
isCompressible: () => isCompressible,
|
|
6708
|
+
isThenable: () => isThenable,
|
|
6709
|
+
join: () => join,
|
|
6710
|
+
listContentFiles: () => listContentFiles,
|
|
6711
|
+
llmsAlternateLinkTag: () => llmsAlternateLinkTag,
|
|
6712
|
+
loadCollections: () => loadCollections,
|
|
6713
|
+
loadConfig: () => loadConfig,
|
|
6714
|
+
loadIndexHtml: () => loadIndexHtml,
|
|
6715
|
+
loadOGImageComponent: () => loadOGImageComponent,
|
|
6716
|
+
loadRoutesModule: () => loadRoutesModule,
|
|
6717
|
+
localizeContentHref: () => localizeContentHref,
|
|
6718
|
+
localizeHref: () => localizeHref,
|
|
6719
|
+
looksLikeLocale: () => looksLikeLocale,
|
|
6720
|
+
lookupMessage: () => lookupMessage,
|
|
6721
|
+
markdownTwinPath: () => markdownTwinPath,
|
|
6722
|
+
matchRoutePattern: () => matchRoutePattern,
|
|
6723
|
+
matchRoutes: () => matchRoutes,
|
|
6724
|
+
mergeLayoutData: () => mergeLayoutData,
|
|
6725
|
+
mergeVary: () => mergeVary,
|
|
6726
|
+
negotiateLocale: () => negotiateLocale,
|
|
6727
|
+
normalizePathname: () => normalizePathname,
|
|
6728
|
+
parseContentPath: () => parseContentPath,
|
|
6729
|
+
parseCookieValue: () => parseCookieValue,
|
|
6730
|
+
performSSRSetup: () => performSSRSetup,
|
|
6731
|
+
preloadContentModule: () => preloadContentModule,
|
|
6732
|
+
processCollections: () => processCollections,
|
|
6733
|
+
removeOverriddenMetaTags: () => removeOverriddenMetaTags,
|
|
6734
|
+
renderOGImageToPNG: () => renderOGImageToPNG,
|
|
6735
|
+
renderSSRDocument: () => renderSSRDocument,
|
|
6736
|
+
renderSSRDocumentStream: () => renderSSRDocumentStream,
|
|
6737
|
+
resetSSRAccessTracking: () => resetSSRAccessTracking,
|
|
6738
|
+
resetSSRContentResults: () => resetSSRContentResults,
|
|
6739
|
+
resolveAppPaths: () => resolveAppPaths,
|
|
6740
|
+
resolveLocale: () => resolveLocale,
|
|
6741
|
+
seedSSRModuleForPath: () => seedSSRModuleForPath,
|
|
6742
|
+
setGlobalCollections: () => setGlobalCollections,
|
|
6743
|
+
setGlobalSSRData: () => setGlobalSSRData,
|
|
6744
|
+
shouldAdvertiseMarkdownTwin: () => shouldAdvertiseMarkdownTwin,
|
|
6745
|
+
shouldExcludeRoute: () => shouldExcludeRoute,
|
|
6746
|
+
splitTemplate: () => splitTemplate,
|
|
6747
|
+
ssrCache: () => ssrCache,
|
|
6748
|
+
statusCache: () => statusCache,
|
|
6749
|
+
stripEnd: () => stripEnd,
|
|
6750
|
+
stripHtmlTags: () => stripHtmlTags,
|
|
6751
|
+
stripLayoutChrome: () => stripLayoutChrome,
|
|
6752
|
+
stripStart: () => stripStart,
|
|
6753
|
+
takeSSRContentResults: () => takeSSRContentResults,
|
|
6754
|
+
toBytes: () => toBytes,
|
|
6755
|
+
toOgLocale: () => toOgLocale,
|
|
6756
|
+
toPromise: () => toPromise
|
|
6324
6757
|
});
|
|
6325
6758
|
var init_core = __esm(() => {
|
|
6326
6759
|
init_src();
|
|
@@ -6328,13 +6761,38 @@ var init_core = __esm(() => {
|
|
|
6328
6761
|
|
|
6329
6762
|
// packages/elysia/src/plugin.ts
|
|
6330
6763
|
init_core();
|
|
6331
|
-
import { existsSync as
|
|
6764
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
6765
|
+
import { join as join8 } from "node:path";
|
|
6332
6766
|
import { pathToFileURL as pathToFileURL8 } from "node:url";
|
|
6333
6767
|
import { createElement as createElement2 } from "react";
|
|
6334
6768
|
|
|
6335
|
-
// packages/elysia/src/libs/
|
|
6769
|
+
// packages/elysia/src/libs/assets.ts
|
|
6336
6770
|
import { existsSync } from "node:fs";
|
|
6337
|
-
|
|
6771
|
+
function resolveClientDir(cwd, assets) {
|
|
6772
|
+
if (assets.startsWith("/")) {
|
|
6773
|
+
return assets;
|
|
6774
|
+
}
|
|
6775
|
+
const rerouteAssetsPath = `${cwd}/.reroute/assets`;
|
|
6776
|
+
if (existsSync(rerouteAssetsPath)) {
|
|
6777
|
+
return `${cwd}/.reroute`;
|
|
6778
|
+
}
|
|
6779
|
+
const devPath = `${cwd.replace(/\/$/, "")}/${assets.replace(/^\.\//, "")}`;
|
|
6780
|
+
return devPath;
|
|
6781
|
+
}
|
|
6782
|
+
|
|
6783
|
+
// packages/elysia/src/libs/cache.ts
|
|
6784
|
+
function resolveServerDataMaxAge(cacheEnabled, maxAgeSeconds) {
|
|
6785
|
+
if (!cacheEnabled || maxAgeSeconds <= 0)
|
|
6786
|
+
return 0;
|
|
6787
|
+
return maxAgeSeconds;
|
|
6788
|
+
}
|
|
6789
|
+
function getEncoding(acceptEncoding) {
|
|
6790
|
+
return /\bbr\b/i.test(acceptEncoding) ? "br" : /gzip/i.test(acceptEncoding) ? "gz" : "raw";
|
|
6791
|
+
}
|
|
6792
|
+
|
|
6793
|
+
// packages/elysia/src/libs/image.ts
|
|
6794
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
6795
|
+
import { join as join4 } from "node:path";
|
|
6338
6796
|
import sharp from "sharp";
|
|
6339
6797
|
var imageCache = new Map;
|
|
6340
6798
|
var MAX_CACHE_SIZE = 100;
|
|
@@ -6377,9 +6835,9 @@ async function loadFromDiskCache(cacheKey) {
|
|
|
6377
6835
|
if (!diskCacheDir)
|
|
6378
6836
|
return null;
|
|
6379
6837
|
try {
|
|
6380
|
-
const cachePath =
|
|
6381
|
-
const imagePath =
|
|
6382
|
-
if (!(
|
|
6838
|
+
const cachePath = join4(diskCacheDir, `${cacheKey}.json`);
|
|
6839
|
+
const imagePath = join4(diskCacheDir, `${cacheKey}.img`);
|
|
6840
|
+
if (!(existsSync2(cachePath) && existsSync2(imagePath))) {
|
|
6383
6841
|
return null;
|
|
6384
6842
|
}
|
|
6385
6843
|
const metadata3 = JSON.parse(await Bun.file(cachePath).text());
|
|
@@ -6400,8 +6858,8 @@ async function saveToDiskCache(cacheKey, result) {
|
|
|
6400
6858
|
if (!diskCacheDir)
|
|
6401
6859
|
return;
|
|
6402
6860
|
try {
|
|
6403
|
-
const cachePath =
|
|
6404
|
-
const imagePath =
|
|
6861
|
+
const cachePath = join4(diskCacheDir, `${cacheKey}.json`);
|
|
6862
|
+
const imagePath = join4(diskCacheDir, `${cacheKey}.img`);
|
|
6405
6863
|
await Bun.write(cachePath, JSON.stringify({
|
|
6406
6864
|
contentType: result.contentType,
|
|
6407
6865
|
format: result.format,
|
|
@@ -6510,11 +6968,6 @@ import { NotFoundError as NotFoundError2 } from "elysia";
|
|
|
6510
6968
|
init_core();
|
|
6511
6969
|
import { NotFoundError } from "elysia";
|
|
6512
6970
|
|
|
6513
|
-
// packages/elysia/src/libs/cache.ts
|
|
6514
|
-
function getEncoding(acceptEncoding) {
|
|
6515
|
-
return /\bbr\b/i.test(acceptEncoding) ? "br" : /gzip/i.test(acceptEncoding) ? "gz" : "raw";
|
|
6516
|
-
}
|
|
6517
|
-
|
|
6518
6971
|
// packages/elysia/src/libs/response.ts
|
|
6519
6972
|
var CONTENT_TYPES = {
|
|
6520
6973
|
xml: "application/xml; charset=utf-8",
|
|
@@ -6676,43 +7129,40 @@ function getAssetCacheControl(filePath, contentType, maxAge, directive, isWatchM
|
|
|
6676
7129
|
}
|
|
6677
7130
|
|
|
6678
7131
|
// packages/elysia/src/routes/artifacts.ts
|
|
7132
|
+
function isThemeBundleName(fileName) {
|
|
7133
|
+
return fileName === "index.css" || /^index\.[a-z0-9]{8,}\.css$/i.test(fileName);
|
|
7134
|
+
}
|
|
7135
|
+
function bundledThemeCssResponse(cacheControl) {
|
|
7136
|
+
const bundled = globalThis.__REROUTE_THEME_CSS__;
|
|
7137
|
+
if (!bundled)
|
|
7138
|
+
throw new NotFoundError2;
|
|
7139
|
+
return new Response(bundled, {
|
|
7140
|
+
headers: {
|
|
7141
|
+
"Content-Type": "text/css; charset=utf-8",
|
|
7142
|
+
"Cache-Control": cacheControl
|
|
7143
|
+
}
|
|
7144
|
+
});
|
|
7145
|
+
}
|
|
6679
7146
|
function registerArtifactsRoutes(app, cwd, fileCache, options) {
|
|
6680
7147
|
const { bundleMaxAge, directive, isWatchMode = false } = options;
|
|
6681
|
-
app.get("/.reroute/index.css", async ({ headers: headers2 }) => {
|
|
6682
|
-
const filePath = join(cwd, ".reroute", "index.css");
|
|
6683
|
-
const acceptEncoding = headers2["accept-encoding"] ?? "";
|
|
6684
|
-
try {
|
|
6685
|
-
const cacheControl = isWatchMode ? "no-cache, no-store, must-revalidate" : `${directive}, max-age=${bundleMaxAge}`;
|
|
6686
|
-
if (isWatchMode) {
|
|
6687
|
-
const { readFileSync } = await import("node:fs");
|
|
6688
|
-
const content2 = readFileSync(filePath);
|
|
6689
|
-
return new Response(content2, {
|
|
6690
|
-
headers: {
|
|
6691
|
-
"Content-Type": "text/css; charset=utf-8",
|
|
6692
|
-
"Cache-Control": cacheControl
|
|
6693
|
-
}
|
|
6694
|
-
});
|
|
6695
|
-
}
|
|
6696
|
-
return await serveFile(filePath, acceptEncoding, fileCache, {
|
|
6697
|
-
cacheControl
|
|
6698
|
-
});
|
|
6699
|
-
} catch {}
|
|
6700
|
-
});
|
|
6701
7148
|
app.get("/bundles/*", async ({ params, headers: headers2 }) => {
|
|
6702
7149
|
const fileName = String(params["*"] ?? "").replace(/^\/+/, "");
|
|
6703
7150
|
if (!fileName)
|
|
6704
7151
|
throw new NotFoundError2;
|
|
6705
7152
|
const filePath = join(cwd, ".reroute", "bundles", fileName);
|
|
6706
7153
|
const acceptEncoding = headers2["accept-encoding"] ?? "";
|
|
7154
|
+
const cacheControl = getHashedFileCacheControl(fileName, bundleMaxAge, directive, isWatchMode);
|
|
6707
7155
|
try {
|
|
6708
|
-
const cacheControl = getHashedFileCacheControl(fileName, bundleMaxAge, directive, isWatchMode);
|
|
6709
7156
|
return await serveFile(filePath, acceptEncoding, fileCache, {
|
|
6710
7157
|
cacheControl
|
|
6711
7158
|
});
|
|
6712
|
-
} catch (
|
|
6713
|
-
if (
|
|
6714
|
-
|
|
6715
|
-
|
|
7159
|
+
} catch (error) {
|
|
7160
|
+
if (error instanceof NotFoundError2 && isThemeBundleName(fileName)) {
|
|
7161
|
+
return bundledThemeCssResponse(cacheControl);
|
|
7162
|
+
}
|
|
7163
|
+
if (error instanceof NotFoundError2)
|
|
7164
|
+
throw error;
|
|
7165
|
+
console.error("[reroute] Failed to serve bundle:", filePath, error);
|
|
6716
7166
|
throw new NotFoundError2;
|
|
6717
7167
|
}
|
|
6718
7168
|
});
|
|
@@ -6760,7 +7210,7 @@ function registerContentRoutes(app, cwd, collectionCache, directive, maxAge, isW
|
|
|
6760
7210
|
if (!collectionPath)
|
|
6761
7211
|
throw new NotFoundError3;
|
|
6762
7212
|
const cacheKey = `content:${collectionPath}`;
|
|
6763
|
-
const cached = collectionCache.get(cacheKey);
|
|
7213
|
+
const cached = isWatchMode ? undefined : collectionCache.get(cacheKey);
|
|
6764
7214
|
if (cached) {
|
|
6765
7215
|
if (isOtelAvailable2()) {
|
|
6766
7216
|
const currentSpan = trace3.getActiveSpan();
|
|
@@ -6783,19 +7233,20 @@ function registerContentRoutes(app, cwd, collectionCache, directive, maxAge, isW
|
|
|
6783
7233
|
}
|
|
6784
7234
|
throw new NotFoundError3;
|
|
6785
7235
|
}
|
|
6786
|
-
const
|
|
6787
|
-
const mod = await import(url);
|
|
7236
|
+
const mod = await dynamicImport(collectionFile, isWatchMode);
|
|
6788
7237
|
const items = mod.items ?? [];
|
|
6789
7238
|
const body = JSON.stringify({ collection: collectionPath, items });
|
|
6790
7239
|
const response = new Response(body, {
|
|
6791
7240
|
status: 200,
|
|
6792
7241
|
headers: {
|
|
6793
7242
|
"content-type": "application/json; charset=utf-8",
|
|
6794
|
-
"cache-control": buildCacheControl(maxAge, directive),
|
|
7243
|
+
"cache-control": isWatchMode ? buildDevCacheControl() : buildCacheControl(maxAge, directive),
|
|
6795
7244
|
"Reroute-Cache": "MISS"
|
|
6796
7245
|
}
|
|
6797
7246
|
});
|
|
6798
|
-
|
|
7247
|
+
if (!isWatchMode) {
|
|
7248
|
+
collectionCache.set(cacheKey, response);
|
|
7249
|
+
}
|
|
6799
7250
|
if (isOtelAvailable2()) {
|
|
6800
7251
|
const currentSpan = trace3.getActiveSpan();
|
|
6801
7252
|
currentSpan?.setAttributes({
|
|
@@ -6821,8 +7272,8 @@ function registerContentRoutes(app, cwd, collectionCache, directive, maxAge, isW
|
|
|
6821
7272
|
|
|
6822
7273
|
// packages/elysia/src/routes/image.ts
|
|
6823
7274
|
init_core();
|
|
6824
|
-
import { existsSync as
|
|
6825
|
-
import { join as
|
|
7275
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
7276
|
+
import { join as join5 } from "node:path";
|
|
6826
7277
|
function parseNumericParam(value) {
|
|
6827
7278
|
if (!value)
|
|
6828
7279
|
return;
|
|
@@ -6869,12 +7320,12 @@ function registerImageRoutes(app, options) {
|
|
|
6869
7320
|
}
|
|
6870
7321
|
function resolveInternalImagePath(url, clientDir2) {
|
|
6871
7322
|
const cleanUrl = url.startsWith("/") ? url.slice(1) : url;
|
|
6872
|
-
const imagePath =
|
|
6873
|
-
const normalizedPath =
|
|
7323
|
+
const imagePath = join5(clientDir2, cleanUrl);
|
|
7324
|
+
const normalizedPath = join5(clientDir2, cleanUrl);
|
|
6874
7325
|
if (!normalizedPath.startsWith(clientDir2)) {
|
|
6875
7326
|
return { error: "Access denied" };
|
|
6876
7327
|
}
|
|
6877
|
-
if (!
|
|
7328
|
+
if (!existsSync3(imagePath)) {
|
|
6878
7329
|
return { error: "Image not found" };
|
|
6879
7330
|
}
|
|
6880
7331
|
if (!isImageFile(imagePath)) {
|
|
@@ -7021,6 +7472,38 @@ function jsonError(message, status = 500) {
|
|
|
7021
7472
|
});
|
|
7022
7473
|
}
|
|
7023
7474
|
|
|
7475
|
+
// packages/elysia/src/routes/liveReloadClient.ts
|
|
7476
|
+
function parseConnectedBootId(data) {
|
|
7477
|
+
if (data === "connected")
|
|
7478
|
+
return "";
|
|
7479
|
+
if (data.startsWith("connected:"))
|
|
7480
|
+
return data.slice("connected:".length);
|
|
7481
|
+
return null;
|
|
7482
|
+
}
|
|
7483
|
+
function shouldReloadOnReconnect(previousBootId, nextBootId) {
|
|
7484
|
+
return Boolean(previousBootId && nextBootId && previousBootId !== nextBootId);
|
|
7485
|
+
}
|
|
7486
|
+
|
|
7487
|
+
// packages/elysia/src/routes/themeCssRefresh.ts
|
|
7488
|
+
function refreshThemeCss() {
|
|
7489
|
+
const href = `/bundles/index.css?t=${Date.now()}`;
|
|
7490
|
+
const next = document.createElement("link");
|
|
7491
|
+
next.rel = "stylesheet";
|
|
7492
|
+
next.setAttribute("data-reroute", "theme");
|
|
7493
|
+
next.href = href;
|
|
7494
|
+
const existing = document.querySelector('link[data-reroute="theme"]');
|
|
7495
|
+
const style = document.querySelector('style[data-reroute="theme"]');
|
|
7496
|
+
const previous = existing ?? style;
|
|
7497
|
+
if (previous) {
|
|
7498
|
+
previous.removeAttribute("data-reroute");
|
|
7499
|
+
next.onload = () => previous.remove();
|
|
7500
|
+
previous.after(next);
|
|
7501
|
+
return true;
|
|
7502
|
+
}
|
|
7503
|
+
document.head.appendChild(next);
|
|
7504
|
+
return true;
|
|
7505
|
+
}
|
|
7506
|
+
|
|
7024
7507
|
// packages/elysia/src/routes/internal.ts
|
|
7025
7508
|
function parsePathname(p) {
|
|
7026
7509
|
try {
|
|
@@ -7078,20 +7561,24 @@ function registerInternalRoutes(app, opts) {
|
|
|
7078
7561
|
async function handleKeyRequest(pathname, dataKey, headers2) {
|
|
7079
7562
|
const { computeSSRData: computeSSRData2 } = await Promise.resolve().then(() => (init_core(), exports_core));
|
|
7080
7563
|
const cacheKey = `${pathname}:promises`;
|
|
7081
|
-
let promiseData = dataCache?.get(cacheKey);
|
|
7564
|
+
let promiseData = isWatchMode || maxAge <= 0 ? undefined : dataCache?.get(cacheKey);
|
|
7082
7565
|
const promiseDataCached = promiseData !== undefined;
|
|
7083
7566
|
if (!promiseData) {
|
|
7084
7567
|
const sp = extractSearchParams(pathname);
|
|
7085
7568
|
const { data } = await computeSSRData2(pathname, clientDir, cwd, isWatchMode, { streaming: true, maxAge }, sp);
|
|
7086
7569
|
promiseData = data;
|
|
7087
|
-
|
|
7570
|
+
if (!isWatchMode && maxAge > 0) {
|
|
7571
|
+
dataCache?.set(cacheKey, promiseData);
|
|
7572
|
+
}
|
|
7088
7573
|
}
|
|
7089
7574
|
if (promiseData && typeof promiseData === "object") {
|
|
7090
7575
|
const value = promiseData[dataKey];
|
|
7091
7576
|
if (value instanceof Promise) {
|
|
7092
7577
|
const resolved = await value;
|
|
7093
7578
|
const resolvedCacheKey = `${pathname}:${dataKey}:resolved`;
|
|
7094
|
-
|
|
7579
|
+
if (!isWatchMode && maxAge > 0) {
|
|
7580
|
+
dataCache?.set(resolvedCacheKey, resolved);
|
|
7581
|
+
}
|
|
7095
7582
|
return jsonWithCache({ data: resolved }, dataCacheControl || "no-cache", headers2, promiseDataCached ? "HIT" : "MISS");
|
|
7096
7583
|
}
|
|
7097
7584
|
if (value !== undefined) {
|
|
@@ -7103,7 +7590,7 @@ function registerInternalRoutes(app, opts) {
|
|
|
7103
7590
|
async function handleFullDataRequest(pathname) {
|
|
7104
7591
|
const { computeSSRData: computeSSRData2 } = await Promise.resolve().then(() => (init_core(), exports_core));
|
|
7105
7592
|
const cacheKey = `${pathname}:streaming`;
|
|
7106
|
-
let data = dataCache?.get(cacheKey);
|
|
7593
|
+
let data = isWatchMode || maxAge <= 0 ? undefined : dataCache?.get(cacheKey);
|
|
7107
7594
|
const cacheHit = data !== undefined;
|
|
7108
7595
|
if (data === undefined) {
|
|
7109
7596
|
const sp = extractSearchParams(pathname);
|
|
@@ -7114,7 +7601,9 @@ function registerInternalRoutes(app, opts) {
|
|
|
7114
7601
|
console.error("[__reroute_data] Error computing data:", error);
|
|
7115
7602
|
data = null;
|
|
7116
7603
|
}
|
|
7117
|
-
|
|
7604
|
+
if (!isWatchMode && maxAge > 0) {
|
|
7605
|
+
dataCache?.set(cacheKey, data);
|
|
7606
|
+
}
|
|
7118
7607
|
}
|
|
7119
7608
|
return { data, cacheHit };
|
|
7120
7609
|
}
|
|
@@ -7166,6 +7655,7 @@ var LIVE_RELOAD_CLIENT_CODE = `// Reroute live reload client
|
|
|
7166
7655
|
let eventSource = null;
|
|
7167
7656
|
let hasConnected = false;
|
|
7168
7657
|
let wasDisconnected = false;
|
|
7658
|
+
let lastBootId = null;
|
|
7169
7659
|
let reloadTriggered = false;
|
|
7170
7660
|
let rebuildNotice = null;
|
|
7171
7661
|
let reconnectAttempts = 0;
|
|
@@ -7218,14 +7708,9 @@ function triggerFullReload(reason) {
|
|
|
7218
7708
|
window.location.reload();
|
|
7219
7709
|
}
|
|
7220
7710
|
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
const url = new URL(theme.href, location.href);
|
|
7225
|
-
url.searchParams.set('t', String(Date.now()));
|
|
7226
|
-
theme.href = url.toString();
|
|
7227
|
-
return true;
|
|
7228
|
-
}
|
|
7711
|
+
FUNCTION_PARSE_CONNECTED_BOOT_ID
|
|
7712
|
+
FUNCTION_SHOULD_RELOAD_ON_RECONNECT
|
|
7713
|
+
FUNCTION_REFRESH_THEME_CSS
|
|
7229
7714
|
|
|
7230
7715
|
function showRebuildNotice() {
|
|
7231
7716
|
if (rebuildNotice) return;
|
|
@@ -7346,12 +7831,22 @@ function connect() {
|
|
|
7346
7831
|
eventSource = new EventSource('/__reroute_watch');
|
|
7347
7832
|
|
|
7348
7833
|
eventSource.addEventListener('message', (e) => {
|
|
7349
|
-
|
|
7350
|
-
|
|
7834
|
+
const bootId = parseConnectedBootId(e.data);
|
|
7835
|
+
if (bootId !== null) {
|
|
7836
|
+
reconnectAttempts = 0;
|
|
7837
|
+
if (bootId) lastBootId = lastBootId ?? bootId;
|
|
7351
7838
|
if (hasConnected && wasDisconnected && !reloadTriggered) {
|
|
7352
|
-
|
|
7839
|
+
if (shouldReloadOnReconnect(lastBootId, bootId)) {
|
|
7840
|
+
triggerFullReload('Server restarted, reloading...');
|
|
7841
|
+
return;
|
|
7842
|
+
}
|
|
7843
|
+
lastBootId = bootId || lastBootId;
|
|
7844
|
+
wasDisconnected = false;
|
|
7845
|
+
hideRebuildNotice();
|
|
7846
|
+
console.log('[reroute] ✓ Live reload reconnected');
|
|
7353
7847
|
return;
|
|
7354
7848
|
}
|
|
7849
|
+
if (bootId) lastBootId = bootId;
|
|
7355
7850
|
hasConnected = true;
|
|
7356
7851
|
wasDisconnected = false;
|
|
7357
7852
|
console.log('[reroute] ✓ Live reload connected');
|
|
@@ -7360,11 +7855,8 @@ function connect() {
|
|
|
7360
7855
|
showRebuildNotice();
|
|
7361
7856
|
} else if (e.data === 'reload:css') {
|
|
7362
7857
|
hideRebuildNotice();
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
} else {
|
|
7366
|
-
triggerFullReload('Build complete, reloading...');
|
|
7367
|
-
}
|
|
7858
|
+
refreshThemeCss();
|
|
7859
|
+
console.log('[reroute] ✓ Theme CSS refreshed');
|
|
7368
7860
|
} else if (e.data === 'reload' || e.data === 'reload:full') {
|
|
7369
7861
|
triggerFullReload('Build complete, reloading...');
|
|
7370
7862
|
}
|
|
@@ -7375,9 +7867,7 @@ function connect() {
|
|
|
7375
7867
|
wasDisconnected = true;
|
|
7376
7868
|
eventSource?.close();
|
|
7377
7869
|
if (hasConnected && reconnectAttempts === 0) {
|
|
7378
|
-
|
|
7379
|
-
console.log('[reroute] \uD83D\uDD04 Server restarting...');
|
|
7380
|
-
showRebuildNotice();
|
|
7870
|
+
console.log('[reroute] \uD83D\uDD04 Live reload disconnected, reconnecting...');
|
|
7381
7871
|
}
|
|
7382
7872
|
scheduleReconnect();
|
|
7383
7873
|
});
|
|
@@ -7385,8 +7875,9 @@ function connect() {
|
|
|
7385
7875
|
|
|
7386
7876
|
restoreScrollPosition();
|
|
7387
7877
|
connect();
|
|
7388
|
-
|
|
7878
|
+
`.replace("FUNCTION_PARSE_CONNECTED_BOOT_ID", parseConnectedBootId.toString()).replace("FUNCTION_SHOULD_RELOAD_ON_RECONNECT", shouldReloadOnReconnect.toString()).replace("FUNCTION_REFRESH_THEME_CSS", refreshThemeCss.toString());
|
|
7389
7879
|
function registerLiveReloadRoutes(app, state) {
|
|
7880
|
+
const bootId = crypto.randomUUID();
|
|
7390
7881
|
console.log("[reroute] Registering SSE endpoint at /__reroute_watch");
|
|
7391
7882
|
app.get("/__reroute_watch", () => {
|
|
7392
7883
|
const encoder = new TextEncoder;
|
|
@@ -7397,9 +7888,9 @@ function registerLiveReloadRoutes(app, state) {
|
|
|
7397
7888
|
currentController = controller;
|
|
7398
7889
|
state.clients.add(controller);
|
|
7399
7890
|
console.log("[reroute] Browser connected for live reload");
|
|
7400
|
-
controller.enqueue(encoder.encode(`retry:
|
|
7891
|
+
controller.enqueue(encoder.encode(`retry: 2147483647
|
|
7401
7892
|
`));
|
|
7402
|
-
controller.enqueue(encoder.encode(`data: connected
|
|
7893
|
+
controller.enqueue(encoder.encode(`data: connected:${bootId}
|
|
7403
7894
|
|
|
7404
7895
|
`));
|
|
7405
7896
|
if (state.pendingReload) {
|
|
@@ -7587,13 +8078,17 @@ function registerLLMsRoutes(app, options) {
|
|
|
7587
8078
|
const { ttlMs, ttlMsFull, baseUrl } = defaults;
|
|
7588
8079
|
const llmsCache = new TTLCache(100, ttlMs);
|
|
7589
8080
|
const availableLlms = [];
|
|
8081
|
+
const contentSignal = formatContentSignal(llmsConfig.contentSignal, "default");
|
|
8082
|
+
const signalHeaders = contentSignal ? { "Content-Signal": contentSignal } : {};
|
|
7590
8083
|
const responseOpts = {
|
|
7591
8084
|
maxAge: defaults.maxAge,
|
|
7592
|
-
directive
|
|
8085
|
+
directive,
|
|
8086
|
+
extraHeaders: signalHeaders
|
|
7593
8087
|
};
|
|
7594
8088
|
const responseOptsFull = {
|
|
7595
8089
|
maxAge: defaults.maxAgeFull,
|
|
7596
|
-
directive
|
|
8090
|
+
directive,
|
|
8091
|
+
extraHeaders: signalHeaders
|
|
7597
8092
|
};
|
|
7598
8093
|
availableLlms.push(...getRootLlmsRoutes(llmsConfig));
|
|
7599
8094
|
if (llmsConfig.enableIndex !== false) {
|
|
@@ -7678,6 +8173,7 @@ function registerLLMsRoutes(app, options) {
|
|
|
7678
8173
|
collections: [collection],
|
|
7679
8174
|
baseUrl,
|
|
7680
8175
|
isWatchMode,
|
|
8176
|
+
targetCollection: collection,
|
|
7681
8177
|
llmsConfig: {
|
|
7682
8178
|
...llmsConfig,
|
|
7683
8179
|
siteName: meta.title,
|
|
@@ -7716,6 +8212,7 @@ function registerLLMsRoutes(app, options) {
|
|
|
7716
8212
|
baseUrl,
|
|
7717
8213
|
isWatchMode,
|
|
7718
8214
|
bundleUrl,
|
|
8215
|
+
targetCollection: collection,
|
|
7719
8216
|
llmsConfig: {
|
|
7720
8217
|
...llmsConfig,
|
|
7721
8218
|
siteName: meta.title,
|
|
@@ -7745,7 +8242,7 @@ function registerLLMsRoutes(app, options) {
|
|
|
7745
8242
|
cacheStatus: "HIT"
|
|
7746
8243
|
}) : textResponse(cached, {
|
|
7747
8244
|
...responseOpts,
|
|
7748
|
-
extraHeaders: { Vary: "Accept" },
|
|
8245
|
+
extraHeaders: { ...signalHeaders, Vary: "Accept" },
|
|
7749
8246
|
cacheStatus: "HIT"
|
|
7750
8247
|
});
|
|
7751
8248
|
}
|
|
@@ -7763,7 +8260,7 @@ function registerLLMsRoutes(app, options) {
|
|
|
7763
8260
|
llmsCache.set(cacheKey, content2);
|
|
7764
8261
|
return format === "md" ? markdownResponse(content2, { ...responseOpts, cacheStatus: "MISS" }) : textResponse(content2, {
|
|
7765
8262
|
...responseOpts,
|
|
7766
|
-
extraHeaders: { Vary: "Accept" },
|
|
8263
|
+
extraHeaders: { ...signalHeaders, Vary: "Accept" },
|
|
7767
8264
|
cacheStatus: "MISS"
|
|
7768
8265
|
});
|
|
7769
8266
|
}
|
|
@@ -7801,8 +8298,8 @@ import { NotFoundError as NotFoundError6 } from "elysia";
|
|
|
7801
8298
|
async function tryLoadPrebuiltCollection(cwd, collection, slug, meta) {
|
|
7802
8299
|
try {
|
|
7803
8300
|
const jsPath = `${cwd}/.reroute/collections/${collection}.js`;
|
|
7804
|
-
const { existsSync:
|
|
7805
|
-
if (
|
|
8301
|
+
const { existsSync: existsSync4 } = await import("node:fs");
|
|
8302
|
+
if (existsSync4(jsPath)) {
|
|
7806
8303
|
try {
|
|
7807
8304
|
const mod = await import(jsPath);
|
|
7808
8305
|
const items = mod.items || [];
|
|
@@ -7911,7 +8408,7 @@ async function loadContentMeta(clientDir, collection, slug, isWatchMode, meta) {
|
|
|
7911
8408
|
}
|
|
7912
8409
|
}
|
|
7913
8410
|
async function loadMatchedRouteModule(clientDir, routePath, isWatchMode) {
|
|
7914
|
-
const { existsSync:
|
|
8411
|
+
const { existsSync: existsSync4 } = await import("node:fs");
|
|
7915
8412
|
const { pathToFileURL: pathToFileURL8 } = await import("node:url");
|
|
7916
8413
|
const normalizedRoutePath = routePath === "" ? "index" : routePath;
|
|
7917
8414
|
const possiblePaths = [
|
|
@@ -7925,7 +8422,7 @@ async function loadMatchedRouteModule(clientDir, routePath, isWatchMode) {
|
|
|
7925
8422
|
`${clientDir}/routes/${normalizedRoutePath}/index.md`
|
|
7926
8423
|
];
|
|
7927
8424
|
for (const possiblePath of possiblePaths) {
|
|
7928
|
-
if (
|
|
8425
|
+
if (existsSync4(possiblePath)) {
|
|
7929
8426
|
return await import(pathToFileURL8(possiblePath).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
7930
8427
|
}
|
|
7931
8428
|
}
|
|
@@ -8036,19 +8533,19 @@ function registerOGRoutes(app, options) {
|
|
|
8036
8533
|
}
|
|
8037
8534
|
return;
|
|
8038
8535
|
}
|
|
8039
|
-
function getFontPaths(fontPath, baseDir,
|
|
8536
|
+
function getFontPaths(fontPath, baseDir, join6) {
|
|
8040
8537
|
const fontRelativePath = fontPath.replace(/^(\.\/)?src\/client\/assets\//, "").replace(/^assets\//, "");
|
|
8041
8538
|
return [
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8539
|
+
join6(clientDir, "assets", fontRelativePath),
|
|
8540
|
+
join6(baseDir, ".reroute", "assets", fontRelativePath),
|
|
8541
|
+
join6(cwd, ".reroute", "assets", fontRelativePath),
|
|
8542
|
+
join6(cwd, fontPath),
|
|
8543
|
+
join6(baseDir, fontPath)
|
|
8047
8544
|
];
|
|
8048
8545
|
}
|
|
8049
|
-
async function tryLoadFont(font, possiblePaths,
|
|
8546
|
+
async function tryLoadFont(font, possiblePaths, existsSync4) {
|
|
8050
8547
|
for (const fontPath of possiblePaths) {
|
|
8051
|
-
if (
|
|
8548
|
+
if (existsSync4(fontPath)) {
|
|
8052
8549
|
const fontFile = Bun.file(fontPath);
|
|
8053
8550
|
const data = await fontFile.arrayBuffer();
|
|
8054
8551
|
return {
|
|
@@ -8066,15 +8563,15 @@ function registerOGRoutes(app, options) {
|
|
|
8066
8563
|
if (!ogConfig.fonts || ogConfig.fonts.length === 0) {
|
|
8067
8564
|
return [];
|
|
8068
8565
|
}
|
|
8069
|
-
const { join:
|
|
8070
|
-
const { existsSync:
|
|
8566
|
+
const { join: join6, dirname: dirname2 } = await import("node:path");
|
|
8567
|
+
const { existsSync: existsSync4 } = await import("node:fs");
|
|
8071
8568
|
const isCompiledBinary = typeof Bun !== "undefined" && process.argv[0]?.endsWith(process.argv[1]);
|
|
8072
|
-
const baseDir = isCompiledBinary ?
|
|
8569
|
+
const baseDir = isCompiledBinary ? dirname2(process.argv[1]) : cwd;
|
|
8073
8570
|
const loadedFonts = [];
|
|
8074
8571
|
for (const font of ogConfig.fonts) {
|
|
8075
8572
|
try {
|
|
8076
|
-
const possiblePaths = getFontPaths(font.path, baseDir,
|
|
8077
|
-
const loadedFont = await tryLoadFont(font, possiblePaths,
|
|
8573
|
+
const possiblePaths = getFontPaths(font.path, baseDir, join6);
|
|
8574
|
+
const loadedFont = await tryLoadFont(font, possiblePaths, existsSync4);
|
|
8078
8575
|
if (loadedFont) {
|
|
8079
8576
|
loadedFonts.push(loadedFont);
|
|
8080
8577
|
} else {
|
|
@@ -8301,15 +8798,20 @@ function registerRobotsRoute(app, options) {
|
|
|
8301
8798
|
sitemapEnabled,
|
|
8302
8799
|
redirects
|
|
8303
8800
|
} = options;
|
|
8801
|
+
const cacheEnabled = options.cacheEnabled !== false;
|
|
8304
8802
|
app.get("/robots.txt", async () => {
|
|
8305
8803
|
try {
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
8804
|
+
if (cacheEnabled) {
|
|
8805
|
+
const cached = robotsCache.get("robots:main");
|
|
8806
|
+
if (cached) {
|
|
8807
|
+
return textResponse(cached, { maxAge, cacheStatus: "HIT" });
|
|
8808
|
+
}
|
|
8309
8809
|
}
|
|
8310
8810
|
const discovery5 = await discoverRobotsData(cwd, isWatchMode, robotsConfig, sitemapConfig, redirects);
|
|
8311
8811
|
const txt = generateRobots(discovery5, robotsConfig, sitemapEnabled);
|
|
8312
|
-
|
|
8812
|
+
if (cacheEnabled) {
|
|
8813
|
+
robotsCache.set("robots:main", txt);
|
|
8814
|
+
}
|
|
8313
8815
|
return textResponse(txt, { maxAge, cacheStatus: "MISS" });
|
|
8314
8816
|
} catch (error) {
|
|
8315
8817
|
console.error("[reroute] Failed to generate robots.txt:", error);
|
|
@@ -8704,8 +9206,8 @@ function registerSearchRoute(app, cwd, directive, maxAge, searchConfig) {
|
|
|
8704
9206
|
init_core();
|
|
8705
9207
|
import { NotFoundError as NotFoundError9 } from "elysia";
|
|
8706
9208
|
var sitemapDiscoveryCache = new TTLCache(1, 5 * 60 * 1000);
|
|
8707
|
-
async function getOrDiscoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig) {
|
|
8708
|
-
if (isWatchMode) {
|
|
9209
|
+
async function getOrDiscoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig, cacheEnabled = true) {
|
|
9210
|
+
if (isWatchMode || !cacheEnabled) {
|
|
8709
9211
|
return discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig);
|
|
8710
9212
|
}
|
|
8711
9213
|
const cacheKey = "sitemap:discovery";
|
|
@@ -8718,7 +9220,7 @@ async function getOrDiscoverSitemapData(cwd, collections2, baseUrl, isWatchMode,
|
|
|
8718
9220
|
}
|
|
8719
9221
|
async function generateAndCacheSitemap(options, _ttlMs) {
|
|
8720
9222
|
const { cwd, collections: collections2, baseUrl, isWatchMode, sitemapConfig } = options;
|
|
8721
|
-
const discovery5 = await getOrDiscoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig);
|
|
9223
|
+
const discovery5 = await getOrDiscoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig, options.cacheEnabled);
|
|
8722
9224
|
const result = await generateSitemap(discovery5, baseUrl, {
|
|
8723
9225
|
changefreq: sitemapConfig?.changefreq,
|
|
8724
9226
|
priority: sitemapConfig?.priority,
|
|
@@ -8734,19 +9236,24 @@ async function generateAndCacheSitemap(options, _ttlMs) {
|
|
|
8734
9236
|
function registerSitemapRoutes(app, options) {
|
|
8735
9237
|
const { maxAge, sitemapCache } = options;
|
|
8736
9238
|
const ttlMs = toTTL(maxAge);
|
|
9239
|
+
const cacheEnabled = options.cacheEnabled !== false;
|
|
8737
9240
|
app.get("/sitemap.xml", async () => {
|
|
8738
9241
|
try {
|
|
8739
|
-
|
|
8740
|
-
|
|
8741
|
-
|
|
9242
|
+
if (cacheEnabled) {
|
|
9243
|
+
const cached = sitemapCache.get("sitemap:main");
|
|
9244
|
+
if (cached) {
|
|
9245
|
+
return xmlResponse(cached, { maxAge, cacheStatus: "HIT" });
|
|
9246
|
+
}
|
|
8742
9247
|
}
|
|
8743
9248
|
const result = await generateAndCacheSitemap(options, ttlMs);
|
|
8744
|
-
if (
|
|
8745
|
-
|
|
8746
|
-
|
|
9249
|
+
if (cacheEnabled) {
|
|
9250
|
+
if (result.needsIndex) {
|
|
9251
|
+
for (const page of result.pages) {
|
|
9252
|
+
sitemapCache.set(`sitemap:${page.filename}`, page.xml);
|
|
9253
|
+
}
|
|
8747
9254
|
}
|
|
9255
|
+
sitemapCache.set("sitemap:main", result.xml);
|
|
8748
9256
|
}
|
|
8749
|
-
sitemapCache.set("sitemap:main", result.xml);
|
|
8750
9257
|
return xmlResponse(result.xml, { maxAge, cacheStatus: "MISS" });
|
|
8751
9258
|
} catch (error) {
|
|
8752
9259
|
console.error("[reroute] Failed to generate sitemap:", error);
|
|
@@ -8762,16 +9269,20 @@ function registerSitemapRoutes(app, options) {
|
|
|
8762
9269
|
const filename = `sitemap-${pageMatch[1]}.xml`;
|
|
8763
9270
|
const cacheKey = `sitemap:${filename}`;
|
|
8764
9271
|
try {
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
9272
|
+
if (cacheEnabled) {
|
|
9273
|
+
const cached = sitemapCache.get(cacheKey);
|
|
9274
|
+
if (cached) {
|
|
9275
|
+
return xmlResponse(cached, { maxAge, cacheStatus: "HIT" });
|
|
9276
|
+
}
|
|
8768
9277
|
}
|
|
8769
9278
|
const result = await generateAndCacheSitemap(options, ttlMs);
|
|
8770
9279
|
const pageData = result.pages.find((p) => p.filename === filename);
|
|
8771
9280
|
if (!pageData) {
|
|
8772
9281
|
throw new NotFoundError9;
|
|
8773
9282
|
}
|
|
8774
|
-
|
|
9283
|
+
if (cacheEnabled) {
|
|
9284
|
+
sitemapCache.set(cacheKey, pageData.xml);
|
|
9285
|
+
}
|
|
8775
9286
|
return xmlResponse(pageData.xml, { maxAge, cacheStatus: "MISS" });
|
|
8776
9287
|
} catch (error) {
|
|
8777
9288
|
if (error instanceof NotFoundError9)
|
|
@@ -8786,16 +9297,16 @@ function registerSitemapRoutes(app, options) {
|
|
|
8786
9297
|
// packages/elysia/src/routes/ssr.ts
|
|
8787
9298
|
init_core();
|
|
8788
9299
|
init_server2();
|
|
8789
|
-
import { join as
|
|
9300
|
+
import { join as join7 } from "node:path";
|
|
8790
9301
|
import { trace as trace4 } from "@opentelemetry/api";
|
|
8791
9302
|
import { NotFoundError as NotFoundError10 } from "elysia";
|
|
8792
9303
|
|
|
8793
9304
|
// packages/elysia/src/libs/i18n.ts
|
|
8794
9305
|
init_core();
|
|
8795
|
-
import { join as
|
|
9306
|
+
import { join as join6 } from "node:path";
|
|
8796
9307
|
var cachedI18n = null;
|
|
8797
9308
|
async function loadI18nState(cwd) {
|
|
8798
|
-
const path2 =
|
|
9309
|
+
const path2 = join6(cwd, ".reroute", "i18n.json");
|
|
8799
9310
|
try {
|
|
8800
9311
|
const file = Bun.file(path2);
|
|
8801
9312
|
if (!await file.exists()) {
|
|
@@ -8809,8 +9320,8 @@ async function loadI18nState(cwd) {
|
|
|
8809
9320
|
catalogs: {}
|
|
8810
9321
|
};
|
|
8811
9322
|
}
|
|
8812
|
-
const
|
|
8813
|
-
const mtime =
|
|
9323
|
+
const stat6 = await file.stat();
|
|
9324
|
+
const mtime = stat6?.mtime?.getTime?.() ?? Date.now();
|
|
8814
9325
|
if (cachedI18n && cachedI18n.cwd === cwd && cachedI18n.mtime === mtime) {
|
|
8815
9326
|
return cachedI18n.data;
|
|
8816
9327
|
}
|
|
@@ -8832,14 +9343,14 @@ async function loadI18nState(cwd) {
|
|
|
8832
9343
|
async function listContentCollections(cwd) {
|
|
8833
9344
|
try {
|
|
8834
9345
|
const { readdir: readdir6 } = await import("node:fs/promises");
|
|
8835
|
-
const dir =
|
|
9346
|
+
const dir = join6(cwd, ".reroute", "collections");
|
|
8836
9347
|
const entries = await readdir6(dir);
|
|
8837
9348
|
return entries.filter((f) => f.endsWith(".js")).map((f) => f.replace(/\.js$/, ""));
|
|
8838
9349
|
} catch {
|
|
8839
9350
|
return [];
|
|
8840
9351
|
}
|
|
8841
9352
|
}
|
|
8842
|
-
async function resolveI18nForRequest(cwd, pathname, headers2, collections2) {
|
|
9353
|
+
async function resolveI18nForRequest(cwd, pathname, headers2, collections2, search) {
|
|
8843
9354
|
const i18n2 = await loadI18nState(cwd);
|
|
8844
9355
|
const disabled = {
|
|
8845
9356
|
enabled: false,
|
|
@@ -8856,6 +9367,7 @@ async function resolveI18nForRequest(cwd, pathname, headers2, collections2) {
|
|
|
8856
9367
|
const knownCollections = collections2?.length ? collections2 : await listContentCollections(cwd);
|
|
8857
9368
|
const resolution = resolveLocale({
|
|
8858
9369
|
pathname,
|
|
9370
|
+
search,
|
|
8859
9371
|
cookieHeader: headers2.cookie,
|
|
8860
9372
|
acceptLanguage: headers2["accept-language"],
|
|
8861
9373
|
availableLocales: i18n2.locales,
|
|
@@ -8916,9 +9428,10 @@ function isOtelAvailable3() {
|
|
|
8916
9428
|
return false;
|
|
8917
9429
|
}
|
|
8918
9430
|
}
|
|
8919
|
-
async function applyI18nForSSR(cwd, pathname, headers2, set, fallbackLang) {
|
|
8920
|
-
const i18nResult = await resolveI18nForRequest(cwd, pathname, headers2);
|
|
8921
|
-
|
|
9431
|
+
async function applyI18nForSSR(cwd, pathname, headers2, set, fallbackLang, search = "") {
|
|
9432
|
+
const i18nResult = await resolveI18nForRequest(cwd, pathname, headers2, undefined, search);
|
|
9433
|
+
const current = `${pathname}${search}`;
|
|
9434
|
+
if (i18nResult.redirectTo && i18nResult.redirectTo !== current) {
|
|
8922
9435
|
const redirectHeaders = {
|
|
8923
9436
|
Location: i18nResult.redirectTo
|
|
8924
9437
|
};
|
|
@@ -8966,7 +9479,14 @@ function registerSSRRoutes(app, options) {
|
|
|
8966
9479
|
}
|
|
8967
9480
|
return headers2;
|
|
8968
9481
|
};
|
|
9482
|
+
const attachHtmlHeaders = (headers2, pathname, status, link) => {
|
|
9483
|
+
if (link && !headers2.Link && !headers2.link) {
|
|
9484
|
+
headers2.Link = link;
|
|
9485
|
+
}
|
|
9486
|
+
applyLlmsDiscoveryHeaders(headers2, pathname, options.llmsConfig, status);
|
|
9487
|
+
};
|
|
8969
9488
|
const SSR_HTML_TTL_MS = serverCacheEnabled && serverMaxAge > 0 ? serverMaxAge * 1000 : 0;
|
|
9489
|
+
const ssrDataMaxAge = isWatchMode ? 0 : resolveServerDataMaxAge(serverCacheEnabled, serverMaxAge);
|
|
8970
9490
|
const htmlCache = new LRUCache(200);
|
|
8971
9491
|
const makeKey = (pathname, searchParams, acceptEncoding) => {
|
|
8972
9492
|
const queryString = searchParams?.toString();
|
|
@@ -8977,7 +9497,7 @@ function registerSSRRoutes(app, options) {
|
|
|
8977
9497
|
let contentRoutes = [];
|
|
8978
9498
|
let dynamicRoutes = [];
|
|
8979
9499
|
try {
|
|
8980
|
-
const manifestPath =
|
|
9500
|
+
const manifestPath = join7(cwd, ".reroute", "manifest.json");
|
|
8981
9501
|
const { readFileSync } = __require("node:fs");
|
|
8982
9502
|
const manifestText = readFileSync(manifestPath, "utf-8");
|
|
8983
9503
|
const manifest = JSON.parse(manifestText);
|
|
@@ -9013,7 +9533,7 @@ function registerSSRRoutes(app, options) {
|
|
|
9013
9533
|
request.headers.forEach((value, key) => {
|
|
9014
9534
|
headers2[key.toLowerCase()] = value;
|
|
9015
9535
|
});
|
|
9016
|
-
const i18n2 = await applyI18nForSSR(cwd, pathname, headers2, set, lang);
|
|
9536
|
+
const i18n2 = await applyI18nForSSR(cwd, pathname, headers2, set, lang, url.search);
|
|
9017
9537
|
if (i18n2.redirect)
|
|
9018
9538
|
return i18n2.redirect;
|
|
9019
9539
|
const parentSpan = store.telemetrySpan;
|
|
@@ -9034,6 +9554,7 @@ function registerSSRRoutes(app, options) {
|
|
|
9034
9554
|
}
|
|
9035
9555
|
set.status = cached.status;
|
|
9036
9556
|
Object.assign(set.headers, cached.headers);
|
|
9557
|
+
attachHtmlHeaders(set.headers, pathname, cached.status);
|
|
9037
9558
|
set.headers["Reroute-Cache"] = "HIT";
|
|
9038
9559
|
return new Response(cached.body);
|
|
9039
9560
|
}
|
|
@@ -9100,7 +9621,7 @@ function registerSSRRoutes(app, options) {
|
|
|
9100
9621
|
head,
|
|
9101
9622
|
lang: i18n2.effectiveLang,
|
|
9102
9623
|
appId,
|
|
9103
|
-
maxAge:
|
|
9624
|
+
maxAge: ssrDataMaxAge,
|
|
9104
9625
|
searchParams,
|
|
9105
9626
|
ogConfig: options.ogConfig,
|
|
9106
9627
|
ogMetaConfig: options.ogMetaConfig,
|
|
@@ -9164,9 +9685,7 @@ function registerSSRRoutes(app, options) {
|
|
|
9164
9685
|
...extraHeaders
|
|
9165
9686
|
};
|
|
9166
9687
|
addCacheControl(cacheHeaders, cacheControlHeader);
|
|
9167
|
-
|
|
9168
|
-
cacheHeaders.Link = set.headers.link;
|
|
9169
|
-
}
|
|
9688
|
+
attachHtmlHeaders(cacheHeaders, pathname, status, set.headers.link);
|
|
9170
9689
|
htmlCache.set(ck, {
|
|
9171
9690
|
status,
|
|
9172
9691
|
headers: cacheHeaders,
|
|
@@ -9181,9 +9700,7 @@ function registerSSRRoutes(app, options) {
|
|
|
9181
9700
|
...extraHeaders
|
|
9182
9701
|
};
|
|
9183
9702
|
addCacheControl(resHeaders, cacheControlHeader);
|
|
9184
|
-
|
|
9185
|
-
resHeaders.Link = set.headers.link;
|
|
9186
|
-
}
|
|
9703
|
+
attachHtmlHeaders(resHeaders, pathname, status, set.headers.link);
|
|
9187
9704
|
set.status = status;
|
|
9188
9705
|
response = new Response(body, {
|
|
9189
9706
|
status,
|
|
@@ -9217,9 +9734,7 @@ function registerSSRRoutes(app, options) {
|
|
|
9217
9734
|
"Content-Type": "text/html; charset=utf-8"
|
|
9218
9735
|
};
|
|
9219
9736
|
addCacheControl(cacheHeaders, cacheControlHeader);
|
|
9220
|
-
|
|
9221
|
-
cacheHeaders.Link = set.headers.link;
|
|
9222
|
-
}
|
|
9737
|
+
attachHtmlHeaders(cacheHeaders, pathname, status, set.headers.link);
|
|
9223
9738
|
htmlCache.set(ck, {
|
|
9224
9739
|
status,
|
|
9225
9740
|
headers: cacheHeaders,
|
|
@@ -9238,6 +9753,7 @@ function registerSSRRoutes(app, options) {
|
|
|
9238
9753
|
"Reroute-Cache": "MISS"
|
|
9239
9754
|
};
|
|
9240
9755
|
addCacheControl(resHeaders, cacheControlHeader);
|
|
9756
|
+
attachHtmlHeaders(resHeaders, pathname, status, set.headers.link);
|
|
9241
9757
|
const res = new Response(cachingStream, {
|
|
9242
9758
|
status,
|
|
9243
9759
|
headers: resHeaders
|
|
@@ -9256,6 +9772,7 @@ function registerSSRRoutes(app, options) {
|
|
|
9256
9772
|
"Reroute-Cache": "MISS"
|
|
9257
9773
|
};
|
|
9258
9774
|
addCacheControl(streamHeaders, cacheControlHeader);
|
|
9775
|
+
attachHtmlHeaders(streamHeaders, pathname, status, set.headers.link);
|
|
9259
9776
|
response = new Response(stream2, {
|
|
9260
9777
|
status,
|
|
9261
9778
|
headers: streamHeaders
|
|
@@ -9283,7 +9800,7 @@ function registerSSRRoutes(app, options) {
|
|
|
9283
9800
|
head,
|
|
9284
9801
|
lang: i18n2.effectiveLang,
|
|
9285
9802
|
appId,
|
|
9286
|
-
maxAge:
|
|
9803
|
+
maxAge: ssrDataMaxAge,
|
|
9287
9804
|
searchParams,
|
|
9288
9805
|
ogConfig: options.ogConfig,
|
|
9289
9806
|
ogMetaConfig: options.ogMetaConfig,
|
|
@@ -9341,9 +9858,7 @@ function registerSSRRoutes(app, options) {
|
|
|
9341
9858
|
...extraHeaders
|
|
9342
9859
|
};
|
|
9343
9860
|
addCacheControl(resHeaders, cacheControlHeader);
|
|
9344
|
-
|
|
9345
|
-
resHeaders.Link = set.headers.link;
|
|
9346
|
-
}
|
|
9861
|
+
attachHtmlHeaders(resHeaders, pathname, status, set.headers.link);
|
|
9347
9862
|
set.status = status;
|
|
9348
9863
|
response = new Response(body, {
|
|
9349
9864
|
status,
|
|
@@ -9516,6 +10031,12 @@ var reroute = () => async (app) => {
|
|
|
9516
10031
|
}
|
|
9517
10032
|
});
|
|
9518
10033
|
const globalConfig = await loadConfig(cwd);
|
|
10034
|
+
if (!globalThis.__REROUTE_SERVER_BUNDLE__) {
|
|
10035
|
+
const artifactsServerPath = join8(cwd, ".reroute/artifacts.server.ts");
|
|
10036
|
+
if (existsSync4(artifactsServerPath)) {
|
|
10037
|
+
await import(pathToFileURL8(artifactsServerPath).href);
|
|
10038
|
+
}
|
|
10039
|
+
}
|
|
9519
10040
|
let rootComponent;
|
|
9520
10041
|
const globalApp = globalThis.__REROUTE_APP_COMPONENT__;
|
|
9521
10042
|
if (globalApp) {
|
|
@@ -9531,7 +10052,9 @@ var reroute = () => async (app) => {
|
|
|
9531
10052
|
const ssrHead = globalConfig.app?.head ?? "";
|
|
9532
10053
|
const ssrLang = globalConfig.app?.lang ?? "en";
|
|
9533
10054
|
const ssrAppId = globalConfig.app?.appId ?? "root";
|
|
9534
|
-
const
|
|
10055
|
+
const appPaths = resolveAppPaths(globalConfig);
|
|
10056
|
+
const clientDir = resolveClientDir(cwd, appPaths.clientDir);
|
|
10057
|
+
const staticAssetsDir = join8(clientDir, "assets");
|
|
9535
10058
|
const staticConfig = globalConfig.static ?? {};
|
|
9536
10059
|
const ignorePatterns = staticConfig.ignorePatterns ?? [
|
|
9537
10060
|
".DS_Store",
|
|
@@ -9542,6 +10065,7 @@ var reroute = () => async (app) => {
|
|
|
9542
10065
|
const server2 = globalConfig.server;
|
|
9543
10066
|
const serverCacheEnabled = server2?.cache ?? true;
|
|
9544
10067
|
const serverMaxAge = server2?.maxAge ?? 3600;
|
|
10068
|
+
const serverDataMaxAge = resolveServerDataMaxAge(serverCacheEnabled, serverMaxAge);
|
|
9545
10069
|
const browser = globalConfig.browser;
|
|
9546
10070
|
const browserCacheEnabled = browser?.cache ?? true;
|
|
9547
10071
|
const browserMaxAge = browser?.maxAge ?? 300;
|
|
@@ -9619,9 +10143,8 @@ var reroute = () => async (app) => {
|
|
|
9619
10143
|
}
|
|
9620
10144
|
}
|
|
9621
10145
|
};
|
|
9622
|
-
const clientDir = existsSync3(`${cwd}/.reroute/assets`) ? `${cwd}/.reroute` : `${cwd}/src/client`;
|
|
9623
10146
|
const shouldIgnore = !ignorePatterns.length ? () => false : (file) => ignorePatterns.find((pattern) => typeof pattern === "string" ? file.includes(pattern) : pattern.test(file));
|
|
9624
|
-
const isWatchMode = Array.isArray(process.execArgv) && process.execArgv.includes("--watch") || Array.isArray(process.argv) && process.argv.includes("--watch");
|
|
10147
|
+
const isWatchMode = process.env.REROUTE_DEV === "1" || Array.isArray(process.execArgv) && process.execArgv.includes("--watch") || Array.isArray(process.argv) && process.argv.includes("--watch");
|
|
9625
10148
|
const dataCacheControl = browserCacheEnabled ? `${browserDirective}, max-age=${browserMaxAge}` : undefined;
|
|
9626
10149
|
if (isWatchMode) {
|
|
9627
10150
|
console.log(`[reroute] Live reload enabled`);
|
|
@@ -9640,6 +10163,15 @@ var reroute = () => async (app) => {
|
|
|
9640
10163
|
if (body?.mode === "css")
|
|
9641
10164
|
mode = "css";
|
|
9642
10165
|
} catch {}
|
|
10166
|
+
if (mode === "full") {
|
|
10167
|
+
ssrCache.clear();
|
|
10168
|
+
statusCache.clear();
|
|
10169
|
+
collectionCache.clear();
|
|
10170
|
+
dataCache.clear();
|
|
10171
|
+
fileCache.clear();
|
|
10172
|
+
clearWatchImportCache();
|
|
10173
|
+
clearSSRModuleStores();
|
|
10174
|
+
}
|
|
9643
10175
|
console.log(`[reroute] Reload notification received (${mode}), notifying ${liveReloadState.clients.size} browser(s)...`);
|
|
9644
10176
|
notifyReload(mode);
|
|
9645
10177
|
return new Response(JSON.stringify({
|
|
@@ -9676,7 +10208,7 @@ var reroute = () => async (app) => {
|
|
|
9676
10208
|
const getBundleUrl = isWatchMode ? readBundleUrl : async () => initialBundleUrl;
|
|
9677
10209
|
const { loadCollections: loadCollections2, inlineThemeCSS: inlineThemeCSS2, loadIndexHtml: loadIndexHtml2 } = await Promise.resolve().then(() => (init_core(), exports_core));
|
|
9678
10210
|
const startupCollections = await loadCollections2(cwd, isWatchMode);
|
|
9679
|
-
const startupThemeCSS = await inlineThemeCSS2(clientDir,
|
|
10211
|
+
const startupThemeCSS = await inlineThemeCSS2(clientDir, isWatchMode);
|
|
9680
10212
|
const startupIndexHtml = await loadIndexHtml2(clientDir);
|
|
9681
10213
|
const collectionsTtlMs = serverMaxAge * 1000;
|
|
9682
10214
|
let collectionsCache = serverCacheEnabled ? { data: startupCollections, exp: Date.now() + collectionsTtlMs } : null;
|
|
@@ -9694,7 +10226,7 @@ var reroute = () => async (app) => {
|
|
|
9694
10226
|
};
|
|
9695
10227
|
return fresh;
|
|
9696
10228
|
};
|
|
9697
|
-
const getThemeCSS = isWatchMode ? () => inlineThemeCSS2(clientDir,
|
|
10229
|
+
const getThemeCSS = isWatchMode ? () => inlineThemeCSS2(clientDir, isWatchMode) : async () => startupThemeCSS;
|
|
9698
10230
|
const getIndexHtml = isWatchMode ? () => loadIndexHtml2(clientDir) : async () => startupIndexHtml;
|
|
9699
10231
|
if (globalConfig.redirects && globalConfig.redirects.length > 0) {
|
|
9700
10232
|
registerRedirectRoutes(app, globalConfig.redirects);
|
|
@@ -9708,9 +10240,9 @@ var reroute = () => async (app) => {
|
|
|
9708
10240
|
clientDir,
|
|
9709
10241
|
cwd,
|
|
9710
10242
|
dataCacheControl,
|
|
9711
|
-
dataCache,
|
|
10243
|
+
dataCache: serverDataMaxAge > 0 ? dataCache : undefined,
|
|
9712
10244
|
isWatchMode,
|
|
9713
|
-
maxAge:
|
|
10245
|
+
maxAge: serverDataMaxAge
|
|
9714
10246
|
});
|
|
9715
10247
|
registerArtifactsRoutes(app, cwd, fileCache, {
|
|
9716
10248
|
bundleMaxAge,
|
|
@@ -9745,15 +10277,20 @@ var reroute = () => async (app) => {
|
|
|
9745
10277
|
}
|
|
9746
10278
|
if (robotsEnabled && robotsConfig) {
|
|
9747
10279
|
try {
|
|
10280
|
+
const robotsWithSignal = robotsConfig.contentSignal !== undefined || !llmsEnabled ? robotsConfig : {
|
|
10281
|
+
...robotsConfig,
|
|
10282
|
+
contentSignal: llmsConfig?.contentSignal ?? {}
|
|
10283
|
+
};
|
|
9748
10284
|
registerRobotsRoute(app, {
|
|
9749
10285
|
cwd,
|
|
9750
|
-
maxAge: robotsConfig.maxAge ?? browserMaxAge,
|
|
10286
|
+
maxAge: browserCacheEnabled ? robotsConfig.maxAge ?? browserMaxAge : 0,
|
|
9751
10287
|
isWatchMode,
|
|
9752
10288
|
robotsCache,
|
|
9753
|
-
robotsConfig,
|
|
10289
|
+
robotsConfig: robotsWithSignal,
|
|
9754
10290
|
sitemapConfig,
|
|
9755
10291
|
sitemapEnabled,
|
|
9756
|
-
redirects: globalConfig.redirects
|
|
10292
|
+
redirects: globalConfig.redirects,
|
|
10293
|
+
cacheEnabled: serverCacheEnabled
|
|
9757
10294
|
});
|
|
9758
10295
|
console.log("[reroute] Robots.txt generation enabled");
|
|
9759
10296
|
} catch (error) {
|
|
@@ -9766,10 +10303,11 @@ var reroute = () => async (app) => {
|
|
|
9766
10303
|
cwd,
|
|
9767
10304
|
collections: collections2,
|
|
9768
10305
|
baseUrl: sitemapBaseUrl,
|
|
9769
|
-
maxAge: browserMaxAge,
|
|
10306
|
+
maxAge: browserCacheEnabled ? browserMaxAge : 0,
|
|
9770
10307
|
isWatchMode,
|
|
9771
10308
|
sitemapCache,
|
|
9772
|
-
sitemapConfig
|
|
10309
|
+
sitemapConfig,
|
|
10310
|
+
cacheEnabled: serverCacheEnabled
|
|
9773
10311
|
});
|
|
9774
10312
|
console.log(`[reroute] Sitemap enabled at ${sitemapBaseUrl}/sitemap.xml`);
|
|
9775
10313
|
} catch (error) {
|
|
@@ -9862,7 +10400,8 @@ var reroute = () => async (app) => {
|
|
|
9862
10400
|
ogMetaConfig: globalConfig.og,
|
|
9863
10401
|
baseUrl,
|
|
9864
10402
|
autoCanonical,
|
|
9865
|
-
titleSuffix
|
|
10403
|
+
titleSuffix,
|
|
10404
|
+
llmsConfig: llmsEnabled ? llmsConfig : undefined
|
|
9866
10405
|
});
|
|
9867
10406
|
} catch (error) {
|
|
9868
10407
|
console.error("[reroute] Failed to register SSR routes:", error);
|
|
@@ -9884,4 +10423,4 @@ export {
|
|
|
9884
10423
|
reroute
|
|
9885
10424
|
};
|
|
9886
10425
|
|
|
9887
|
-
//# debugId=
|
|
10426
|
+
//# debugId=239BA0745203D99F64756E2164756E21
|