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,37 +1,36 @@
|
|
|
1
1
|
import { useEvent } from "#nuxtseo/nitro";
|
|
2
2
|
import { countPages, queryPages } from "../../db/queries.js";
|
|
3
3
|
export default {
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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:
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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:
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
${absoluteMarkdownLinks(contentPage.markdown, canonicalUrl)}`;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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<
|
|
2
|
+
export declare function renderMarkdown(event: H3Event, markdownPath: string): Promise<string | Response | import("#nuxtseo/h3").HTTPError<unknown>>;
|