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
|
@@ -1,74 +1,85 @@
|
|
|
1
1
|
import { resolveLocaleAlternateUrl } from "../../i18n-url.js";
|
|
2
2
|
import { toMarkdownPath } from "../../markdown-path.js";
|
|
3
3
|
import { computeLocaleAlternates } from "./i18n.js";
|
|
4
|
+
/**
|
|
5
|
+
* Encode a URL path for safe inclusion in an HTTP header value.
|
|
6
|
+
* HTTP header values must be ASCII-only per RFC 9110 §5.5, so paths containing
|
|
7
|
+
* non-Latin characters (e.g. Chinese, Cyrillic) must be percent-encoded or
|
|
8
|
+
* Cloudflare (and other RFC-compliant runtimes) will reject the header.
|
|
9
|
+
* `encodeURI` preserves `/` separators and other reserved URL characters.
|
|
10
|
+
*/
|
|
4
11
|
export function encodePathForHeader(path) {
|
|
5
|
-
|
|
12
|
+
return encodeURI(path);
|
|
6
13
|
}
|
|
7
14
|
export const LLMS_TXT_PATH = "/llms.txt";
|
|
8
15
|
function resolveHeaderUrl(path, resolveUrl) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
+
if (!resolveUrl) return path;
|
|
17
|
+
try {
|
|
18
|
+
return resolveUrl(path);
|
|
19
|
+
} catch {
|
|
20
|
+
return path;
|
|
21
|
+
}
|
|
16
22
|
}
|
|
23
|
+
/** Build the request-specific links shared by success and error responses. */
|
|
17
24
|
function buildBaseParts(path, variant, config, resolveUrl) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return parts;
|
|
25
|
+
const parts = [];
|
|
26
|
+
if (variant === "html") {
|
|
27
|
+
if (config.markdownAvailable !== false) {
|
|
28
|
+
const href = resolveHeaderUrl(toMarkdownPath(path), resolveUrl);
|
|
29
|
+
parts.push(`<${encodePathForHeader(href)}>; rel="alternate"; type="text/markdown"`);
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
const href = resolveHeaderUrl(path, resolveUrl);
|
|
33
|
+
parts.push(`<${encodePathForHeader(href)}>; rel="alternate"; type="text/html"`);
|
|
34
|
+
parts.push(`<${encodePathForHeader(href)}>; rel="canonical"`);
|
|
35
|
+
}
|
|
36
|
+
if (config.describedby !== false) {
|
|
37
|
+
const href = resolveHeaderUrl(LLMS_TXT_PATH, resolveUrl);
|
|
38
|
+
parts.push(`<${encodePathForHeader(href)}>; rel="describedby"`);
|
|
39
|
+
}
|
|
40
|
+
if (config.aiTerms) parts.push(`<${config.aiTerms.href}>; rel="ai-terms"`);
|
|
41
|
+
return parts;
|
|
36
42
|
}
|
|
37
43
|
function appendLocaleParts(parts, path, variant, config, resolveUrl, routeContext) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
if (config.i18n) {
|
|
45
|
+
const alternates = computeLocaleAlternates(path, config.i18n, routeContext);
|
|
46
|
+
for (const alt of alternates) {
|
|
47
|
+
const alternatePath = variant === "markdown" ? toMarkdownPath(alt.path) : alt.path;
|
|
48
|
+
const href = resolveLocaleAlternateUrl({
|
|
49
|
+
...alt,
|
|
50
|
+
path: alternatePath
|
|
51
|
+
}, (candidate) => resolveHeaderUrl(candidate, resolveUrl));
|
|
52
|
+
parts.push(`<${encodePathForHeader(href)}>; rel="alternate"; hreflang="${alt.hreflang}"`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
49
55
|
}
|
|
50
56
|
function appendCatalogPart(parts, config) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
if (config.apiCatalog) {
|
|
58
|
+
const catalog = `<${encodePathForHeader(config.apiCatalog.href)}>; rel="api-catalog"`;
|
|
59
|
+
parts.push(catalog);
|
|
60
|
+
return catalog;
|
|
61
|
+
}
|
|
56
62
|
}
|
|
57
63
|
export function buildLinkHeader(path, variant, config, resolveUrl, routeContext = {}) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
const parts = buildBaseParts(path, variant, config, resolveUrl);
|
|
65
|
+
appendLocaleParts(parts, path, variant, config, resolveUrl, routeContext);
|
|
66
|
+
appendCatalogPart(parts, config);
|
|
67
|
+
return parts.join(", ");
|
|
62
68
|
}
|
|
69
|
+
/** Resolve request-specific URLs once for both success and error responses. */
|
|
63
70
|
export function buildStatusAwareLinkHeaders(path, variant, config, resolveUrl, routeContext = {}) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
const parts = buildBaseParts(path, variant, config, resolveUrl);
|
|
72
|
+
const safeParts = parts.slice();
|
|
73
|
+
const catalog = appendCatalogPart(safeParts, config);
|
|
74
|
+
const error = safeParts.join(", ");
|
|
75
|
+
if (!config.i18n) return {
|
|
76
|
+
error,
|
|
77
|
+
success: error
|
|
78
|
+
};
|
|
79
|
+
appendLocaleParts(parts, path, variant, config, resolveUrl, routeContext);
|
|
80
|
+
if (catalog) parts.push(catalog);
|
|
81
|
+
return {
|
|
82
|
+
error,
|
|
83
|
+
success: parts.join(", ")
|
|
84
|
+
};
|
|
74
85
|
}
|
|
@@ -5,57 +5,47 @@ import { escapeMarkdownHtml } from "../../markdown-text.js";
|
|
|
5
5
|
const RE_FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---\r?\n*/;
|
|
6
6
|
const RE_INLINE_WHITESPACE = /\s+/g;
|
|
7
7
|
function imageMetadataFence(frontmatter) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
images[key.value] = value.value;
|
|
20
|
-
}
|
|
21
|
-
if (!Object.keys(images).length)
|
|
22
|
-
return;
|
|
23
|
-
return `\`\`\`yaml
|
|
24
|
-
${stringify({ meta: images }, { lineWidth: 0 }).trimEnd()}
|
|
25
|
-
\`\`\``;
|
|
8
|
+
const document = parseDocument(frontmatter);
|
|
9
|
+
const meta = document.get("meta", true);
|
|
10
|
+
if (document.errors.length || !isMap(meta)) return;
|
|
11
|
+
const images = {};
|
|
12
|
+
for (const { key, value } of meta.items) {
|
|
13
|
+
if (!isScalar(key) || typeof key.value !== "string" || !isScalar(value)) continue;
|
|
14
|
+
if (key.value !== "og:image" && !key.value.startsWith("og:image:") && key.value !== "twitter:image" && !key.value.startsWith("twitter:image:")) continue;
|
|
15
|
+
if (typeof value.value === "string" || typeof value.value === "number" && Number.isFinite(value.value)) images[key.value] = value.value;
|
|
16
|
+
}
|
|
17
|
+
if (!Object.keys(images).length) return;
|
|
18
|
+
return `\`\`\`yaml\n${stringify({ meta: images }, { lineWidth: 0 }).trimEnd()}\n\`\`\``;
|
|
26
19
|
}
|
|
27
20
|
export function formatPageForLlmsFullTxt(route, title, description, markdown, siteUrl) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
21
|
+
const canonicalUrl = siteUrl ? joinURL(siteUrl, route) : route;
|
|
22
|
+
const pageTitle = escapeMarkdownHtml((title && title !== route ? title : route).trim().replace(RE_INLINE_WHITESPACE, " "));
|
|
23
|
+
const pageDescription = escapeMarkdownHtml(description.trim().replace(RE_INLINE_WHITESPACE, " "));
|
|
24
|
+
const content = markdown.replace(RE_FRONTMATTER, "").trim();
|
|
25
|
+
const parts = [
|
|
26
|
+
"---",
|
|
27
|
+
"",
|
|
28
|
+
`- **Page:** ${pageTitle}`,
|
|
29
|
+
`- **Source:** ${canonicalUrl}`
|
|
30
|
+
];
|
|
31
|
+
if (pageDescription) parts.push(`- **Description:** ${pageDescription}`);
|
|
32
|
+
const frontmatter = markdown.match(RE_FRONTMATTER)?.[1];
|
|
33
|
+
const images = frontmatter && imageMetadataFence(frontmatter);
|
|
34
|
+
if (images) parts.push("", images);
|
|
35
|
+
parts.push("");
|
|
36
|
+
if (content) {
|
|
37
|
+
parts.push(content);
|
|
38
|
+
parts.push("");
|
|
39
|
+
}
|
|
40
|
+
return `${parts.join("\n")}\n`;
|
|
46
41
|
}
|
|
47
42
|
export function buildLlmsFullTxtHeader(siteInfo, llmsTxtConfig) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
parts.push("", normalizedContent);
|
|
57
|
-
}
|
|
58
|
-
return `${parts.join("\n")}
|
|
59
|
-
|
|
60
|
-
`;
|
|
43
|
+
const parts = [`# ${escapeMarkdownHtml(siteInfo?.name || siteInfo?.url || "Site")}`];
|
|
44
|
+
if (siteInfo?.description) parts.push("", `> ${escapeMarkdownHtml(siteInfo.description)}`);
|
|
45
|
+
if (siteInfo?.url) parts.push("", `Canonical Origin: ${siteInfo.url}`);
|
|
46
|
+
if (llmsTxtConfig) {
|
|
47
|
+
const normalizedContent = normalizeLlmsTxtConfig(llmsTxtConfig);
|
|
48
|
+
if (normalizedContent) parts.push("", normalizedContent);
|
|
49
|
+
}
|
|
50
|
+
return `${parts.join("\n")}\n\n`;
|
|
61
51
|
}
|
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
import { markdownAlternatePath, toMarkdownPath } from "../../markdown-path.js";
|
|
2
2
|
const RE_ABSOLUTE_URL = /^(?:[a-z][a-z\d+.-]*:|\/\/)/i;
|
|
3
|
+
/**
|
|
4
|
+
* Map an upstream `Location` onto the markdown sibling of its target.
|
|
5
|
+
*
|
|
6
|
+
* A target on another origin, or one without a markdown sibling, keeps its
|
|
7
|
+
* original location. Query and fragment carry over to the sibling.
|
|
8
|
+
*/
|
|
3
9
|
export function resolveMarkdownRedirect(location, { pageUrl, origins = [] }) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
const page = new URL(pageUrl);
|
|
11
|
+
const target = URL.canParse(location, page) ? new URL(location, page) : null;
|
|
12
|
+
if (!target || target.origin !== page.origin && !origins.includes(target.origin)) return {
|
|
13
|
+
_tag: "redirect",
|
|
14
|
+
location
|
|
15
|
+
};
|
|
16
|
+
const markdownPath = markdownAlternatePath(target.pathname);
|
|
17
|
+
if (!markdownPath) return {
|
|
18
|
+
_tag: "redirect",
|
|
19
|
+
location
|
|
20
|
+
};
|
|
21
|
+
if (markdownPath === toMarkdownPath(page.pathname)) return {
|
|
22
|
+
_tag: "follow",
|
|
23
|
+
path: `${target.pathname}${target.search}`
|
|
24
|
+
};
|
|
25
|
+
const markdownLocation = `${markdownPath}${target.search}${target.hash}`;
|
|
26
|
+
return {
|
|
27
|
+
_tag: "redirect",
|
|
28
|
+
location: RE_ABSOLUTE_URL.test(location) ? `${target.origin}${markdownLocation}` : markdownLocation
|
|
29
|
+
};
|
|
18
30
|
}
|
|
@@ -1,62 +1,77 @@
|
|
|
1
1
|
import { negotiateContent, parseAcceptHeader } from "@mdream/js/negotiate";
|
|
2
2
|
import { getBotInfo } from "@nuxtjs/robots/util";
|
|
3
3
|
import { getHeaders } from "#nuxtseo/h3";
|
|
4
|
-
import { hasMarkdownTwin
|
|
5
|
-
const RE_MD_EXT = /\.md$/;
|
|
4
|
+
import { hasMarkdownTwin } from "../../markdown-path.js";
|
|
6
5
|
export function toMarkdownRequest(event, isPrerender = !!import.meta.prerender) {
|
|
7
|
-
|
|
6
|
+
return {
|
|
7
|
+
path: event.path,
|
|
8
|
+
headers: getHeaders(event),
|
|
9
|
+
isPrerender
|
|
10
|
+
};
|
|
8
11
|
}
|
|
12
|
+
// Bot negotiation is optional. Default negotiation depends only on Accept.
|
|
9
13
|
export function negotiateRequestRepresentation(request, botNegotiation = false) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
if (request.isPrerender || request.headers["x-nitro-prerender"]) return "html";
|
|
15
|
+
const accept = request.headers.accept;
|
|
16
|
+
const preference = negotiateContent(accept);
|
|
17
|
+
if (!botNegotiation || preference !== "html" || request.headers["sec-fetch-dest"] === "document") return preference;
|
|
18
|
+
// A heuristic must not override an explicit Markdown rejection.
|
|
19
|
+
const entries = parseAcceptHeader(accept?.toLowerCase() || "");
|
|
20
|
+
const matching = [
|
|
21
|
+
"text/markdown",
|
|
22
|
+
"text/*",
|
|
23
|
+
"*/*"
|
|
24
|
+
].map((type) => entries.filter((entry) => entry.type === type)).find((group) => group.length > 0);
|
|
25
|
+
if (matching && matching.every((entry) => entry.q === 0)) return preference;
|
|
26
|
+
const botInfo = getBotInfo(request.headers);
|
|
27
|
+
if (botInfo?.category === "ai") return "markdown";
|
|
28
|
+
return preference;
|
|
24
29
|
}
|
|
30
|
+
// H3 wrapper over the pure negotiation above.
|
|
25
31
|
export function negotiateRepresentation(event, botNegotiation = false) {
|
|
26
|
-
|
|
32
|
+
return negotiateRequestRepresentation(toMarkdownRequest(event), botNegotiation);
|
|
27
33
|
}
|
|
28
|
-
export function getRequestRenderInfo(request, mode = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
34
|
+
export function getRequestRenderInfo(request, mode = {
|
|
35
|
+
_tag: "runtime",
|
|
36
|
+
contentNegotiation: true
|
|
37
|
+
}) {
|
|
38
|
+
const queryIndex = request.path.indexOf("?");
|
|
39
|
+
const originalPath = queryIndex === -1 ? request.path : request.path.slice(0, queryIndex);
|
|
40
|
+
const isPrerender = mode._tag === "prerender";
|
|
41
|
+
const isExplicit = originalPath.endsWith(".md");
|
|
42
|
+
if (isPrerender && !isExplicit) return null;
|
|
43
|
+
const targetPath = isExplicit ? originalPath.slice(0, -3) : originalPath;
|
|
44
|
+
if (!hasMarkdownTwin(targetPath)) return null;
|
|
45
|
+
const accept = request.headers.accept || "";
|
|
46
|
+
if (!isExplicit && accept && /\b(?:application\/json|text\/event-stream)\b/i.test(accept) && !/text\/(?:html|markdown|plain)\b|\*\/\*/i.test(accept)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const negotiation = isPrerender ? "markdown" : mode.contentNegotiation ? negotiateRequestRepresentation(request, mode.botNegotiation) : "html";
|
|
50
|
+
if (isExplicit) {
|
|
51
|
+
const path = normalizePath(originalPath.slice(0, -3));
|
|
52
|
+
return {
|
|
53
|
+
path,
|
|
54
|
+
isExplicit: true,
|
|
55
|
+
negotiation: "markdown"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (negotiation === "not-acceptable") return { notAcceptable: true };
|
|
59
|
+
return {
|
|
60
|
+
path: normalizePath(originalPath),
|
|
61
|
+
isExplicit: false,
|
|
62
|
+
negotiation
|
|
63
|
+
};
|
|
51
64
|
}
|
|
52
|
-
export function getMarkdownRenderInfo(event, mode = {
|
|
53
|
-
|
|
65
|
+
export function getMarkdownRenderInfo(event, mode = {
|
|
66
|
+
_tag: "runtime",
|
|
67
|
+
contentNegotiation: true
|
|
68
|
+
}) {
|
|
69
|
+
return getRequestRenderInfo(toMarkdownRequest(event), mode);
|
|
54
70
|
}
|
|
55
71
|
function normalizePath(path) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return path;
|
|
72
|
+
if (path.endsWith("/index")) return path.slice(0, -5) || "/";
|
|
73
|
+
return path;
|
|
59
74
|
}
|
|
60
75
|
export function clientPrefersMarkdown(event, botNegotiation = false) {
|
|
61
|
-
|
|
76
|
+
return negotiateRepresentation(event, botNegotiation) === "markdown";
|
|
62
77
|
}
|
|
@@ -50,3 +50,11 @@ export type NegotiationDecision = {
|
|
|
50
50
|
* the early handler, the middleware and unit tests.
|
|
51
51
|
*/
|
|
52
52
|
export declare function resolveNegotiationDecision(input: NegotiationInput): NegotiationDecision;
|
|
53
|
+
export declare function withoutQuery(path: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Skip requests that can never negotiate or render Markdown based on path
|
|
56
|
+
* alone, before reading headers, runtime config, or route rules.
|
|
57
|
+
*/
|
|
58
|
+
export declare function resolveNegotiationPathSkip(requestPath: string, artifactPaths?: ReadonlySet<string>): Extract<NegotiationDecision, {
|
|
59
|
+
_tag: 'skip';
|
|
60
|
+
}> | undefined;
|
|
@@ -1,40 +1,112 @@
|
|
|
1
|
-
import { toMarkdownPath } from "../../markdown-path.js";
|
|
1
|
+
import { hasMarkdownTwin, toMarkdownPath } from "../../markdown-path.js";
|
|
2
2
|
import { getContentNegotiationVary, resolveContentNegotiation } from "./content-negotiation.js";
|
|
3
3
|
import { getRequestRenderInfo } from "./markdown-request.js";
|
|
4
|
+
/** Marks an internal HTML fetch that must bypass content negotiation. */
|
|
4
5
|
export const INTERNAL_HEADER = "x-ai-ready-internal";
|
|
6
|
+
/**
|
|
7
|
+
* Decide how one request maps to an HTML or Markdown representation.
|
|
8
|
+
*
|
|
9
|
+
* Pure: every input arrives as data, so the same call answers the same way for
|
|
10
|
+
* the early handler, the middleware and unit tests.
|
|
11
|
+
*/
|
|
5
12
|
export function resolveNegotiationDecision(input) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
const { request, stage } = input;
|
|
14
|
+
const path = withoutQuery(request.path);
|
|
15
|
+
if (path.startsWith("/.well-known/")) return {
|
|
16
|
+
_tag: "skip",
|
|
17
|
+
reason: "well-known"
|
|
18
|
+
};
|
|
19
|
+
if (input.artifactPaths?.has(path)) return {
|
|
20
|
+
_tag: "skip",
|
|
21
|
+
reason: "artifact"
|
|
22
|
+
};
|
|
23
|
+
// Internal module requests need the HTML representation.
|
|
24
|
+
if (request.headers[INTERNAL_HEADER]) return {
|
|
25
|
+
_tag: "skip",
|
|
26
|
+
reason: "internal"
|
|
27
|
+
};
|
|
28
|
+
const pathSkip = resolveNegotiationPathSkip(path, input.artifactPaths);
|
|
29
|
+
if (pathSkip) return pathSkip;
|
|
30
|
+
const negotiation = resolveContentNegotiation({
|
|
31
|
+
policy: input.policy,
|
|
32
|
+
routeRule: input.routeRule,
|
|
33
|
+
botNegotiation: input.botNegotiation
|
|
34
|
+
});
|
|
35
|
+
const renderInfo = getRequestRenderInfo(request, {
|
|
36
|
+
_tag: "runtime",
|
|
37
|
+
contentNegotiation: negotiation._tag === "enabled",
|
|
38
|
+
botNegotiation: input.botNegotiation
|
|
39
|
+
});
|
|
40
|
+
if (!renderInfo) return {
|
|
41
|
+
_tag: "skip",
|
|
42
|
+
reason: "not-a-page"
|
|
43
|
+
};
|
|
44
|
+
if ("notAcceptable" in renderInfo) {
|
|
45
|
+
return {
|
|
46
|
+
_tag: "not-acceptable",
|
|
47
|
+
vary: getContentNegotiationVary(input.botNegotiation)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (renderInfo.isExplicit) {
|
|
51
|
+
// The early stage never renders. A prerendered `.md` file answers first, and
|
|
52
|
+
// rendering belongs behind any auth middleware the site registers.
|
|
53
|
+
if (stage === "early") return {
|
|
54
|
+
_tag: "skip",
|
|
55
|
+
reason: "deferred"
|
|
56
|
+
};
|
|
57
|
+
if (input.hasPrerenderedMarkdown) {
|
|
58
|
+
return input.hasPrerenderedMarkdown(path) ? {
|
|
59
|
+
_tag: "skip",
|
|
60
|
+
reason: "deferred"
|
|
61
|
+
} : { _tag: "missing-markdown" };
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
_tag: "render",
|
|
65
|
+
path: renderInfo.path
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (input.hasPrerenderedMarkdown?.(toMarkdownPath(renderInfo.path)) === false) {
|
|
69
|
+
return {
|
|
70
|
+
_tag: "html",
|
|
71
|
+
path: renderInfo.path,
|
|
72
|
+
negotiation,
|
|
73
|
+
markdownAvailable: false
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (renderInfo.negotiation === "markdown") {
|
|
77
|
+
return {
|
|
78
|
+
_tag: "redirect",
|
|
79
|
+
path: renderInfo.path,
|
|
80
|
+
vary: getContentNegotiationVary(input.botNegotiation)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
_tag: "html",
|
|
85
|
+
path: renderInfo.path,
|
|
86
|
+
negotiation
|
|
87
|
+
};
|
|
36
88
|
}
|
|
37
|
-
function withoutQuery(path) {
|
|
38
|
-
|
|
39
|
-
|
|
89
|
+
export function withoutQuery(path) {
|
|
90
|
+
const queryIndex = path.indexOf("?");
|
|
91
|
+
return queryIndex === -1 ? path : path.slice(0, queryIndex);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Skip requests that can never negotiate or render Markdown based on path
|
|
95
|
+
* alone, before reading headers, runtime config, or route rules.
|
|
96
|
+
*/
|
|
97
|
+
export function resolveNegotiationPathSkip(requestPath, artifactPaths) {
|
|
98
|
+
const path = withoutQuery(requestPath);
|
|
99
|
+
if (path.startsWith("/.well-known/")) return {
|
|
100
|
+
_tag: "skip",
|
|
101
|
+
reason: "well-known"
|
|
102
|
+
};
|
|
103
|
+
if (artifactPaths?.has(path)) return {
|
|
104
|
+
_tag: "skip",
|
|
105
|
+
reason: "artifact"
|
|
106
|
+
};
|
|
107
|
+
const targetPath = path.endsWith(".md") ? path.slice(0, -3) : path;
|
|
108
|
+
if (!hasMarkdownTwin(targetPath)) return {
|
|
109
|
+
_tag: "skip",
|
|
110
|
+
reason: "not-a-page"
|
|
111
|
+
};
|
|
40
112
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { H3Event } from '#nuxtseo/h3';
|
|
2
|
-
import type { ModulePublicRuntimeConfig } from '../../../module.
|
|
2
|
+
import type { ModulePublicRuntimeConfig } from '../../../module.mjs';
|
|
3
3
|
import type { RuntimeRouteContext } from './i18n.js';
|
|
4
4
|
import type { NegotiationDecision, NegotiationStage } from './negotiation-decision.js';
|
|
5
5
|
import { sendRedirect } from '#nuxtseo/h3';
|