nuxt-ai-ready 3.6.0 → 3.6.2
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/dist/agent-skills-config-CmZq9uWW.mjs +18 -0
- package/dist/agent-skills-zGLgFB6H.mjs +468 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +656 -570
- package/dist/devtools/pages/ai-ready/debug.vue +9 -3
- package/dist/devtools/pages/ai-ready/index.vue +3 -1
- package/dist/devtools/pages/ai-ready/llms-txt.vue +15 -4
- package/dist/devtools/pages/ai-ready.vue +28 -4
- package/dist/module.d.mts +106 -112
- package/dist/module.json +3 -3
- package/dist/module.mjs +2732 -26
- package/dist/package-metadata-B1darl8W.mjs +28 -0
- package/dist/prerender-QMv07W4h.mjs +650 -0
- package/dist/runtime/app/composables/webmcp.js +90 -97
- package/dist/runtime/app/plugins/md-alternate.server.js +29 -26
- package/dist/runtime/app/plugins/md-hints.prerender.js +13 -15
- package/dist/runtime/app/plugins/webmcp.client.js +49 -53
- package/dist/runtime/app/webmcp-config.js +2 -2
- package/dist/runtime/cache-control.js +16 -10
- package/dist/runtime/i18n-url.js +6 -6
- package/dist/runtime/index.js +4 -12
- package/dist/runtime/llms-txt-directive.js +20 -13
- package/dist/runtime/llms-txt-files.js +188 -187
- package/dist/runtime/llms-txt-format.js +54 -55
- package/dist/runtime/llms-txt-i18n.js +22 -19
- package/dist/runtime/llms-txt-utils.js +140 -95
- package/dist/runtime/markdown-links.js +45 -39
- package/dist/runtime/markdown-path.js +29 -9
- package/dist/runtime/markdown-text.js +2 -1
- package/dist/runtime/mcp.js +5 -1
- package/dist/runtime/route-path.js +14 -8
- package/dist/runtime/server/db/drizzle/client.js +71 -75
- package/dist/runtime/server/db/drizzle/index.js +16 -28
- package/dist/runtime/server/db/drizzle/providers/bun.d.ts +2 -1
- package/dist/runtime/server/db/drizzle/providers/bun.js +10 -7
- package/dist/runtime/server/db/drizzle/providers/d1.js +16 -13
- package/dist/runtime/server/db/drizzle/providers/dbPath.js +60 -37
- package/dist/runtime/server/db/drizzle/providers/libsql.js +23 -11
- package/dist/runtime/server/db/drizzle/providers/neon.js +13 -10
- package/dist/runtime/server/db/drizzle/providers/node-sqlite.js +10 -7
- package/dist/runtime/server/db/drizzle/providers/postgres.js +13 -10
- package/dist/runtime/server/db/drizzle/queries.js +633 -532
- package/dist/runtime/server/db/drizzle/raw.js +200 -176
- package/dist/runtime/server/db/index.js +3 -0
- package/dist/runtime/server/db/queries.js +816 -607
- package/dist/runtime/server/db/schema/postgres.js +56 -50
- package/dist/runtime/server/db/schema/sqlite.js +56 -50
- package/dist/runtime/server/db/schema-sql.js +35 -38
- package/dist/runtime/server/db/seed.js +60 -45
- package/dist/runtime/server/db/shared.js +300 -213
- package/dist/runtime/server/index.js +1 -17
- package/dist/runtime/server/mcp/cache-key.js +5 -1
- package/dist/runtime/server/mcp/resources/pages.js +32 -33
- package/dist/runtime/server/mcp/tools/get-page-markdown.js +41 -27
- package/dist/runtime/server/mcp/tools/list-pages.js +40 -34
- package/dist/runtime/server/mcp/tools/search-pages.js +24 -16
- package/dist/runtime/server/middleware/markdown.d.ts +1 -1
- package/dist/runtime/server/middleware/markdown.js +15 -13
- package/dist/runtime/server/middleware/markdown.prerender.d.ts +1 -1
- package/dist/runtime/server/middleware/markdown.prerender.js +135 -119
- package/dist/runtime/server/middleware/render-markdown.d.ts +1 -1
- package/dist/runtime/server/middleware/render-markdown.js +164 -144
- package/dist/runtime/server/plugins/ai-terms.d.ts +1 -1
- package/dist/runtime/server/plugins/ai-terms.js +4 -8
- package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.d.ts +1 -1
- package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.js +7 -8
- package/dist/runtime/server/plugins/content-signal-capture.prerender.d.ts +1 -1
- package/dist/runtime/server/plugins/content-signal-capture.prerender.js +7 -7
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.d.ts +1 -1
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.js +13 -14
- package/dist/runtime/server/plugins/db-lifecycle.js +13 -11
- package/dist/runtime/server/plugins/html-capture.prerender.js +6 -6
- package/dist/runtime/server/plugins/link-header-nitro3.d.ts +1 -1
- package/dist/runtime/server/plugins/link-header-nitro3.js +23 -13
- package/dist/runtime/server/plugins/link-header.d.ts +1 -1
- package/dist/runtime/server/plugins/link-header.js +30 -30
- package/dist/runtime/server/plugins/llms-txt-directive-html.d.ts +1 -1
- package/dist/runtime/server/plugins/llms-txt-directive-html.js +4 -3
- package/dist/runtime/server/plugins/markdown-negotiation.d.ts +1 -1
- package/dist/runtime/server/plugins/markdown-negotiation.js +64 -45
- package/dist/runtime/server/plugins/sitemap-seeder.js +144 -112
- package/dist/runtime/server/routes/__ai-ready/cron.get.d.ts +1 -1
- package/dist/runtime/server/routes/__ai-ready/cron.get.js +17 -11
- package/dist/runtime/server/routes/__ai-ready/devtools.get.d.ts +1 -1
- package/dist/runtime/server/routes/__ai-ready/devtools.get.js +60 -45
- package/dist/runtime/server/routes/__ai-ready/pages.get.d.ts +36 -1
- package/dist/runtime/server/routes/__ai-ready/pages.get.js +44 -40
- package/dist/runtime/server/routes/__ai-ready/poll.post.d.ts +15 -1
- package/dist/runtime/server/routes/__ai-ready/poll.post.js +30 -30
- package/dist/runtime/server/routes/__ai-ready/prune.post.d.ts +13 -1
- package/dist/runtime/server/routes/__ai-ready/prune.post.js +29 -15
- package/dist/runtime/server/routes/__ai-ready/reindex.post.d.ts +22 -1
- package/dist/runtime/server/routes/__ai-ready/reindex.post.js +31 -21
- package/dist/runtime/server/routes/__ai-ready/restore.post.d.ts +4 -1
- package/dist/runtime/server/routes/__ai-ready/restore.post.js +28 -22
- package/dist/runtime/server/routes/__ai-ready/status.get.d.ts +1 -1
- package/dist/runtime/server/routes/__ai-ready/status.get.js +52 -53
- package/dist/runtime/server/routes/__ai-ready-debug.get.d.ts +83 -1
- package/dist/runtime/server/routes/__ai-ready-debug.get.js +209 -189
- package/dist/runtime/server/routes/agent-skills-artifact.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-artifact.js +16 -14
- package/dist/runtime/server/routes/agent-skills-index.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-index.js +8 -6
- package/dist/runtime/server/routes/ai-catalog.js +19 -19
- package/dist/runtime/server/routes/ai-terms.js +23 -19
- package/dist/runtime/server/routes/api-catalog.js +23 -23
- package/dist/runtime/server/routes/llms-full.txt.get.d.ts +1 -1
- package/dist/runtime/server/routes/llms-full.txt.get.js +42 -41
- package/dist/runtime/server/routes/llms.txt.get.d.ts +1 -1
- package/dist/runtime/server/routes/llms.txt.get.js +38 -33
- package/dist/runtime/server/routes/mcp-server-card.js +19 -19
- package/dist/runtime/server/routes/sitemap.md.get.d.ts +1 -1
- package/dist/runtime/server/routes/sitemap.md.get.js +38 -39
- package/dist/runtime/server/tasks/ai-ready-cron.d.ts +1 -1
- package/dist/runtime/server/tasks/ai-ready-cron.js +17 -14
- package/dist/runtime/server/utils/auth.js +76 -53
- package/dist/runtime/server/utils/batchIndex.js +72 -60
- package/dist/runtime/server/utils/checkStale.js +181 -134
- package/dist/runtime/server/utils/cloudflare-prerendered.js +23 -20
- package/dist/runtime/server/utils/cloudflare.js +69 -51
- package/dist/runtime/server/utils/content-negotiation.js +30 -18
- package/dist/runtime/server/utils/content.js +4 -1
- package/dist/runtime/server/utils/context.js +30 -19
- package/dist/runtime/server/utils/cron-plan.js +6 -6
- package/dist/runtime/server/utils/discovery-response.js +5 -6
- package/dist/runtime/server/utils/fetch.js +2 -1
- package/dist/runtime/server/utils/frontmatter.js +44 -57
- package/dist/runtime/server/utils/i18n.js +3 -8
- package/dist/runtime/server/utils/indexPage.js +152 -113
- package/dist/runtime/server/utils/keywords.js +278 -277
- package/dist/runtime/server/utils/link-header.js +67 -56
- package/dist/runtime/server/utils/llms-full.js +39 -49
- package/dist/runtime/server/utils/markdown-redirect.js +26 -14
- package/dist/runtime/server/utils/markdown-request.js +62 -47
- package/dist/runtime/server/utils/negotiation-decision.d.ts +8 -0
- package/dist/runtime/server/utils/negotiation-decision.js +106 -34
- package/dist/runtime/server/utils/negotiation-response.d.ts +1 -1
- package/dist/runtime/server/utils/negotiation-response.js +195 -144
- package/dist/runtime/server/utils/page-updated-at.js +23 -15
- package/dist/runtime/server/utils/prerender-html.js +31 -17
- package/dist/runtime/server/utils/runCron.js +263 -192
- package/dist/runtime/server/utils/sitemap-crawl-state.js +57 -39
- package/dist/runtime/server/utils/sitemap-lastmod.js +16 -14
- package/dist/runtime/server/utils/sitemap-md.js +39 -50
- package/dist/runtime/server/utils/sitemap-routes.js +7 -7
- package/dist/runtime/server/utils/sitemap.js +459 -414
- package/dist/runtime/server/utils.js +141 -122
- package/dist/runtime/site-tool-catalog.js +39 -43
- package/dist/runtime/site-tool-config.js +1 -0
- package/dist/runtime/sync-secret.js +11 -11
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/webmcp-site-tools.js +278 -250
- package/dist/runtime/webmcp.js +53 -42
- package/dist/static-headers-G7hFL3wE.mjs +328 -0
- package/dist/types.d.mts +1 -9
- package/package.json +20 -24
- package/skills/nuxt-ai-ready/SKILL.md +8 -2
- package/dist/chunks/agent-skills.mjs +0 -383
- package/dist/chunks/prerender.mjs +0 -683
- package/dist/shared/nuxt-ai-ready.Bzx0dNWj.mjs +0 -3034
- package/dist/shared/nuxt-ai-ready.DCd-1s1G.mjs +0 -29
|
@@ -12,169 +12,220 @@ import { toDeployedRoute } from "../../route-path.js";
|
|
|
12
12
|
import { setStatusAwareLinkHeader } from "../plugins/link-header.js";
|
|
13
13
|
import { buildLinkHeader, buildStatusAwareLinkHeaders } from "./link-header.js";
|
|
14
14
|
import { toMarkdownRequest } from "./markdown-request.js";
|
|
15
|
-
import { resolveNegotiationDecision } from "./negotiation-decision.js";
|
|
15
|
+
import { resolveNegotiationDecision, resolveNegotiationPathSkip } from "./negotiation-decision.js";
|
|
16
|
+
/** Set once the negotiation headers are on the response, so nothing repeats them. */
|
|
16
17
|
const APPLIED_KEY = "nuxt-ai-ready:negotiation-applied";
|
|
17
18
|
let artifactPaths;
|
|
19
|
+
/** Routes an agent skill answers verbatim; negotiation must not render them. */
|
|
18
20
|
export function agentSkillArtifactPaths() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
artifactPaths ??= new Set(Object.keys(localAgentSkillArtifacts));
|
|
22
|
+
return artifactPaths;
|
|
21
23
|
}
|
|
22
24
|
function createHeaderUrlResolver(event, ctx) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
// `createSitePathResolver` was added after the supported Site Config floor.
|
|
26
|
+
// Older versions retain the established resolver through the context.
|
|
27
|
+
if (!siteConfigUtils.createSitePathResolver) return ctx.resolveUrl;
|
|
28
|
+
// Capture site configuration only for this synchronous header build. The
|
|
29
|
+
// context's live resolver still observes changes after asynchronous hooks.
|
|
30
|
+
let resolveUrl;
|
|
31
|
+
return (path) => {
|
|
32
|
+
// Keep setup inside the builder's existing relative-link error fallback.
|
|
33
|
+
resolveUrl ??= siteConfigUtils.createSitePathResolver(event, {
|
|
34
|
+
absolute: true,
|
|
35
|
+
withBase: true
|
|
36
|
+
});
|
|
37
|
+
return resolveUrl(ctx.resolvePath(path));
|
|
38
|
+
};
|
|
30
39
|
}
|
|
31
40
|
export function setLinkHeader(event, ctx, variant) {
|
|
32
|
-
|
|
41
|
+
setHeader(event, "link", buildLinkHeader(ctx.path, variant, ctx.config, createHeaderUrlResolver(event, ctx), ctx.routeContext));
|
|
33
42
|
}
|
|
34
43
|
export function setStatusAwareHeader(event, ctx, variant) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
if (!ctx.config.i18n && !ctx.config.apiCatalog) {
|
|
45
|
+
setLinkHeader(event, ctx, variant);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// Catalog route rules can overwrite the prepared Link on a native Response.
|
|
49
|
+
// Keep the discovery links available when the response becomes final.
|
|
50
|
+
const headers = buildStatusAwareLinkHeaders(ctx.path, variant, ctx.config, createHeaderUrlResolver(event, ctx), ctx.routeContext);
|
|
51
|
+
setStatusAwareLinkHeader(event, headers.error, headers.success);
|
|
41
52
|
}
|
|
42
53
|
export function setUncacheableHeaders(event) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
+
setHeader(event, "cache-control", "private, no-store");
|
|
55
|
+
setHeader(event, "cdn-cache-control", "no-store");
|
|
56
|
+
for (const header of [
|
|
57
|
+
"cloudflare-cdn-cache-control",
|
|
58
|
+
"netlify-cdn-cache-control",
|
|
59
|
+
"vercel-cdn-cache-control",
|
|
60
|
+
"surrogate-control"
|
|
61
|
+
]) {
|
|
62
|
+
if (getResponseHeader(event, header) !== undefined) setHeader(event, header, "no-store");
|
|
63
|
+
}
|
|
54
64
|
}
|
|
55
65
|
export function setMarkdownHeaders(event, ctx, sourceHeaders) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
export async function ensureSiteConfig(event) {
|
|
85
|
-
if (!event.context._initedSiteConfig)
|
|
86
|
-
await initRequestSiteConfig(event, getRequestURL(event, { xForwardedHost: true, xForwardedProto: true }).origin, getRouteRuleMatcher(useRuntimeConfig(event))(event.path));
|
|
87
|
-
}
|
|
88
|
-
export function buildNegotiationContext(event, path) {
|
|
89
|
-
const runtimeConfig = useRuntimeConfig(event);
|
|
90
|
-
const baseURL = runtimeConfig.app.baseURL;
|
|
91
|
-
const resolvePath = (target) => toDeployedRoute(target, baseURL);
|
|
92
|
-
return {
|
|
93
|
-
config: runtimeConfig["nuxt-ai-ready"],
|
|
94
|
-
path,
|
|
95
|
-
resolvePath,
|
|
96
|
-
resolveUrl: (target) => siteConfigUtils.withSiteUrl(event, resolvePath(target), { withBase: true }),
|
|
97
|
-
routeContext: { host: getRequestHost(event, { xForwardedHost: true }) }
|
|
98
|
-
};
|
|
66
|
+
setHeader(event, "content-type", "text/markdown; charset=utf-8");
|
|
67
|
+
// Usage policy survives a representation change. An explicit twin policy wins.
|
|
68
|
+
const sourcePolicy = sourceHeaders?.get("content-signal");
|
|
69
|
+
if (sourcePolicy !== null && sourcePolicy !== undefined && getResponseHeader(event, "content-signal") === undefined) setHeader(event, "content-signal", sourcePolicy);
|
|
70
|
+
const vary = [getResponseHeader(event, "vary"), sourceHeaders?.get("vary")].filter(Boolean).join(", ");
|
|
71
|
+
setHeader(event, "vary", mergeVaryHeader(vary, "Accept"));
|
|
72
|
+
setLinkHeader(event, ctx, "markdown");
|
|
73
|
+
// A representation change must not turn a private response into public content.
|
|
74
|
+
const privateResponse = [
|
|
75
|
+
"cache-control",
|
|
76
|
+
"cdn-cache-control",
|
|
77
|
+
"cloudflare-cdn-cache-control",
|
|
78
|
+
"netlify-cdn-cache-control",
|
|
79
|
+
"vercel-cdn-cache-control",
|
|
80
|
+
"surrogate-control"
|
|
81
|
+
].some((header) => {
|
|
82
|
+
const value = `${getResponseHeader(event, header) || ""},${sourceHeaders?.get(header) || ""}`;
|
|
83
|
+
return /(?:^|,)\s*(?:private|no-store|no-cache)\s*(?:,|=|$)/i.test(value);
|
|
84
|
+
});
|
|
85
|
+
if (getHeader(event, "cookie") || getHeader(event, "authorization") || getResponseHeader(event, "set-cookie") || sourceHeaders?.has("set-cookie") || privateResponse) {
|
|
86
|
+
setUncacheableHeaders(event);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const cacheHeaders = ctx.config.markdownCacheHeaders;
|
|
90
|
+
if (cacheHeaders) {
|
|
91
|
+
const { maxAge, swr } = cacheHeaders;
|
|
92
|
+
setHeader(event, "cache-control", swr ? `public, max-age=${maxAge}, stale-while-revalidate=${maxAge}` : `public, max-age=${maxAge}`);
|
|
93
|
+
}
|
|
99
94
|
}
|
|
100
95
|
const REQUEST_DECISION = Symbol("nuxt-ai-ready:negotiation");
|
|
96
|
+
// Reuse the compiled radix router when request config copies have equal inputs.
|
|
101
97
|
let matcherCache;
|
|
102
98
|
function getRouteRuleMatcher(runtimeConfig) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
const key = JSON.stringify([runtimeConfig.app?.baseURL, runtimeConfig.nitro?.routeRules]);
|
|
100
|
+
if (matcherCache?.key !== key) {
|
|
101
|
+
matcherCache = {
|
|
102
|
+
key,
|
|
103
|
+
match: createNitroRouteRuleMatcher(runtimeConfig)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return matcherCache.match;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Site config is set up by a Nitro middleware. The early negotiation handler
|
|
110
|
+
* runs in front of that middleware, so it must run the setup itself before it
|
|
111
|
+
* builds absolute URLs. The setup is idempotent.
|
|
112
|
+
*/
|
|
113
|
+
export async function ensureSiteConfig(event) {
|
|
114
|
+
const context = event.context;
|
|
115
|
+
if (!context._initedSiteConfig) {
|
|
116
|
+
const owner = event.node?.req ?? event.req ?? event;
|
|
117
|
+
const cached = context[REQUEST_DECISION];
|
|
118
|
+
const routeRule = cached && cached.owner === owner && cached.path === event.path ? cached.routeRule : getRouteRuleMatcher(useRuntimeConfig(event))(event.path);
|
|
119
|
+
await initRequestSiteConfig(event, getRequestURL(event, {
|
|
120
|
+
xForwardedHost: true,
|
|
121
|
+
xForwardedProto: true
|
|
122
|
+
}).origin, routeRule);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export function buildNegotiationContext(event, path) {
|
|
126
|
+
const runtimeConfig = useRuntimeConfig(event);
|
|
127
|
+
const baseURL = runtimeConfig.app.baseURL;
|
|
128
|
+
const resolvePath = (target) => toDeployedRoute(target, baseURL);
|
|
129
|
+
return {
|
|
130
|
+
config: runtimeConfig["nuxt-ai-ready"],
|
|
131
|
+
path,
|
|
132
|
+
resolvePath,
|
|
133
|
+
resolveUrl: (target) => siteConfigUtils.withSiteUrl(event, resolvePath(target), { withBase: true }),
|
|
134
|
+
routeContext: { host: getRequestHost(event, { xForwardedHost: true }) }
|
|
135
|
+
};
|
|
107
136
|
}
|
|
108
137
|
export function decideNegotiation(event, stage) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
const pathSkip = resolveNegotiationPathSkip(event.path, agentSkillArtifactPaths());
|
|
139
|
+
if (pathSkip) return pathSkip;
|
|
140
|
+
const context = event.context;
|
|
141
|
+
const owner = event.node?.req ?? event.req ?? event;
|
|
142
|
+
let cached = context[REQUEST_DECISION];
|
|
143
|
+
let request;
|
|
144
|
+
if (!cached || cached.owner !== owner || cached.path !== event.path) {
|
|
145
|
+
request = toMarkdownRequest(event);
|
|
146
|
+
// A disabled policy still identifies every config-independent skip. Pages
|
|
147
|
+
// continue below with event config, including request-time env overrides.
|
|
148
|
+
const eligibility = resolveNegotiationDecision({
|
|
149
|
+
stage: "middleware",
|
|
150
|
+
request,
|
|
151
|
+
routeRule: {},
|
|
152
|
+
policy: "disabled",
|
|
153
|
+
artifactPaths: agentSkillArtifactPaths()
|
|
154
|
+
});
|
|
155
|
+
if (eligibility._tag === "skip") return eligibility;
|
|
156
|
+
}
|
|
157
|
+
const runtimeConfig = useRuntimeConfig(event);
|
|
158
|
+
const config = runtimeConfig["nuxt-ai-ready"];
|
|
159
|
+
if (!cached || cached.owner !== owner || cached.path !== event.path || cached.policy !== config.contentNegotiation || cached.botNegotiation !== config.botNegotiation) {
|
|
160
|
+
const markdownPaths = prerenderedMarkdownPaths;
|
|
161
|
+
const routeRule = getRouteRuleMatcher(runtimeConfig)(event.path);
|
|
162
|
+
cached = {
|
|
163
|
+
owner,
|
|
164
|
+
path: event.path,
|
|
165
|
+
policy: config.contentNegotiation,
|
|
166
|
+
botNegotiation: config.botNegotiation,
|
|
167
|
+
routeRule,
|
|
168
|
+
decision: resolveNegotiationDecision({
|
|
169
|
+
stage: "middleware",
|
|
170
|
+
request: request ?? toMarkdownRequest(event),
|
|
171
|
+
routeRule,
|
|
172
|
+
policy: config.contentNegotiation,
|
|
173
|
+
botNegotiation: config.botNegotiation,
|
|
174
|
+
artifactPaths: agentSkillArtifactPaths(),
|
|
175
|
+
hasPrerenderedMarkdown: markdownPaths && !import.meta.prerender ? (path) => markdownPaths.has(decodePath(toDeployedRoute(path, runtimeConfig.app.baseURL))) : undefined
|
|
176
|
+
})
|
|
177
|
+
};
|
|
178
|
+
context[REQUEST_DECISION] = cached;
|
|
179
|
+
}
|
|
180
|
+
// Explicit Markdown must still wait behind static assets and auth middleware.
|
|
181
|
+
return stage === "early" && (cached.decision._tag === "render" || cached.decision._tag === "missing-markdown") ? {
|
|
182
|
+
_tag: "skip",
|
|
183
|
+
reason: "deferred"
|
|
184
|
+
} : cached.decision;
|
|
147
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Apply one negotiation decision to the response.
|
|
188
|
+
*
|
|
189
|
+
* Returns the response value when H3 requires one. Pass-through and `render`
|
|
190
|
+
* decisions return undefined because the caller owns the next step.
|
|
191
|
+
*/
|
|
148
192
|
export async function applyNegotiation(event, decision) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
193
|
+
if (decision._tag === "skip" || decision._tag === "render" || decision._tag === "missing-markdown") return;
|
|
194
|
+
// The early handler and the middleware both run for a pass-through request.
|
|
195
|
+
// Without this guard the second pass appends a duplicate Vary header.
|
|
196
|
+
const context = event.context;
|
|
197
|
+
if (context[APPLIED_KEY]) return;
|
|
198
|
+
context[APPLIED_KEY] = true;
|
|
199
|
+
if (decision._tag === "not-acceptable") {
|
|
200
|
+
appendHeader(event, "vary", decision.vary);
|
|
201
|
+
setUncacheableHeaders(event);
|
|
202
|
+
throw createError({
|
|
203
|
+
statusCode: 406,
|
|
204
|
+
statusMessage: "Not Acceptable",
|
|
205
|
+
message: "Supported types: text/html, text/markdown, text/plain"
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
await ensureSiteConfig(event);
|
|
209
|
+
const ctx = buildNegotiationContext(event, decision.path);
|
|
210
|
+
// Implicit HTML pass-through: advertise the Markdown alternate and let the
|
|
211
|
+
// HTML response continue.
|
|
212
|
+
if (decision._tag === "html") {
|
|
213
|
+
if (decision.negotiation._tag === "enabled") appendHeader(event, "vary", decision.negotiation.vary);
|
|
214
|
+
if (decision.markdownAvailable === false) {
|
|
215
|
+
event.context.aiReadyMarkdownAvailable = false;
|
|
216
|
+
ctx.config = {
|
|
217
|
+
...ctx.config,
|
|
218
|
+
markdownAvailable: false
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
setStatusAwareHeader(event, ctx, "html");
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
// Implicit markdown: redirect to the `.md` twin so the prerendered file (or
|
|
225
|
+
// the `.md` handler) answers. This keeps HTML and Markdown under separate
|
|
226
|
+
// cache keys, which matters on CDNs that ignore Vary.
|
|
227
|
+
appendHeader(event, "vary", decision.vary);
|
|
228
|
+
setLinkHeader(event, ctx, "html");
|
|
229
|
+
setUncacheableHeaders(event);
|
|
230
|
+
return sendRedirect(event, ctx.resolvePath(toMarkdownPath(decision.path)), 307);
|
|
180
231
|
}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
function toIsoDate(value) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return Number.isNaN(date.getTime()) ? "" : date.toISOString();
|
|
2
|
+
if (!value) return "";
|
|
3
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
4
|
+
return Number.isNaN(date.getTime()) ? "" : date.toISOString();
|
|
6
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Resolve when a page's content last changed, from sources that know it.
|
|
8
|
+
*
|
|
9
|
+
* Returns an empty string when no source gives a valid date. The index time is
|
|
10
|
+
* never a fallback: it moves on every deploy or re-index, so a sitemap lastmod
|
|
11
|
+
* built from it tells crawlers every page changed, and they learn to ignore it.
|
|
12
|
+
*/
|
|
7
13
|
export function resolvePageUpdatedAt(sitemapLastmod, metaUpdatedAt) {
|
|
8
|
-
|
|
14
|
+
return toIsoDate(metaUpdatedAt) || toIsoDate(sitemapLastmod);
|
|
9
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Date a runtime-indexed page. A declared date always wins. Otherwise a page
|
|
18
|
+
* gets the detection time only when its body hash differs from an earlier
|
|
19
|
+
* runtime index of the same page. A prerender hash comes from another pipeline,
|
|
20
|
+
* so a difference there proves nothing and never produces a date.
|
|
21
|
+
*/
|
|
10
22
|
export function resolveIndexedUpdatedAt(input) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return "";
|
|
18
|
-
if (previous.source === "runtime" && previous.contentHash !== input.contentHash)
|
|
19
|
-
return input.now.toISOString();
|
|
20
|
-
return previous.updatedAt;
|
|
23
|
+
if (input.declared) return input.declared;
|
|
24
|
+
if (!input.detectDrift) return "";
|
|
25
|
+
const { previous } = input;
|
|
26
|
+
if (!previous?.contentHash) return "";
|
|
27
|
+
if (previous.source === "runtime" && previous.contentHash !== input.contentHash) return input.now.toISOString();
|
|
28
|
+
return previous.updatedAt;
|
|
21
29
|
}
|
|
@@ -1,27 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* In-memory handover of rendered HTML from a page's SSR render to its `.md`
|
|
3
|
+
* twin during prerendering.
|
|
4
|
+
*
|
|
5
|
+
* The `.md` route is queued via `prerenderRoutes()` while the page's own HTML
|
|
6
|
+
* render is in flight, so the page always renders before its `.md` twin is
|
|
7
|
+
* processed. The html-capture plugin stores the rendered HTML here and the
|
|
8
|
+
* markdown prerender middleware consumes it, avoiding a full second SSR render
|
|
9
|
+
* per page (see nuxt/nuxt#35590).
|
|
10
|
+
*
|
|
11
|
+
* Entries are deleted on consume; the few that are never consumed (error/noSSR
|
|
12
|
+
* pages get no `.md` twin) live only for the prerender process lifetime.
|
|
13
|
+
*/
|
|
14
|
+
const htmlByPath = new Map();
|
|
15
|
+
const contentSignalByPath = new Map();
|
|
16
|
+
// Match the key derivation of getMarkdownRenderInfo/toMarkdownPath: `/about/`
|
|
17
|
+
// renders `/about.md`, whose page path resolves to `/about`.
|
|
3
18
|
function normalizeHtmlCachePath(path) {
|
|
4
|
-
|
|
19
|
+
return path.replace(/\/+$/, "") || "/";
|
|
5
20
|
}
|
|
6
21
|
export function storePrerenderedHtml(path, html) {
|
|
7
|
-
|
|
22
|
+
htmlByPath.set(normalizeHtmlCachePath(path), html);
|
|
8
23
|
}
|
|
24
|
+
/** Only rendered pages can hand a policy to a Markdown twin. */
|
|
9
25
|
export function storePrerenderedContentSignal(path, policy) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
contentSignalByPath.set(key, policy);
|
|
26
|
+
const key = normalizeHtmlCachePath(path);
|
|
27
|
+
if (htmlByPath.has(key)) contentSignalByPath.set(key, policy);
|
|
13
28
|
}
|
|
14
29
|
export function consumePrerenderedContentSignal(path) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
30
|
+
const key = normalizeHtmlCachePath(path);
|
|
31
|
+
const policy = contentSignalByPath.get(key);
|
|
32
|
+
contentSignalByPath.delete(key);
|
|
33
|
+
return policy;
|
|
19
34
|
}
|
|
20
35
|
export function consumePrerenderedHtml(path) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return `<!DOCTYPE html><html ${html.htmlAttrs.join(" ")}><head>${html.head.join("")}</head><body ${html.bodyAttrs.join(" ")}>${html.bodyPrepend.join("")}${html.body.join("")}${html.bodyAppend.join("")}</body></html>`;
|
|
36
|
+
const key = normalizeHtmlCachePath(path);
|
|
37
|
+
const html = htmlByPath.get(key);
|
|
38
|
+
htmlByPath.delete(key);
|
|
39
|
+
if (!html || typeof html === "string") return html;
|
|
40
|
+
return `<!DOCTYPE html><html ${html.htmlAttrs.join(" ")}><head>${html.head.join("")}</head><body ${html.bodyAttrs.join(" ")}>${html.bodyPrepend.join("")}${html.body.join("")}${html.bodyAppend.join("")}</body></html>`;
|
|
27
41
|
}
|