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,37 +1,36 @@
1
1
  import { useEvent } from "#nuxtseo/nitro";
2
2
  import { countPages, queryPages } from "../../db/queries.js";
3
3
  export default {
4
- uri: "resource://nuxt-ai-ready/pages",
5
- name: "All Pages",
6
- description: "Page listing as JSON. Supports ?limit=N&offset=N query parameters for pagination.",
7
- metadata: {
8
- mimeType: "application/json"
9
- },
10
- cache: "1h",
11
- async handler(uri) {
12
- const event = useEvent();
13
- const limit = Math.min(Math.max(Number(uri.searchParams.get("limit")) || 100, 1), 500);
14
- const offset = Math.max(Number(uri.searchParams.get("offset")) || 0, 0);
15
- const pages = await queryPages(event, { limit, offset });
16
- const total = await countPages(event);
17
- return {
18
- contents: [{
19
- uri: uri.toString(),
20
- mimeType: "application/json",
21
- text: JSON.stringify({
22
- pages: pages.map((p) => ({
23
- route: p.route,
24
- title: p.title || p.route,
25
- description: p.description || "",
26
- headings: p.headings || void 0,
27
- keywords: p.keywords?.length ? p.keywords : void 0
28
- })),
29
- total,
30
- limit,
31
- offset,
32
- hasMore: offset + pages.length < total
33
- })
34
- }]
35
- };
36
- }
4
+ uri: "resource://nuxt-ai-ready/pages",
5
+ name: "All Pages",
6
+ description: "Page listing as JSON. Supports ?limit=N&offset=N query parameters for pagination.",
7
+ metadata: { mimeType: "application/json" },
8
+ cache: "1h",
9
+ async handler(uri) {
10
+ const event = useEvent();
11
+ const limit = Math.min(Math.max(Number(uri.searchParams.get("limit")) || 100, 1), 500);
12
+ const offset = Math.max(Number(uri.searchParams.get("offset")) || 0, 0);
13
+ const pages = await queryPages(event, {
14
+ limit,
15
+ offset
16
+ });
17
+ const total = await countPages(event);
18
+ return { contents: [{
19
+ uri: uri.toString(),
20
+ mimeType: "application/json",
21
+ text: JSON.stringify({
22
+ pages: pages.map((p) => ({
23
+ route: p.route,
24
+ title: p.title || p.route,
25
+ description: p.description || "",
26
+ headings: p.headings || undefined,
27
+ keywords: p.keywords?.length ? p.keywords : undefined
28
+ })),
29
+ total,
30
+ limit,
31
+ offset,
32
+ hasMore: offset + pages.length < total
33
+ })
34
+ }] };
35
+ }
37
36
  };
@@ -4,33 +4,47 @@ import { useEvent } from "#nuxtseo/nitro";
4
4
  import { normalizeSiteRoute, SITE_TOOL_CATALOG } from "../../../site-tool-catalog.js";
5
5
  import { queryPages } from "../../db/queries.js";
6
6
  import { siteToolCacheKey } from "../cache-key.js";
7
- const inputSchema = {
8
- route: z.string().describe(SITE_TOOL_CATALOG.get_page_markdown.parameters.route)
9
- };
7
+ const inputSchema = { route: z.string().describe(SITE_TOOL_CATALOG.get_page_markdown.parameters.route) };
10
8
  const tool = {
11
- name: SITE_TOOL_CATALOG.get_page_markdown.name,
12
- title: SITE_TOOL_CATALOG.get_page_markdown.title,
13
- description: SITE_TOOL_CATALOG.get_page_markdown.description,
14
- inputSchema,
15
- annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
16
- enabled: () => siteTools.getPageMarkdown.mcp.enabled,
17
- cache: { maxAge: "5m", getKey: siteToolCacheKey },
18
- async handler({ route }) {
19
- const path = normalizeSiteRoute(route);
20
- if (!path) {
21
- return {
22
- content: [{ type: "text", text: "A site route is required, such as /about. Call list_pages to see the available routes." }],
23
- isError: true
24
- };
25
- }
26
- const page = await queryPages(useEvent(), { route: path, includeMarkdown: true });
27
- if (!page) {
28
- return {
29
- content: [{ type: "text", text: `No indexed page found at ${path}. Call search_pages or list_pages to find the correct route.` }],
30
- isError: true
31
- };
32
- }
33
- return page.markdown;
34
- }
9
+ name: SITE_TOOL_CATALOG.get_page_markdown.name,
10
+ title: SITE_TOOL_CATALOG.get_page_markdown.title,
11
+ description: SITE_TOOL_CATALOG.get_page_markdown.description,
12
+ inputSchema,
13
+ annotations: {
14
+ readOnlyHint: true,
15
+ destructiveHint: false,
16
+ openWorldHint: false
17
+ },
18
+ enabled: () => siteTools.getPageMarkdown.mcp.enabled,
19
+ cache: {
20
+ maxAge: "5m",
21
+ getKey: siteToolCacheKey
22
+ },
23
+ async handler({ route }) {
24
+ const path = normalizeSiteRoute(route);
25
+ if (!path) {
26
+ return {
27
+ content: [{
28
+ type: "text",
29
+ text: "A site route is required, such as /about. Call list_pages to see the available routes."
30
+ }],
31
+ isError: true
32
+ };
33
+ }
34
+ const page = await queryPages(useEvent(), {
35
+ route: path,
36
+ includeMarkdown: true
37
+ });
38
+ if (!page) {
39
+ return {
40
+ content: [{
41
+ type: "text",
42
+ text: `No indexed page found at ${path}. Call search_pages or list_pages to find the correct route.`
43
+ }],
44
+ isError: true
45
+ };
46
+ }
47
+ return page.markdown;
48
+ }
35
49
  };
36
50
  export default tool;
@@ -5,41 +5,47 @@ import { SITE_TOOL_CATALOG } from "../../../site-tool-catalog.js";
5
5
  import { countPages, queryPages } from "../../db/queries.js";
6
6
  import { siteToolCacheKey } from "../cache-key.js";
7
7
  const inputSchema = {
8
- limit: z.number().int().min(1).max(50).optional().default(siteTools.listPages.defaultLimit).describe(
9
- `${SITE_TOOL_CATALOG.list_pages.parameters.limit} Defaults to ${siteTools.listPages.defaultLimit}.`
10
- ),
11
- offset: z.number().int().min(0).optional().default(0).describe(SITE_TOOL_CATALOG.list_pages.parameters.offset)
8
+ limit: z.number().int().min(1).max(50).optional().default(siteTools.listPages.defaultLimit).describe(`${SITE_TOOL_CATALOG.list_pages.parameters.limit} Defaults to ${siteTools.listPages.defaultLimit}.`),
9
+ offset: z.number().int().min(0).optional().default(0).describe(SITE_TOOL_CATALOG.list_pages.parameters.offset)
12
10
  };
13
11
  const tool = {
14
- name: SITE_TOOL_CATALOG.list_pages.name,
15
- title: SITE_TOOL_CATALOG.list_pages.title,
16
- description: SITE_TOOL_CATALOG.list_pages.description,
17
- inputSchema,
18
- annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
19
- enabled: () => siteTools.listPages.mcp.enabled,
20
- cache: { maxAge: "1h", getKey: siteToolCacheKey },
21
- async handler({ limit, offset }) {
22
- const event = useEvent();
23
- const pages = await queryPages(event, { limit, offset });
24
- const total = await countPages(event);
25
- return {
26
- content: [{
27
- type: "text",
28
- text: JSON.stringify({
29
- pages: pages.map((p) => ({
30
- route: p.route,
31
- title: p.title || p.route,
32
- description: p.description || "",
33
- headings: p.headings || void 0,
34
- keywords: p.keywords?.length ? p.keywords : void 0
35
- })),
36
- total,
37
- limit,
38
- offset,
39
- hasMore: offset + pages.length < total
40
- })
41
- }]
42
- };
43
- }
12
+ name: SITE_TOOL_CATALOG.list_pages.name,
13
+ title: SITE_TOOL_CATALOG.list_pages.title,
14
+ description: SITE_TOOL_CATALOG.list_pages.description,
15
+ inputSchema,
16
+ annotations: {
17
+ readOnlyHint: true,
18
+ destructiveHint: false,
19
+ openWorldHint: false
20
+ },
21
+ enabled: () => siteTools.listPages.mcp.enabled,
22
+ cache: {
23
+ maxAge: "1h",
24
+ getKey: siteToolCacheKey
25
+ },
26
+ async handler({ limit, offset }) {
27
+ const event = useEvent();
28
+ const pages = await queryPages(event, {
29
+ limit,
30
+ offset
31
+ });
32
+ const total = await countPages(event);
33
+ return { content: [{
34
+ type: "text",
35
+ text: JSON.stringify({
36
+ pages: pages.map((p) => ({
37
+ route: p.route,
38
+ title: p.title || p.route,
39
+ description: p.description || "",
40
+ headings: p.headings || undefined,
41
+ keywords: p.keywords?.length ? p.keywords : undefined
42
+ })),
43
+ total,
44
+ limit,
45
+ offset,
46
+ hasMore: offset + pages.length < total
47
+ })
48
+ }] };
49
+ }
44
50
  };
45
51
  export default tool;
@@ -5,23 +5,31 @@ import { SITE_TOOL_CATALOG } from "../../../site-tool-catalog.js";
5
5
  import { searchPages } from "../../db/queries.js";
6
6
  import { siteToolCacheKey } from "../cache-key.js";
7
7
  const inputSchema = {
8
- query: z.string().describe(SITE_TOOL_CATALOG.search_pages.parameters.query),
9
- limit: z.number().int().min(1).max(50).optional().default(siteTools.searchPages.defaultLimit).describe(
10
- `${SITE_TOOL_CATALOG.search_pages.parameters.limit} Defaults to ${siteTools.searchPages.defaultLimit}.`
11
- )
8
+ query: z.string().describe(SITE_TOOL_CATALOG.search_pages.parameters.query),
9
+ limit: z.number().int().min(1).max(50).optional().default(siteTools.searchPages.defaultLimit).describe(`${SITE_TOOL_CATALOG.search_pages.parameters.limit} Defaults to ${siteTools.searchPages.defaultLimit}.`)
12
10
  };
13
11
  const tool = {
14
- name: SITE_TOOL_CATALOG.search_pages.name,
15
- title: SITE_TOOL_CATALOG.search_pages.title,
16
- description: SITE_TOOL_CATALOG.search_pages.description,
17
- inputSchema,
18
- annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
19
- enabled: () => siteTools.searchPages.mcp.enabled,
20
- cache: { maxAge: "5m", getKey: siteToolCacheKey },
21
- async handler({ query, limit }) {
22
- const event = useEvent();
23
- const results = await searchPages(event, query, { limit });
24
- return { content: [{ type: "text", text: JSON.stringify(results) }] };
25
- }
12
+ name: SITE_TOOL_CATALOG.search_pages.name,
13
+ title: SITE_TOOL_CATALOG.search_pages.title,
14
+ description: SITE_TOOL_CATALOG.search_pages.description,
15
+ inputSchema,
16
+ annotations: {
17
+ readOnlyHint: true,
18
+ destructiveHint: false,
19
+ openWorldHint: false
20
+ },
21
+ enabled: () => siteTools.searchPages.mcp.enabled,
22
+ cache: {
23
+ maxAge: "5m",
24
+ getKey: siteToolCacheKey
25
+ },
26
+ async handler({ query, limit }) {
27
+ const event = useEvent();
28
+ const results = await searchPages(event, query, { limit });
29
+ return { content: [{
30
+ type: "text",
31
+ text: JSON.stringify(results)
32
+ }] };
33
+ }
26
34
  };
27
35
  export default tool;
@@ -1,2 +1,2 @@
1
- declare const _default: any;
1
+ declare const _default: import("#nuxtseo/h3").EventHandlerWithFetch<import("#nuxtseo/h3").EventHandlerRequest, Promise<string | Response | import("#nuxtseo/h3").HTTPError<unknown> | (import("#nuxtseo/h3").HTTPResponse | undefined)>>;
2
2
  export default _default;
@@ -1,19 +1,21 @@
1
1
  import { createError, defineEventHandler } from "#nuxtseo/h3";
2
2
  import { useRuntimeConfig } from "#nuxtseo/nitro";
3
+ import { withoutQuery } from "../utils/negotiation-decision.js";
3
4
  import { applyNegotiation, decideNegotiation } from "../utils/negotiation-response.js";
4
5
  import { isSitemapMdRequest } from "../utils/sitemap-md.js";
5
6
  export default defineEventHandler(async (event) => {
6
- if (event.path.split("?")[0]?.endsWith("/sitemap.md")) {
7
- const runtimeConfig = useRuntimeConfig(event);
8
- if (isSitemapMdRequest(event.path, runtimeConfig.app.baseURL, runtimeConfig["nuxt-ai-ready"]?.sitemapMd !== false))
9
- return;
10
- }
11
- const decision = decideNegotiation(event, "middleware");
12
- if (decision._tag === "missing-markdown")
13
- throw createError({ statusCode: 404, statusMessage: "Markdown page not found" });
14
- const negotiationResponse = await applyNegotiation(event, decision);
15
- if (decision._tag !== "render")
16
- return negotiationResponse;
17
- const { renderMarkdown } = await import("#ai-ready-virtual/render-markdown.mjs");
18
- return renderMarkdown?.(event, decision.path);
7
+ if (withoutQuery(event.path).endsWith("/sitemap.md")) {
8
+ const runtimeConfig = useRuntimeConfig(event);
9
+ if (isSitemapMdRequest(event.path, runtimeConfig.app.baseURL, runtimeConfig["nuxt-ai-ready"]?.sitemapMd !== false)) return;
10
+ }
11
+ const decision = decideNegotiation(event, "middleware");
12
+ if (decision._tag === "missing-markdown") throw createError({
13
+ statusCode: 404,
14
+ statusMessage: "Markdown page not found"
15
+ });
16
+ const negotiationResponse = await applyNegotiation(event, decision);
17
+ if (decision._tag !== "render") return negotiationResponse;
18
+ // Keep the converter and its dependencies off the HTML request path.
19
+ const { renderMarkdown } = await import("#ai-ready-virtual/render-markdown.mjs");
20
+ return renderMarkdown?.(event, decision.path);
19
21
  });
@@ -1,2 +1,2 @@
1
- declare const _default: any;
1
+ declare const _default: import("#nuxtseo/h3").EventHandlerWithFetch<import("#nuxtseo/h3").EventHandlerRequest, Promise<Response | import("#nuxtseo/h3").HTTPError<unknown> | undefined>>;
2
2
  export default _default;
@@ -13,126 +13,142 @@ import { getMarkdownRenderInfo } from "../utils/markdown-request.js";
13
13
  import { agentSkillArtifactPaths } from "../utils/negotiation-response.js";
14
14
  import { consumePrerenderedContentSignal, consumePrerenderedHtml } from "../utils/prerender-html.js";
15
15
  import { isSitemapMdRequest } from "../utils/sitemap-md.js";
16
+ // Pull headings out of source markdown for the page-data record. mdream
17
+ // produces a similar list during HTML conversion; this mirrors that shape so
18
+ // downstream consumers (search, MCP) don't need to special-case content
19
+ // pages. Regex is constructed locally so concurrent prerender requests don't
20
+ // share `lastIndex` state.
16
21
  function extractHeadingsFromMarkdown(markdown) {
17
- const headings = [];
18
- for (const m of markdown.matchAll(/^(#{1,6}) ([^\n]+)$/gm)) {
19
- const hashes = m[1];
20
- const text = m[2]?.trim();
21
- if (!hashes || !text)
22
- continue;
23
- headings.push({ [`h${hashes.length}`]: text });
24
- }
25
- return headings;
22
+ const headings = [];
23
+ for (const m of markdown.matchAll(/^(#{1,6}) ([^\n]+)$/gm)) {
24
+ const hashes = m[1];
25
+ const text = m[2]?.trim();
26
+ if (!hashes || !text) continue;
27
+ headings.push({ [`h${hashes.length}`]: text });
28
+ }
29
+ return headings;
26
30
  }
27
31
  export default defineEventHandler(async (event) => {
28
- if (event.path.startsWith("/.well-known/") || agentSkillArtifactPaths().has(event.path))
29
- return;
30
- if (!import.meta.prerender) {
31
- return;
32
- }
33
- const fullRuntimeConfig = useRuntimeConfig(event);
34
- if (isSitemapMdRequest(event.path, fullRuntimeConfig.app.baseURL, fullRuntimeConfig["nuxt-ai-ready"]?.sitemapMd !== false))
35
- return;
36
- const renderInfo = getMarkdownRenderInfo(event, { _tag: "prerender" });
37
- if (!renderInfo || "notAcceptable" in renderInfo)
38
- return;
39
- const { path } = renderInfo;
40
- let contentSignal = consumePrerenderedContentSignal(path);
41
- const runtimeConfig = fullRuntimeConfig["nuxt-ai-ready"];
42
- const deployedPath = toDeployedRoute(path, fullRuntimeConfig.app.baseURL);
43
- const canonicalUrl = withSiteUrl(event, deployedPath, { withBase: true });
44
- const contentPage = await tryGetContentMarkdown(event, path).catch((error) => {
45
- logger.debug(`[markdown.prerender] Content lookup failed for ${path}`, error);
46
- return null;
47
- });
48
- if (contentPage) {
49
- logger.debug(`[markdown.prerender] Using content source for ${path} (${contentPage.markdown.length} bytes)`);
50
- const frontmatter = buildFrontmatter({
51
- title: contentPage.title,
52
- description: contentPage.description,
53
- canonical_url: canonicalUrl,
54
- last_updated: contentPage.updatedAt
55
- });
56
- const markdown = `${frontmatter}
57
- ${absoluteMarkdownLinks(contentPage.markdown, canonicalUrl)}`;
58
- const headings = extractHeadingsFromMarkdown(contentPage.markdown);
59
- const keywords2 = extractKeywords(contentPage.markdown, "");
60
- return JSON.stringify({
61
- markdown,
62
- title: contentPage.title || "",
63
- description: contentPage.description || "",
64
- headings,
65
- keywords: keywords2,
66
- ...contentSignal !== void 0 && { contentSignal },
67
- // Only a real content date feeds the page index and sitemap lastmod.
68
- ...contentPage.updatedAt && { updatedAt: contentPage.updatedAt }
69
- });
70
- }
71
- let html = consumePrerenderedHtml(path);
72
- if (html) {
73
- logger.debug(`[markdown.prerender] Reusing prerendered HTML for ${path} (${html.length} bytes)`);
74
- } else {
75
- logger.debug(`[markdown.prerender] Fetching HTML for ${path}`);
76
- const response = await fetchRawWithEvent(event, deployedPath, { signal: AbortSignal.timeout(3e4) }).catch((err) => {
77
- if (err?.name === "TimeoutError" || err?.name === "AbortError") {
78
- throw createError({
79
- statusCode: 504,
80
- statusMessage: "Gateway Timeout",
81
- message: `Timed out fetching HTML for ${path}`
82
- });
83
- }
84
- throw err;
85
- });
86
- if (!response.ok) {
87
- return createError({
88
- statusCode: response.status,
89
- statusMessage: response.statusText,
90
- message: `Failed to fetch HTML for ${path}`
91
- });
92
- }
93
- if (!response.headers.get("content-type")?.includes("text/html")) {
94
- return createError({
95
- statusCode: 404,
96
- message: `Not an HTML page: ${path}`
97
- });
98
- }
99
- html = await response.text();
100
- const fetchedPolicy = response.headers.get("content-signal");
101
- const sharedPolicy = fullRuntimeConfig["nuxt-robots"]?.contentSignalHeader;
102
- if (fetchedPolicy !== null && fetchedPolicy !== sharedPolicy)
103
- contentSignal = fetchedPolicy;
104
- logger.debug(`[markdown.prerender] Fetched HTML for ${path} (${html.length} bytes)`);
105
- consumePrerenderedHtml(path);
106
- consumePrerenderedContentSignal(path);
107
- }
108
- if (html.includes("__NUXT_ERROR__") || html.includes("nuxt-error-page")) {
109
- return createError({
110
- statusCode: 404,
111
- message: `Page rendered as error: ${path}`
112
- });
113
- }
114
- const lastUpdated = extractLastUpdated(html);
115
- const result = await convertHtmlToMarkdown(
116
- html,
117
- canonicalUrl,
118
- runtimeConfig.mdreamOptions,
119
- {
120
- extractUpdatedAt: true,
121
- hooks: { route: path, event, isPrerender: true },
122
- additionalFrontmatter: {
123
- canonical_url: canonicalUrl,
124
- ...lastUpdated && { last_updated: lastUpdated }
125
- }
126
- }
127
- );
128
- const keywords = extractKeywords(result.textContent, result.metaKeywords);
129
- return JSON.stringify({
130
- markdown: result.markdown,
131
- title: result.title,
132
- description: result.description,
133
- headings: result.headings,
134
- keywords,
135
- ...contentSignal !== void 0 && { contentSignal },
136
- ...result.updatedAt && { updatedAt: result.updatedAt }
137
- });
32
+ if (event.path.startsWith("/.well-known/") || agentSkillArtifactPaths().has(event.path)) return;
33
+ // Only run during prerender
34
+ if (!import.meta.prerender) {
35
+ return;
36
+ }
37
+ const fullRuntimeConfig = useRuntimeConfig(event);
38
+ if (isSitemapMdRequest(event.path, fullRuntimeConfig.app.baseURL, fullRuntimeConfig["nuxt-ai-ready"]?.sitemapMd !== false)) return;
39
+ const renderInfo = getMarkdownRenderInfo(event, { _tag: "prerender" });
40
+ if (!renderInfo || "notAcceptable" in renderInfo) return;
41
+ const { path } = renderInfo;
42
+ let contentSignal = consumePrerenderedContentSignal(path);
43
+ const runtimeConfig = fullRuntimeConfig["nuxt-ai-ready"];
44
+ const deployedPath = toDeployedRoute(path, fullRuntimeConfig.app.baseURL);
45
+ const canonicalUrl = withSiteUrl(event, deployedPath, { withBase: true });
46
+ // Prefer @nuxt/content source: skip HTML fetch + mdream when the route is
47
+ // backed by a content collection. Body comes from the AST, so headings and
48
+ // keywords come from the markdown itself rather than the rendered HTML.
49
+ const contentPage = await tryGetContentMarkdown(event, path).catch((error) => {
50
+ logger.debug(`[markdown.prerender] Content lookup failed for ${path}`, error);
51
+ return null;
52
+ });
53
+ if (contentPage) {
54
+ logger.debug(`[markdown.prerender] Using content source for ${path} (${contentPage.markdown.length} bytes)`);
55
+ const frontmatter = buildFrontmatter({
56
+ title: contentPage.title,
57
+ description: contentPage.description,
58
+ canonical_url: canonicalUrl,
59
+ last_updated: contentPage.updatedAt
60
+ });
61
+ const markdown = `${frontmatter}\n${absoluteMarkdownLinks(contentPage.markdown, canonicalUrl)}`;
62
+ const headings = extractHeadingsFromMarkdown(contentPage.markdown);
63
+ const keywords = extractKeywords(contentPage.markdown, "");
64
+ return Response.json({
65
+ markdown,
66
+ title: contentPage.title || "",
67
+ description: contentPage.description || "",
68
+ headings,
69
+ keywords,
70
+ ...contentSignal !== undefined && { contentSignal },
71
+ // Only a real content date feeds the page index and sitemap lastmod.
72
+ ...contentPage.updatedAt && { updatedAt: contentPage.updatedAt }
73
+ });
74
+ }
75
+ // The page always renders before its .md twin (the .md route is queued via
76
+ // prerenderRoutes() during that render), so the html-capture plugin has the
77
+ // rendered HTML in memory. Reusing it avoids a full second SSR render per
78
+ // page and the prerender payload-cache rewrite that render triggers (see
79
+ // nuxt/nuxt#35590). Misses (e.g. sitemap-crawled pages that were never
80
+ // prerendered) fall back to event.fetch.
81
+ let html = consumePrerenderedHtml(path);
82
+ if (html) {
83
+ logger.debug(`[markdown.prerender] Reusing prerendered HTML for ${path} (${html.length} bytes)`);
84
+ } else {
85
+ logger.debug(`[markdown.prerender] Fetching HTML for ${path}`);
86
+ const response = await fetchRawWithEvent(event, deployedPath, { signal: AbortSignal.timeout(3e4) }).catch((err) => {
87
+ if (err?.name === "TimeoutError" || err?.name === "AbortError") {
88
+ throw createError({
89
+ statusCode: 504,
90
+ statusMessage: "Gateway Timeout",
91
+ message: `Timed out fetching HTML for ${path}`
92
+ });
93
+ }
94
+ throw err;
95
+ });
96
+ if (!response.ok) {
97
+ return createError({
98
+ statusCode: response.status,
99
+ statusMessage: response.statusText,
100
+ message: `Failed to fetch HTML for ${path}`
101
+ });
102
+ }
103
+ // Only an HTML page has a Markdown twin. A JSON, XML or text route such
104
+ // as an API catalog or a feed gets none, as at runtime.
105
+ if (!response.headers.get("content-type")?.includes("text/html")) {
106
+ return createError({
107
+ statusCode: 404,
108
+ message: `Not an HTML page: ${path}`
109
+ });
110
+ }
111
+ html = await response.text();
112
+ const fetchedPolicy = response.headers.get("content-signal");
113
+ const sharedPolicy = fullRuntimeConfig["nuxt-robots"]?.contentSignalHeader;
114
+ if (fetchedPolicy !== null && fetchedPolicy !== sharedPolicy) contentSignal = fetchedPolicy;
115
+ logger.debug(`[markdown.prerender] Fetched HTML for ${path} (${html.length} bytes)`);
116
+ // the fetch above re-rendered the page, which the capture plugin stored
117
+ // again; nothing will consume that copy, so drop it
118
+ consumePrerenderedHtml(path);
119
+ consumePrerenderedContentSignal(path);
120
+ }
121
+ // Skip error pages that returned 200 (e.g., Vue Router "no match" pages)
122
+ if (html.includes("__NUXT_ERROR__") || html.includes("nuxt-error-page")) {
123
+ return createError({
124
+ statusCode: 404,
125
+ message: `Page rendered as error: ${path}`
126
+ });
127
+ }
128
+ // A page with no date meta gets no `last_updated`. The build time would
129
+ // claim every page changed on every deploy.
130
+ const lastUpdated = extractLastUpdated(html);
131
+ const result = await convertHtmlToMarkdown(html, canonicalUrl, runtimeConfig.mdreamOptions, {
132
+ extractUpdatedAt: true,
133
+ hooks: {
134
+ route: path,
135
+ event,
136
+ isPrerender: true
137
+ },
138
+ additionalFrontmatter: {
139
+ canonical_url: canonicalUrl,
140
+ ...lastUpdated && { last_updated: lastUpdated }
141
+ }
142
+ });
143
+ // Extract keywords from content
144
+ const keywords = extractKeywords(result.textContent, result.metaKeywords);
145
+ return Response.json({
146
+ markdown: result.markdown,
147
+ title: result.title,
148
+ description: result.description,
149
+ headings: result.headings,
150
+ keywords,
151
+ ...contentSignal !== undefined && { contentSignal },
152
+ ...result.updatedAt && { updatedAt: result.updatedAt }
153
+ });
138
154
  });
@@ -1,2 +1,2 @@
1
1
  import type { H3Event } from '#nuxtseo/h3';
2
- export declare function renderMarkdown(event: H3Event, markdownPath: string): Promise<any>;
2
+ export declare function renderMarkdown(event: H3Event, markdownPath: string): Promise<string | Response | import("#nuxtseo/h3").HTTPError<unknown>>;