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.
Files changed (161) hide show
  1. package/dist/agent-skills-config-CmZq9uWW.mjs +18 -0
  2. package/dist/agent-skills-zGLgFB6H.mjs +468 -0
  3. package/dist/cli.d.mts +1 -0
  4. package/dist/cli.mjs +656 -570
  5. package/dist/devtools/pages/ai-ready/debug.vue +9 -3
  6. package/dist/devtools/pages/ai-ready/index.vue +3 -1
  7. package/dist/devtools/pages/ai-ready/llms-txt.vue +15 -4
  8. package/dist/devtools/pages/ai-ready.vue +28 -4
  9. package/dist/module.d.mts +106 -112
  10. package/dist/module.json +3 -3
  11. package/dist/module.mjs +2732 -26
  12. package/dist/package-metadata-B1darl8W.mjs +28 -0
  13. package/dist/prerender-QMv07W4h.mjs +650 -0
  14. package/dist/runtime/app/composables/webmcp.js +90 -97
  15. package/dist/runtime/app/plugins/md-alternate.server.js +29 -26
  16. package/dist/runtime/app/plugins/md-hints.prerender.js +13 -15
  17. package/dist/runtime/app/plugins/webmcp.client.js +49 -53
  18. package/dist/runtime/app/webmcp-config.js +2 -2
  19. package/dist/runtime/cache-control.js +16 -10
  20. package/dist/runtime/i18n-url.js +6 -6
  21. package/dist/runtime/index.js +4 -12
  22. package/dist/runtime/llms-txt-directive.js +20 -13
  23. package/dist/runtime/llms-txt-files.js +188 -187
  24. package/dist/runtime/llms-txt-format.js +54 -55
  25. package/dist/runtime/llms-txt-i18n.js +22 -19
  26. package/dist/runtime/llms-txt-utils.js +140 -95
  27. package/dist/runtime/markdown-links.js +45 -39
  28. package/dist/runtime/markdown-path.js +29 -9
  29. package/dist/runtime/markdown-text.js +2 -1
  30. package/dist/runtime/mcp.js +5 -1
  31. package/dist/runtime/route-path.js +14 -8
  32. package/dist/runtime/server/db/drizzle/client.js +71 -75
  33. package/dist/runtime/server/db/drizzle/index.js +16 -28
  34. package/dist/runtime/server/db/drizzle/providers/bun.d.ts +2 -1
  35. package/dist/runtime/server/db/drizzle/providers/bun.js +10 -7
  36. package/dist/runtime/server/db/drizzle/providers/d1.js +16 -13
  37. package/dist/runtime/server/db/drizzle/providers/dbPath.js +60 -37
  38. package/dist/runtime/server/db/drizzle/providers/libsql.js +23 -11
  39. package/dist/runtime/server/db/drizzle/providers/neon.js +13 -10
  40. package/dist/runtime/server/db/drizzle/providers/node-sqlite.js +10 -7
  41. package/dist/runtime/server/db/drizzle/providers/postgres.js +13 -10
  42. package/dist/runtime/server/db/drizzle/queries.js +633 -532
  43. package/dist/runtime/server/db/drizzle/raw.js +200 -176
  44. package/dist/runtime/server/db/index.js +3 -0
  45. package/dist/runtime/server/db/queries.js +816 -607
  46. package/dist/runtime/server/db/schema/postgres.js +56 -50
  47. package/dist/runtime/server/db/schema/sqlite.js +56 -50
  48. package/dist/runtime/server/db/schema-sql.js +35 -38
  49. package/dist/runtime/server/db/seed.js +60 -45
  50. package/dist/runtime/server/db/shared.js +300 -213
  51. package/dist/runtime/server/index.js +1 -17
  52. package/dist/runtime/server/mcp/cache-key.js +5 -1
  53. package/dist/runtime/server/mcp/resources/pages.js +32 -33
  54. package/dist/runtime/server/mcp/tools/get-page-markdown.js +41 -27
  55. package/dist/runtime/server/mcp/tools/list-pages.js +40 -34
  56. package/dist/runtime/server/mcp/tools/search-pages.js +24 -16
  57. package/dist/runtime/server/middleware/markdown.d.ts +1 -1
  58. package/dist/runtime/server/middleware/markdown.js +15 -13
  59. package/dist/runtime/server/middleware/markdown.prerender.d.ts +1 -1
  60. package/dist/runtime/server/middleware/markdown.prerender.js +135 -119
  61. package/dist/runtime/server/middleware/render-markdown.d.ts +1 -1
  62. package/dist/runtime/server/middleware/render-markdown.js +164 -144
  63. package/dist/runtime/server/plugins/ai-terms.d.ts +1 -1
  64. package/dist/runtime/server/plugins/ai-terms.js +4 -8
  65. package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.d.ts +1 -1
  66. package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.js +7 -8
  67. package/dist/runtime/server/plugins/content-signal-capture.prerender.d.ts +1 -1
  68. package/dist/runtime/server/plugins/content-signal-capture.prerender.js +7 -7
  69. package/dist/runtime/server/plugins/db-lifecycle-nitro3.d.ts +1 -1
  70. package/dist/runtime/server/plugins/db-lifecycle-nitro3.js +13 -14
  71. package/dist/runtime/server/plugins/db-lifecycle.js +13 -11
  72. package/dist/runtime/server/plugins/html-capture.prerender.js +6 -6
  73. package/dist/runtime/server/plugins/link-header-nitro3.d.ts +1 -1
  74. package/dist/runtime/server/plugins/link-header-nitro3.js +23 -13
  75. package/dist/runtime/server/plugins/link-header.d.ts +1 -1
  76. package/dist/runtime/server/plugins/link-header.js +30 -30
  77. package/dist/runtime/server/plugins/llms-txt-directive-html.d.ts +1 -1
  78. package/dist/runtime/server/plugins/llms-txt-directive-html.js +4 -3
  79. package/dist/runtime/server/plugins/markdown-negotiation.d.ts +1 -1
  80. package/dist/runtime/server/plugins/markdown-negotiation.js +64 -45
  81. package/dist/runtime/server/plugins/sitemap-seeder.js +144 -112
  82. package/dist/runtime/server/routes/__ai-ready/cron.get.d.ts +1 -1
  83. package/dist/runtime/server/routes/__ai-ready/cron.get.js +17 -11
  84. package/dist/runtime/server/routes/__ai-ready/devtools.get.d.ts +1 -1
  85. package/dist/runtime/server/routes/__ai-ready/devtools.get.js +60 -45
  86. package/dist/runtime/server/routes/__ai-ready/pages.get.d.ts +36 -1
  87. package/dist/runtime/server/routes/__ai-ready/pages.get.js +44 -40
  88. package/dist/runtime/server/routes/__ai-ready/poll.post.d.ts +15 -1
  89. package/dist/runtime/server/routes/__ai-ready/poll.post.js +30 -30
  90. package/dist/runtime/server/routes/__ai-ready/prune.post.d.ts +13 -1
  91. package/dist/runtime/server/routes/__ai-ready/prune.post.js +29 -15
  92. package/dist/runtime/server/routes/__ai-ready/reindex.post.d.ts +22 -1
  93. package/dist/runtime/server/routes/__ai-ready/reindex.post.js +31 -21
  94. package/dist/runtime/server/routes/__ai-ready/restore.post.d.ts +4 -1
  95. package/dist/runtime/server/routes/__ai-ready/restore.post.js +28 -22
  96. package/dist/runtime/server/routes/__ai-ready/status.get.d.ts +1 -1
  97. package/dist/runtime/server/routes/__ai-ready/status.get.js +52 -53
  98. package/dist/runtime/server/routes/__ai-ready-debug.get.d.ts +83 -1
  99. package/dist/runtime/server/routes/__ai-ready-debug.get.js +209 -189
  100. package/dist/runtime/server/routes/agent-skills-artifact.d.ts +1 -1
  101. package/dist/runtime/server/routes/agent-skills-artifact.js +16 -14
  102. package/dist/runtime/server/routes/agent-skills-index.d.ts +1 -1
  103. package/dist/runtime/server/routes/agent-skills-index.js +8 -6
  104. package/dist/runtime/server/routes/ai-catalog.js +19 -19
  105. package/dist/runtime/server/routes/ai-terms.js +23 -19
  106. package/dist/runtime/server/routes/api-catalog.js +23 -23
  107. package/dist/runtime/server/routes/llms-full.txt.get.d.ts +1 -1
  108. package/dist/runtime/server/routes/llms-full.txt.get.js +42 -41
  109. package/dist/runtime/server/routes/llms.txt.get.d.ts +1 -1
  110. package/dist/runtime/server/routes/llms.txt.get.js +38 -33
  111. package/dist/runtime/server/routes/mcp-server-card.js +19 -19
  112. package/dist/runtime/server/routes/sitemap.md.get.d.ts +1 -1
  113. package/dist/runtime/server/routes/sitemap.md.get.js +38 -39
  114. package/dist/runtime/server/tasks/ai-ready-cron.d.ts +1 -1
  115. package/dist/runtime/server/tasks/ai-ready-cron.js +17 -14
  116. package/dist/runtime/server/utils/auth.js +76 -53
  117. package/dist/runtime/server/utils/batchIndex.js +72 -60
  118. package/dist/runtime/server/utils/checkStale.js +181 -134
  119. package/dist/runtime/server/utils/cloudflare-prerendered.js +23 -20
  120. package/dist/runtime/server/utils/cloudflare.js +69 -51
  121. package/dist/runtime/server/utils/content-negotiation.js +30 -18
  122. package/dist/runtime/server/utils/content.js +4 -1
  123. package/dist/runtime/server/utils/context.js +30 -19
  124. package/dist/runtime/server/utils/cron-plan.js +6 -6
  125. package/dist/runtime/server/utils/discovery-response.js +5 -6
  126. package/dist/runtime/server/utils/fetch.js +2 -1
  127. package/dist/runtime/server/utils/frontmatter.js +44 -57
  128. package/dist/runtime/server/utils/i18n.js +3 -8
  129. package/dist/runtime/server/utils/indexPage.js +152 -113
  130. package/dist/runtime/server/utils/keywords.js +278 -277
  131. package/dist/runtime/server/utils/link-header.js +67 -56
  132. package/dist/runtime/server/utils/llms-full.js +39 -49
  133. package/dist/runtime/server/utils/markdown-redirect.js +26 -14
  134. package/dist/runtime/server/utils/markdown-request.js +62 -47
  135. package/dist/runtime/server/utils/negotiation-decision.d.ts +8 -0
  136. package/dist/runtime/server/utils/negotiation-decision.js +106 -34
  137. package/dist/runtime/server/utils/negotiation-response.d.ts +1 -1
  138. package/dist/runtime/server/utils/negotiation-response.js +195 -144
  139. package/dist/runtime/server/utils/page-updated-at.js +23 -15
  140. package/dist/runtime/server/utils/prerender-html.js +31 -17
  141. package/dist/runtime/server/utils/runCron.js +263 -192
  142. package/dist/runtime/server/utils/sitemap-crawl-state.js +57 -39
  143. package/dist/runtime/server/utils/sitemap-lastmod.js +16 -14
  144. package/dist/runtime/server/utils/sitemap-md.js +39 -50
  145. package/dist/runtime/server/utils/sitemap-routes.js +7 -7
  146. package/dist/runtime/server/utils/sitemap.js +459 -414
  147. package/dist/runtime/server/utils.js +141 -122
  148. package/dist/runtime/site-tool-catalog.js +39 -43
  149. package/dist/runtime/site-tool-config.js +1 -0
  150. package/dist/runtime/sync-secret.js +11 -11
  151. package/dist/runtime/types.js +1 -0
  152. package/dist/runtime/webmcp-site-tools.js +278 -250
  153. package/dist/runtime/webmcp.js +53 -42
  154. package/dist/static-headers-G7hFL3wE.mjs +328 -0
  155. package/dist/types.d.mts +1 -9
  156. package/package.json +20 -24
  157. package/skills/nuxt-ai-ready/SKILL.md +8 -2
  158. package/dist/chunks/agent-skills.mjs +0 -383
  159. package/dist/chunks/prerender.mjs +0 -683
  160. package/dist/shared/nuxt-ai-ready.Bzx0dNWj.mjs +0 -3034
  161. 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
- return encodeURI(path);
12
+ return encodeURI(path);
6
13
  }
7
14
  export const LLMS_TXT_PATH = "/llms.txt";
8
15
  function resolveHeaderUrl(path, resolveUrl) {
9
- if (!resolveUrl)
10
- return path;
11
- try {
12
- return resolveUrl(path);
13
- } catch {
14
- return path;
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
- const parts = [];
19
- if (variant === "html") {
20
- if (config.markdownAvailable !== false) {
21
- const href = resolveHeaderUrl(toMarkdownPath(path), resolveUrl);
22
- parts.push(`<${encodePathForHeader(href)}>; rel="alternate"; type="text/markdown"`);
23
- }
24
- } else {
25
- const href = resolveHeaderUrl(path, resolveUrl);
26
- parts.push(`<${encodePathForHeader(href)}>; rel="alternate"; type="text/html"`);
27
- parts.push(`<${encodePathForHeader(href)}>; rel="canonical"`);
28
- }
29
- if (config.describedby !== false) {
30
- const href = resolveHeaderUrl(LLMS_TXT_PATH, resolveUrl);
31
- parts.push(`<${encodePathForHeader(href)}>; rel="describedby"`);
32
- }
33
- if (config.aiTerms)
34
- parts.push(`<${config.aiTerms.href}>; rel="ai-terms"`);
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
- if (config.i18n) {
39
- const alternates = computeLocaleAlternates(path, config.i18n, routeContext);
40
- for (const alt of alternates) {
41
- const alternatePath = variant === "markdown" ? toMarkdownPath(alt.path) : alt.path;
42
- const href = resolveLocaleAlternateUrl(
43
- { ...alt, path: alternatePath },
44
- (candidate) => resolveHeaderUrl(candidate, resolveUrl)
45
- );
46
- parts.push(`<${encodePathForHeader(href)}>; rel="alternate"; hreflang="${alt.hreflang}"`);
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
- if (config.apiCatalog) {
52
- const catalog = `<${encodePathForHeader(config.apiCatalog.href)}>; rel="api-catalog"`;
53
- parts.push(catalog);
54
- return catalog;
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
- const parts = buildBaseParts(path, variant, config, resolveUrl);
59
- appendLocaleParts(parts, path, variant, config, resolveUrl, routeContext);
60
- appendCatalogPart(parts, config);
61
- return parts.join(", ");
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
- const parts = buildBaseParts(path, variant, config, resolveUrl);
65
- const safeParts = parts.slice();
66
- const catalog = appendCatalogPart(safeParts, config);
67
- const error = safeParts.join(", ");
68
- if (!config.i18n)
69
- return { error, success: error };
70
- appendLocaleParts(parts, path, variant, config, resolveUrl, routeContext);
71
- if (catalog)
72
- parts.push(catalog);
73
- return { error, success: parts.join(", ") };
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
- const document = parseDocument(frontmatter);
9
- const meta = document.get("meta", true);
10
- if (document.errors.length || !isMap(meta))
11
- return;
12
- const images = {};
13
- for (const { key, value } of meta.items) {
14
- if (!isScalar(key) || typeof key.value !== "string" || !isScalar(value))
15
- continue;
16
- if (key.value !== "og:image" && !key.value.startsWith("og:image:") && key.value !== "twitter:image" && !key.value.startsWith("twitter:image:"))
17
- continue;
18
- if (typeof value.value === "string" || typeof value.value === "number" && Number.isFinite(value.value))
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
- const canonicalUrl = siteUrl ? joinURL(siteUrl, route) : route;
29
- const pageTitle = escapeMarkdownHtml((title && title !== route ? title : route).trim().replace(RE_INLINE_WHITESPACE, " "));
30
- const pageDescription = escapeMarkdownHtml(description.trim().replace(RE_INLINE_WHITESPACE, " "));
31
- const content = markdown.replace(RE_FRONTMATTER, "").trim();
32
- const parts = ["---", "", `- **Page:** ${pageTitle}`, `- **Source:** ${canonicalUrl}`];
33
- if (pageDescription)
34
- parts.push(`- **Description:** ${pageDescription}`);
35
- const frontmatter = markdown.match(RE_FRONTMATTER)?.[1];
36
- const images = frontmatter && imageMetadataFence(frontmatter);
37
- if (images)
38
- parts.push("", images);
39
- parts.push("");
40
- if (content) {
41
- parts.push(content);
42
- parts.push("");
43
- }
44
- return `${parts.join("\n")}
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
- const parts = [`# ${escapeMarkdownHtml(siteInfo?.name || siteInfo?.url || "Site")}`];
49
- if (siteInfo?.description)
50
- parts.push("", `> ${escapeMarkdownHtml(siteInfo.description)}`);
51
- if (siteInfo?.url)
52
- parts.push("", `Canonical Origin: ${siteInfo.url}`);
53
- if (llmsTxtConfig) {
54
- const normalizedContent = normalizeLlmsTxtConfig(llmsTxtConfig);
55
- if (normalizedContent)
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
- const page = new URL(pageUrl);
5
- const target = URL.canParse(location, page) ? new URL(location, page) : null;
6
- if (!target || target.origin !== page.origin && !origins.includes(target.origin))
7
- return { _tag: "redirect", location };
8
- const markdownPath = markdownAlternatePath(target.pathname);
9
- if (!markdownPath)
10
- return { _tag: "redirect", location };
11
- if (markdownPath === toMarkdownPath(page.pathname))
12
- return { _tag: "follow", path: `${target.pathname}${target.search}` };
13
- const markdownLocation = `${markdownPath}${target.search}${target.hash}`;
14
- return {
15
- _tag: "redirect",
16
- location: RE_ABSOLUTE_URL.test(location) ? `${target.origin}${markdownLocation}` : markdownLocation
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, isReservedPath } from "../../markdown-path.js";
5
- const RE_MD_EXT = /\.md$/;
4
+ import { hasMarkdownTwin } from "../../markdown-path.js";
6
5
  export function toMarkdownRequest(event, isPrerender = !!import.meta.prerender) {
7
- return { path: event.path, headers: getHeaders(event), isPrerender };
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
- if (request.isPrerender || request.headers["x-nitro-prerender"])
11
- return "html";
12
- const accept = request.headers.accept;
13
- const preference = negotiateContent(accept);
14
- if (!botNegotiation || preference !== "html" || request.headers["sec-fetch-dest"] === "document")
15
- return preference;
16
- const entries = parseAcceptHeader(accept?.toLowerCase() || "");
17
- const matching = ["text/markdown", "text/*", "*/*"].map((type) => entries.filter((entry) => entry.type === type)).find((group) => group.length > 0);
18
- if (matching && matching.every((entry) => entry.q === 0))
19
- return preference;
20
- const botInfo = getBotInfo(request.headers);
21
- if (botInfo?.category === "ai")
22
- return "markdown";
23
- return preference;
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
- return negotiateRequestRepresentation(toMarkdownRequest(event), botNegotiation);
32
+ return negotiateRequestRepresentation(toMarkdownRequest(event), botNegotiation);
27
33
  }
28
- export function getRequestRenderInfo(request, mode = { _tag: "runtime", contentNegotiation: true }) {
29
- const queryIndex = request.path.indexOf("?");
30
- const originalPath = queryIndex === -1 ? request.path : request.path.slice(0, queryIndex);
31
- const isPrerender = mode._tag === "prerender";
32
- if (isReservedPath(originalPath.replace(RE_MD_EXT, "")))
33
- return null;
34
- const accept = request.headers.accept || "";
35
- if (!originalPath.endsWith(".md") && accept && /\b(?:application\/json|text\/event-stream)\b/i.test(accept) && !/text\/(?:html|markdown|plain)\b|\*\/\*/i.test(accept)) {
36
- return null;
37
- }
38
- const isExplicit = originalPath.endsWith(".md");
39
- if (isPrerender && !isExplicit)
40
- return null;
41
- if (!isExplicit && !hasMarkdownTwin(originalPath))
42
- return null;
43
- const negotiation = isPrerender ? "markdown" : mode.contentNegotiation ? negotiateRequestRepresentation(request, mode.botNegotiation) : "html";
44
- if (isExplicit) {
45
- const path = normalizePath(originalPath.slice(0, -3));
46
- return { path, isExplicit: true, negotiation: "markdown" };
47
- }
48
- if (negotiation === "not-acceptable")
49
- return { notAcceptable: true };
50
- return { path: normalizePath(originalPath), isExplicit: false, negotiation };
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 = { _tag: "runtime", contentNegotiation: true }) {
53
- return getRequestRenderInfo(toMarkdownRequest(event), mode);
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
- if (path.endsWith("/index"))
57
- return path.slice(0, -5) || "/";
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
- return negotiateRepresentation(event, botNegotiation) === "markdown";
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
- const { request, stage } = input;
7
- const path = withoutQuery(request.path);
8
- if (path.startsWith("/.well-known/"))
9
- return { _tag: "skip", reason: "well-known" };
10
- if (input.artifactPaths?.has(path))
11
- return { _tag: "skip", reason: "artifact" };
12
- if (request.headers[INTERNAL_HEADER])
13
- return { _tag: "skip", reason: "internal" };
14
- const negotiation = resolveContentNegotiation({ policy: input.policy, routeRule: input.routeRule, botNegotiation: input.botNegotiation });
15
- const renderInfo = getRequestRenderInfo(request, {
16
- _tag: "runtime",
17
- contentNegotiation: negotiation._tag === "enabled",
18
- botNegotiation: input.botNegotiation
19
- });
20
- if (!renderInfo)
21
- return { _tag: "skip", reason: "not-a-page" };
22
- if ("notAcceptable" in renderInfo)
23
- return { _tag: "not-acceptable", vary: getContentNegotiationVary(input.botNegotiation) };
24
- if (renderInfo.isExplicit) {
25
- if (stage === "early")
26
- return { _tag: "skip", reason: "deferred" };
27
- if (input.hasPrerenderedMarkdown)
28
- return input.hasPrerenderedMarkdown(path) ? { _tag: "skip", reason: "deferred" } : { _tag: "missing-markdown" };
29
- return { _tag: "render", path: renderInfo.path };
30
- }
31
- if (input.hasPrerenderedMarkdown?.(toMarkdownPath(renderInfo.path)) === false)
32
- return { _tag: "html", path: renderInfo.path, negotiation, markdownAvailable: false };
33
- if (renderInfo.negotiation === "markdown")
34
- return { _tag: "redirect", path: renderInfo.path, vary: getContentNegotiationVary(input.botNegotiation) };
35
- return { _tag: "html", path: renderInfo.path, negotiation };
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
- const queryIndex = path.indexOf("?");
39
- return queryIndex === -1 ? path : path.slice(0, queryIndex);
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.js';
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';