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,66 +1,78 @@
|
|
|
1
1
|
import { countPages, queryPages } from "../db/queries.js";
|
|
2
2
|
import { logger } from "../logger.js";
|
|
3
3
|
import { indexPageByRoute } from "./indexPage.js";
|
|
4
|
+
/** Concurrent fetches per batch (balances speed vs memory/subrequests) */
|
|
4
5
|
const CONCURRENCY = 5;
|
|
6
|
+
/**
|
|
7
|
+
* Batch index pending pages with parallel processing
|
|
8
|
+
* Processes pages in concurrent chunks for better throughput
|
|
9
|
+
*/
|
|
5
10
|
export async function batchIndexPages(event, options = {}) {
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
11
|
+
const startTime = Date.now();
|
|
12
|
+
const limit = Math.min(options.limit ?? 10, 50);
|
|
13
|
+
const timeout = options.timeout ?? 3e4;
|
|
14
|
+
const concurrency = options.concurrency ?? CONCURRENCY;
|
|
15
|
+
const beforeCount = await countPages(event, { where: { pending: true } });
|
|
16
|
+
if (beforeCount === 0) {
|
|
17
|
+
return {
|
|
18
|
+
indexed: 0,
|
|
19
|
+
remaining: 0,
|
|
20
|
+
errors: [],
|
|
21
|
+
duration: Date.now() - startTime,
|
|
22
|
+
complete: true
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
let indexed = 0;
|
|
26
|
+
const errors = [];
|
|
27
|
+
let processed = 0;
|
|
28
|
+
while (processed < limit) {
|
|
29
|
+
// Check timeout for 'all' mode
|
|
30
|
+
if (options.all && Date.now() - startTime >= timeout) {
|
|
31
|
+
logger.debug(`[batchIndex] Timeout reached after ${Date.now() - startTime}ms`);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
// Fetch next chunk of pending pages
|
|
35
|
+
const chunkSize = Math.min(concurrency, limit - processed);
|
|
36
|
+
const pages = await queryPages(event, {
|
|
37
|
+
where: { pending: true },
|
|
38
|
+
limit: chunkSize
|
|
39
|
+
});
|
|
40
|
+
if (pages.length === 0) break;
|
|
41
|
+
// Process chunk in parallel
|
|
42
|
+
logger.debug(`[batchIndex] Processing ${pages.length} pages concurrently`);
|
|
43
|
+
const results = await Promise.all(pages.map(async (page) => {
|
|
44
|
+
const result = await indexPageByRoute(page.route, event, {
|
|
45
|
+
markFailedAsError: true,
|
|
46
|
+
force: true
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
route: page.route,
|
|
50
|
+
result
|
|
51
|
+
};
|
|
52
|
+
}));
|
|
53
|
+
// Tally results
|
|
54
|
+
for (const result of results) {
|
|
55
|
+
processed++;
|
|
56
|
+
if (result.result.gone) {
|
|
57
|
+
logger.debug(`[batchIndex] Pruned gone route: ${result.route}`);
|
|
58
|
+
} else if (result.result.success) {
|
|
59
|
+
indexed++;
|
|
60
|
+
logger.debug(`[batchIndex] Indexed: ${result.route}`);
|
|
61
|
+
} else {
|
|
62
|
+
errors.push(result.route);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Exit if we got fewer pages than requested (no more pending)
|
|
66
|
+
if (pages.length < chunkSize) break;
|
|
67
|
+
// For non-all mode, respect the limit
|
|
68
|
+
if (!options.all && processed >= limit) break;
|
|
69
|
+
}
|
|
70
|
+
const remaining = await countPages(event, { where: { pending: true } });
|
|
71
|
+
return {
|
|
72
|
+
indexed,
|
|
73
|
+
remaining,
|
|
74
|
+
errors,
|
|
75
|
+
duration: Date.now() - startTime,
|
|
76
|
+
complete: remaining === 0
|
|
77
|
+
};
|
|
66
78
|
}
|
|
@@ -1,157 +1,204 @@
|
|
|
1
1
|
import { useRuntimeConfig } from "#nuxtseo/nitro";
|
|
2
|
-
import {
|
|
3
|
-
countPages,
|
|
4
|
-
getContentHashes,
|
|
5
|
-
getInfoValue,
|
|
6
|
-
markRoutesPending,
|
|
7
|
-
resetSitemapErrors,
|
|
8
|
-
setInfoValue
|
|
9
|
-
} from "../db/index.js";
|
|
2
|
+
import { countPages, getContentHashes, getInfoValue, markRoutesPending, resetSitemapErrors, setInfoValue } from "../db/index.js";
|
|
10
3
|
import { decompressFromBase64, importDbDump } from "../db/shared.js";
|
|
11
4
|
import { logger } from "../logger.js";
|
|
12
5
|
import { fetchPublicAsset } from "./cloudflare.js";
|
|
6
|
+
// A host can answer the metadata path with something else, such as a base URL
|
|
7
|
+
// redirect page. Only a real build ID counts as a dump.
|
|
13
8
|
function parseBuildMeta(value) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
if (!value || typeof value !== "object") return null;
|
|
10
|
+
const { buildId, pageCount, createdAt } = value;
|
|
11
|
+
if (typeof buildId !== "string" || !buildId || typeof pageCount !== "number") return null;
|
|
12
|
+
return {
|
|
13
|
+
buildId,
|
|
14
|
+
pageCount,
|
|
15
|
+
createdAt: typeof createdAt === "string" ? createdAt : ""
|
|
16
|
+
};
|
|
20
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Fetch build metadata from static assets
|
|
20
|
+
*/
|
|
21
21
|
async function fetchBuildMeta(event) {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
logger.debug("[stale-check] Fetching meta...");
|
|
23
|
+
return parseBuildMeta(await fetchPublicAsset(event, "/__ai-ready/pages.meta.json"));
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Fetch and decompress dump data
|
|
27
|
+
*/
|
|
25
28
|
async function fetchDump(event) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
logger.debug("[stale-check] Fetching dump...");
|
|
30
|
+
const dumpData = await fetchPublicAsset(event, "/__ai-ready/pages.dump", { responseType: "text" });
|
|
31
|
+
if (!dumpData) {
|
|
32
|
+
logger.debug("[stale-check] Failed to fetch dump");
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
logger.debug(`[stale-check] Decompressing dump (${(dumpData.length / 1024).toFixed(1)}kb)...`);
|
|
36
|
+
return decompressFromBase64(dumpData).catch((error) => {
|
|
37
|
+
logger.warn("[stale-check] Build dump is unreadable, skipping restore:", error);
|
|
38
|
+
return null;
|
|
39
|
+
});
|
|
37
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Get stored build ID from database
|
|
43
|
+
*/
|
|
38
44
|
async function getStoredBuildId(event) {
|
|
39
|
-
|
|
45
|
+
return getInfoValue(event, "build_id");
|
|
40
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Set stored build ID in database
|
|
49
|
+
*/
|
|
41
50
|
async function setStoredBuildId(event, buildId) {
|
|
42
|
-
|
|
51
|
+
await setInfoValue(event, "build_id", buildId);
|
|
43
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Get last stale check timestamp from database
|
|
55
|
+
*/
|
|
44
56
|
async function getLastStaleCheck(event) {
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
const value = await getInfoValue(event, "last_stale_check");
|
|
58
|
+
return value ? Number.parseInt(value, 10) : null;
|
|
47
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Set last stale check timestamp in database
|
|
62
|
+
*/
|
|
48
63
|
async function setLastStaleCheck(event) {
|
|
49
|
-
|
|
64
|
+
await setInfoValue(event, "last_stale_check", Date.now().toString());
|
|
50
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Insert new pages from dump (as already indexed since dump has full content)
|
|
68
|
+
*/
|
|
51
69
|
async function insertFromDump(event, rows) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
await importDbDump(db, rows);
|
|
70
|
+
if (rows.length === 0) return;
|
|
71
|
+
const { useRawDb } = await import("../db/index.js");
|
|
72
|
+
const db = await useRawDb(event);
|
|
73
|
+
await importDbDump(db, rows);
|
|
57
74
|
}
|
|
58
75
|
export const STALE_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
76
|
+
/**
|
|
77
|
+
* Check if data is stale and handle restore/mark-pending
|
|
78
|
+
* Called at start of cron - handles:
|
|
79
|
+
* 1. Empty DB with a different build ID → restore from dump
|
|
80
|
+
* 2. Build ID changed → compare hashes, only mark changed pages pending, add new pages from dump
|
|
81
|
+
* Skips HTTP fetch if checked within 5 minutes and DB is populated
|
|
82
|
+
*/
|
|
59
83
|
export async function checkAndHandleStale(event) {
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
84
|
+
const config = useRuntimeConfig()["nuxt-ai-ready"];
|
|
85
|
+
const debug = config.debug;
|
|
86
|
+
const dbCount = await countPages(event);
|
|
87
|
+
const storedBuildId = await getStoredBuildId(event);
|
|
88
|
+
// Fast path: skip HTTP fetch if recently checked and DB has data
|
|
89
|
+
if (dbCount > 0 && storedBuildId) {
|
|
90
|
+
const lastCheck = await getLastStaleCheck(event);
|
|
91
|
+
if (lastCheck && Date.now() - lastCheck < STALE_CHECK_INTERVAL_MS) {
|
|
92
|
+
if (debug) logger.info(`[stale-check] Skipping - checked ${Math.round((Date.now() - lastCheck) / 1e3)}s ago`);
|
|
93
|
+
return {
|
|
94
|
+
action: "none",
|
|
95
|
+
dbCount,
|
|
96
|
+
buildId: storedBuildId,
|
|
97
|
+
reason: "recently_checked"
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const meta = await fetchBuildMeta(event);
|
|
102
|
+
if (debug) {
|
|
103
|
+
logger.info(`[stale-check] DB count: ${dbCount}, stored buildId: ${storedBuildId || "none"}, dump buildId: ${meta?.buildId || "none"}`);
|
|
104
|
+
}
|
|
105
|
+
// No dump available - nothing to do
|
|
106
|
+
if (!meta) {
|
|
107
|
+
if (debug) logger.info("[stale-check] No build metadata found, skipping stale check");
|
|
108
|
+
return {
|
|
109
|
+
action: "none",
|
|
110
|
+
dbCount,
|
|
111
|
+
reason: "no_dump_metadata"
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// An empty database can reflect HTTP 410 cleanup within the current build.
|
|
115
|
+
if (dbCount === 0 && storedBuildId !== meta.buildId) {
|
|
116
|
+
if (debug) logger.info("[stale-check] DB empty, restoring from dump...");
|
|
117
|
+
const rows = await fetchDump(event);
|
|
118
|
+
if (!rows) {
|
|
119
|
+
logger.warn("[stale-check] Failed to fetch dump for restore");
|
|
120
|
+
return {
|
|
121
|
+
action: "none",
|
|
122
|
+
dbCount: 0,
|
|
123
|
+
dumpCount: meta.pageCount,
|
|
124
|
+
reason: "dump_fetch_failed"
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const { useRawDb } = await import("../db/index.js");
|
|
128
|
+
const db = await useRawDb(event);
|
|
129
|
+
await importDbDump(db, rows);
|
|
130
|
+
await setStoredBuildId(event, meta.buildId);
|
|
131
|
+
await setLastStaleCheck(event);
|
|
132
|
+
logger.info(`[stale-check] Restored ${rows.length} pages from dump (buildId: ${meta.buildId})`);
|
|
133
|
+
return {
|
|
134
|
+
action: "restored",
|
|
135
|
+
buildId: meta.buildId,
|
|
136
|
+
dbCount: rows.length,
|
|
137
|
+
dumpCount: meta.pageCount
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
// Case 2: Build ID changed - compare hashes and only mark changed pages pending
|
|
141
|
+
if (storedBuildId !== meta.buildId) {
|
|
142
|
+
if (debug) logger.info(`[stale-check] Build ID changed (${storedBuildId} → ${meta.buildId}), comparing hashes...`);
|
|
143
|
+
// Reset sitemap errors on new build (deployment might fix the issue)
|
|
144
|
+
const sitemapsReset = await resetSitemapErrors(event);
|
|
145
|
+
if (sitemapsReset > 0 && debug) logger.info(`[stale-check] Reset ${sitemapsReset} sitemap error(s)`);
|
|
146
|
+
const dumpRows = await fetchDump(event);
|
|
147
|
+
if (!dumpRows) {
|
|
148
|
+
logger.warn("[stale-check] Failed to fetch dump for hash comparison");
|
|
149
|
+
return {
|
|
150
|
+
action: "none",
|
|
151
|
+
dbCount,
|
|
152
|
+
dumpCount: meta.pageCount,
|
|
153
|
+
reason: "dump_fetch_failed"
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
// Get current DB hashes
|
|
157
|
+
const dbHashes = await getContentHashes(event);
|
|
158
|
+
// Find changed and new pages
|
|
159
|
+
const changedRoutes = [];
|
|
160
|
+
const newRows = [];
|
|
161
|
+
for (const row of dumpRows) {
|
|
162
|
+
const dbHash = dbHashes.get(row.route);
|
|
163
|
+
if (dbHash === undefined) {
|
|
164
|
+
// New page not in DB
|
|
165
|
+
newRows.push(row);
|
|
166
|
+
} else if (dbHash !== row.content_hash) {
|
|
167
|
+
// Hash changed - mark pending for re-index
|
|
168
|
+
changedRoutes.push(row.route);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Insert new pages from dump (already has full content)
|
|
172
|
+
if (newRows.length > 0) {
|
|
173
|
+
await insertFromDump(event, newRows);
|
|
174
|
+
if (debug) logger.info(`[stale-check] Added ${newRows.length} new pages from dump`);
|
|
175
|
+
}
|
|
176
|
+
// Mark changed pages as pending
|
|
177
|
+
if (changedRoutes.length > 0) {
|
|
178
|
+
await markRoutesPending(event, changedRoutes);
|
|
179
|
+
if (debug) logger.info(`[stale-check] Marked ${changedRoutes.length} pages pending (hash changed)`);
|
|
180
|
+
}
|
|
181
|
+
await setStoredBuildId(event, meta.buildId);
|
|
182
|
+
await setLastStaleCheck(event);
|
|
183
|
+
const unchangedCount = dumpRows.length - newRows.length - changedRoutes.length;
|
|
184
|
+
logger.info(`[stale-check] Build ID changed: ${changedRoutes.length} changed, ${newRows.length} new, ${unchangedCount} unchanged (buildId: ${meta.buildId})`);
|
|
185
|
+
return {
|
|
186
|
+
action: changedRoutes.length > 0 || newRows.length > 0 ? "marked_pending" : "none",
|
|
187
|
+
buildId: meta.buildId,
|
|
188
|
+
dbCount: dbCount + newRows.length,
|
|
189
|
+
dumpCount: meta.pageCount,
|
|
190
|
+
changedCount: changedRoutes.length,
|
|
191
|
+
addedCount: newRows.length,
|
|
192
|
+
sitemapsReset
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
// Case 3: Same build ID - no action needed
|
|
196
|
+
await setLastStaleCheck(event);
|
|
197
|
+
if (debug) logger.info("[stale-check] Build ID unchanged, no action needed");
|
|
198
|
+
return {
|
|
199
|
+
action: "none",
|
|
200
|
+
buildId: meta.buildId,
|
|
201
|
+
dbCount,
|
|
202
|
+
dumpCount: meta.pageCount
|
|
203
|
+
};
|
|
157
204
|
}
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import cloudflareFallbackPaths from "#ai-ready-virtual/cloudflare-fallback-paths.mjs";
|
|
2
2
|
import { getRequestHeaders, getRequestURL, getResponseHeaders } from "#nuxtseo/h3";
|
|
3
3
|
import { mergeVaryHeader } from "../../cache-control.js";
|
|
4
|
+
/** Serve the original static HTML after negotiation, without rendering it again. */
|
|
4
5
|
export function serveCloudflarePrerenderedPage(event) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
if (!cloudflareFallbackPaths.size) return;
|
|
7
|
+
if (event.method !== "GET" && event.method !== "HEAD") return;
|
|
8
|
+
const assets = event.context.cloudflare?.env?.ASSETS;
|
|
9
|
+
if (!assets) return;
|
|
10
|
+
const url = getRequestURL(event);
|
|
11
|
+
if (!cloudflareFallbackPaths.has(url.pathname)) return;
|
|
12
|
+
return assets.fetch(new Request(url, {
|
|
13
|
+
method: event.method,
|
|
14
|
+
headers: getRequestHeaders(event)
|
|
15
|
+
})).then((response) => {
|
|
16
|
+
const headers = new Headers(response.headers);
|
|
17
|
+
for (const [name, value] of Object.entries(getResponseHeaders(event))) {
|
|
18
|
+
if (value === undefined) continue;
|
|
19
|
+
const header = Array.isArray(value) ? value.join(", ") : String(value);
|
|
20
|
+
headers.set(name, name.toLowerCase() === "vary" ? mergeVaryHeader(headers.get(name) ?? undefined, header) : header);
|
|
21
|
+
}
|
|
22
|
+
return new Response(response.body, {
|
|
23
|
+
status: response.status,
|
|
24
|
+
statusText: response.statusText,
|
|
25
|
+
headers
|
|
26
|
+
});
|
|
27
|
+
});
|
|
25
28
|
}
|