nuxt-ai-ready 3.6.1 → 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 +18 -22
- 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
|
@@ -6,203 +6,274 @@ import { checkAndHandleStale, STALE_CHECK_INTERVAL_MS } from "./checkStale.js";
|
|
|
6
6
|
import { resolveCronPlan, resolveSitemapIntervalMinutes } from "./cron-plan.js";
|
|
7
7
|
import { crawlSitemapByRoute, getSitemapsFromConfig } from "./sitemap.js";
|
|
8
8
|
import { mapSitemapRoutes } from "./sitemap-routes.js";
|
|
9
|
+
/** The message from an unknown throw, without assuming it is an `Error`. */
|
|
9
10
|
function describeFailure(error) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return String(error);
|
|
11
|
+
if (error instanceof Error) return error.message;
|
|
12
|
+
return String(error);
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Run cron job logic - shared between scheduled task and HTTP endpoint
|
|
16
|
+
*
|
|
17
|
+
* This is the error boundary for the whole run. Nothing throws past it: the
|
|
18
|
+
* scheduled task has no request context and no handler above it, so a throw
|
|
19
|
+
* here becomes an opaque platform exception rather than something the host can
|
|
20
|
+
* report. Every failure comes back as `CronResult.failed`.
|
|
21
|
+
*/
|
|
14
22
|
export async function runCron(event, options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
// Skip in dev - DB and context not available
|
|
24
|
+
if (import.meta.dev) return {};
|
|
25
|
+
return executeCron(event, options).catch((error) => {
|
|
26
|
+
const message = describeFailure(error);
|
|
27
|
+
logger.error(`[cron] Run failed: ${message}`);
|
|
28
|
+
return { failed: {
|
|
29
|
+
stage: "run",
|
|
30
|
+
message
|
|
31
|
+
} };
|
|
32
|
+
});
|
|
22
33
|
}
|
|
23
34
|
async function executeCron(event, options) {
|
|
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
|
-
|
|
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
|
-
|
|
35
|
+
const config = useRuntimeConfig()["nuxt-ai-ready"];
|
|
36
|
+
const debug = config.debug;
|
|
37
|
+
const startTime = Date.now();
|
|
38
|
+
const results = {};
|
|
39
|
+
const allErrors = [];
|
|
40
|
+
const sitemapIntervalMinutes = resolveSitemapIntervalMinutes(config.runtimeSync.ttl);
|
|
41
|
+
// Prevent overlapping cron runs.
|
|
42
|
+
// This is the first database call of the run and it used to sit outside the
|
|
43
|
+
// try below, so a database blip here threw straight out of the task.
|
|
44
|
+
const lock = await tryAcquireCronLock(event).catch((error) => {
|
|
45
|
+
logger.error(`[cron] Could not acquire the lock: ${describeFailure(error)}`);
|
|
46
|
+
return null;
|
|
47
|
+
});
|
|
48
|
+
if (lock === null) {
|
|
49
|
+
return { failed: {
|
|
50
|
+
stage: "lock",
|
|
51
|
+
message: "Could not acquire the cron lock"
|
|
52
|
+
} };
|
|
53
|
+
}
|
|
54
|
+
if (lock._tag === "held") {
|
|
55
|
+
if (debug) {
|
|
56
|
+
logger.info(`[cron] Skipping - another cron run is in progress`);
|
|
57
|
+
}
|
|
58
|
+
return { stale: {
|
|
59
|
+
action: "none",
|
|
60
|
+
dbCount: 0,
|
|
61
|
+
reason: "lock_held"
|
|
62
|
+
} };
|
|
63
|
+
}
|
|
64
|
+
if (debug) {
|
|
65
|
+
logger.info(`[cron] Starting cron run (batchSize: ${options?.batchSize ?? config.runtimeSync.batchSize})`);
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
// Fast path: single query to check if any work is needed
|
|
69
|
+
if (config.runtimeSync.enabled) {
|
|
70
|
+
const status = await getCronFastPathStatus(event, sitemapIntervalMinutes);
|
|
71
|
+
if (status) {
|
|
72
|
+
const now = Date.now();
|
|
73
|
+
const staleCheckNeeded = !status.lastStaleCheck || now - status.lastStaleCheck >= STALE_CHECK_INTERVAL_MS;
|
|
74
|
+
const plan = resolveCronPlan({
|
|
75
|
+
status,
|
|
76
|
+
runtimeSyncTtlSeconds: config.runtimeSync.ttl,
|
|
77
|
+
staleCheckNeeded
|
|
78
|
+
});
|
|
79
|
+
if (!plan.hasWork) {
|
|
80
|
+
if (debug) {
|
|
81
|
+
const duration = Date.now() - startTime;
|
|
82
|
+
logger.info(`[cron] Fast path: no work needed (${duration}ms)`);
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
stale: {
|
|
86
|
+
action: "none",
|
|
87
|
+
dbCount: status.totalPages,
|
|
88
|
+
reason: "fast_path_no_work"
|
|
89
|
+
},
|
|
90
|
+
index: {
|
|
91
|
+
indexed: 0,
|
|
92
|
+
remaining: 0,
|
|
93
|
+
complete: true
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (debug) {
|
|
98
|
+
logger.info(`[cron] Work needed: stale=${staleCheckNeeded}, pending=${status.pendingPages}, sitemaps=${status.sitemapsNeedCrawl}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Check for stale data and handle restore/mark-pending
|
|
103
|
+
// This runs before indexing to ensure data is ready
|
|
104
|
+
if (config.runtimeSync.enabled) {
|
|
105
|
+
results.stale = await checkAndHandleStale(event).catch((err) => {
|
|
106
|
+
logger.warn("[ai-ready:cron] Stale check failed:", err.message);
|
|
107
|
+
allErrors.push(`stale-check: ${err.message}`);
|
|
108
|
+
return {
|
|
109
|
+
action: "none",
|
|
110
|
+
dbCount: 0,
|
|
111
|
+
reason: err.message
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
if (debug && results.stale) {
|
|
115
|
+
logger.info(`[cron] Stale check: ${results.stale.action} (db: ${results.stale.dbCount}, dump: ${results.stale.dumpCount ?? "n/a"})`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Ping next sitemap to trigger seeding via sitemap:resolved hook
|
|
119
|
+
// The sitemap-seeder plugin handles actual route insertion
|
|
120
|
+
if (config.runtimeSync.enabled) {
|
|
121
|
+
const sitemapResult = await pingSitemap(event, config, sitemapIntervalMinutes, debug).catch((err) => {
|
|
122
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
123
|
+
logger.warn("[ai-ready:cron] Sitemap ping failed:", msg);
|
|
124
|
+
allErrors.push(`sitemap: ${msg}`);
|
|
125
|
+
return {
|
|
126
|
+
pinged: false,
|
|
127
|
+
pruned: 0,
|
|
128
|
+
error: msg
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
results.sitemap = sitemapResult;
|
|
132
|
+
if (debug) {
|
|
133
|
+
if (sitemapResult.name) {
|
|
134
|
+
logger.info(`[cron] Sitemap: pinged ${sitemapResult.name}${sitemapResult.continuing ? " (continuing)" : sitemapResult.error ? ` (error: ${sitemapResult.error})` : ""}`);
|
|
135
|
+
}
|
|
136
|
+
if (sitemapResult.pruned > 0) {
|
|
137
|
+
logger.info(`[cron] Sitemap: pruned ${sitemapResult.pruned} stale routes`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Start logging this cron run (only if debugCron enabled)
|
|
142
|
+
const runId = config.debugCron ? await startCronRun(event) : null;
|
|
143
|
+
results.runId = runId;
|
|
144
|
+
// Run runtime indexing if enabled
|
|
145
|
+
if (config.runtimeSync.enabled) {
|
|
146
|
+
const limit = options?.batchSize ?? config.runtimeSync.batchSize;
|
|
147
|
+
const indexResult = await batchIndexPages(event, {
|
|
148
|
+
limit,
|
|
149
|
+
all: false
|
|
150
|
+
});
|
|
151
|
+
results.index = {
|
|
152
|
+
indexed: indexResult.indexed,
|
|
153
|
+
remaining: indexResult.remaining,
|
|
154
|
+
errors: indexResult.errors.length > 0 ? indexResult.errors : undefined,
|
|
155
|
+
complete: indexResult.complete
|
|
156
|
+
};
|
|
157
|
+
if (indexResult.errors.length > 0) {
|
|
158
|
+
allErrors.push(...indexResult.errors);
|
|
159
|
+
}
|
|
160
|
+
if (debug) {
|
|
161
|
+
logger.info(`[cron] Index: ${indexResult.indexed} pages (${indexResult.remaining} remaining${indexResult.errors.length > 0 ? `, ${indexResult.errors.length} errors` : ""})`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Complete the cron run log (only if debugCron enabled)
|
|
165
|
+
if (runId && config.debugCron) {
|
|
166
|
+
await completeCronRun(event, runId, {
|
|
167
|
+
pagesIndexed: results.index?.indexed || 0,
|
|
168
|
+
pagesRemaining: results.index?.remaining || 0,
|
|
169
|
+
errors: allErrors
|
|
170
|
+
});
|
|
171
|
+
// Prune cron logs older than 24 hours
|
|
172
|
+
await pruneCronRunsByAge(event);
|
|
173
|
+
}
|
|
174
|
+
// Summary log
|
|
175
|
+
if (debug) {
|
|
176
|
+
const duration = Date.now() - startTime;
|
|
177
|
+
const parts = [];
|
|
178
|
+
if (results.stale?.action !== "none") parts.push(results.stale?.action);
|
|
179
|
+
if (results.sitemap?.name) parts.push(`pinged ${results.sitemap.name}`);
|
|
180
|
+
if (results.index?.indexed) parts.push(`${results.index.indexed} indexed`);
|
|
181
|
+
if (allErrors.length > 0) parts.push(`${allErrors.length} errors`);
|
|
182
|
+
logger.info(`[cron] Complete in ${duration}ms${parts.length > 0 ? `: ${parts.join(", ")}` : ""}`);
|
|
183
|
+
}
|
|
184
|
+
return results;
|
|
185
|
+
} finally {
|
|
186
|
+
// Always release the lock; a throw between acquire and release would
|
|
187
|
+
// otherwise strand it for CRON_LOCK_TTL_MS, blocking subsequent runs.
|
|
188
|
+
// The token check inside release keeps a run that outlived the TTL from
|
|
189
|
+
// deleting a newer owner's lock.
|
|
190
|
+
await releaseCronLock(event, lock.token).catch((err) => {
|
|
191
|
+
logger.warn(`[cron] Failed to release lock: ${err?.message || err}`);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
146
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Ping next sitemap to trigger rendering and seeding
|
|
197
|
+
* The sitemap-seeder plugin hooks into sitemap:resolved to seed routes
|
|
198
|
+
*/
|
|
147
199
|
async function pingSitemap(event, config, sitemapIntervalMinutes, debug) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
200
|
+
const { pruneTtl } = config.runtimeSync;
|
|
201
|
+
// Seeding and pruning must agree on how far last_seen_at may lag.
|
|
202
|
+
const refreshWindowMs = resolveSeedRefreshWindowMs(pruneTtl);
|
|
203
|
+
// Sync sitemap list from runtime config to DB
|
|
204
|
+
const sitemaps = getSitemapsFromConfig(event);
|
|
205
|
+
if (sitemaps.length === 0) {
|
|
206
|
+
// Fallback: single sitemap mode
|
|
207
|
+
sitemaps.push({
|
|
208
|
+
name: "sitemap.xml",
|
|
209
|
+
route: "/sitemap.xml"
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
await syncSitemaps(event, sitemaps);
|
|
213
|
+
// Get next sitemap to ping (round-robin, prioritizes errors for retry)
|
|
214
|
+
const nextSitemap = await getNextSitemapToCrawl(event, sitemapIntervalMinutes);
|
|
215
|
+
if (!nextSitemap) {
|
|
216
|
+
if (debug) logger.info("[cron] No sitemaps to ping");
|
|
217
|
+
// Still do pruning even if no sitemap to ping
|
|
218
|
+
let pruned = 0;
|
|
219
|
+
if (pruneTtl > 0) {
|
|
220
|
+
pruned = await pruneStaleRoutes(event, pruneTtl, undefined, refreshWindowMs);
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
pinged: false,
|
|
224
|
+
pruned
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
if (debug) logger.info(`[cron] Pinging sitemap: ${nextSitemap.name} (${nextSitemap.route})`);
|
|
228
|
+
// Fetch one bounded round. ASSETS.fetch avoids self-fetch hangs on Cloudflare.
|
|
229
|
+
if (debug) logger.info(`[cron] Starting sitemap fetch: ${nextSitemap.route}`);
|
|
230
|
+
const result = await crawlSitemapByRoute(event, {
|
|
231
|
+
route: nextSitemap.route,
|
|
232
|
+
state: nextSitemap.crawlState
|
|
233
|
+
});
|
|
234
|
+
// Thread each entry's URL so seeded locales derive from the page's own host
|
|
235
|
+
// on multi-domain i18n sites, never from the cron request host.
|
|
236
|
+
const routes = [...mapSitemapRoutes(result.urls).entries()].map(([route, url]) => ({
|
|
237
|
+
route,
|
|
238
|
+
url: url.loc,
|
|
239
|
+
lastmod: url.lastmod
|
|
240
|
+
}));
|
|
241
|
+
if (routes.length > 0) await seedRoutes(event, routes, { refreshWindowMs });
|
|
242
|
+
if (result._tag === "failed") {
|
|
243
|
+
await markSitemapError(event, nextSitemap.name, result.error);
|
|
244
|
+
return {
|
|
245
|
+
name: nextSitemap.name,
|
|
246
|
+
pinged: false,
|
|
247
|
+
pruned: 0,
|
|
248
|
+
error: result.error
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
if (result._tag === "partial") {
|
|
252
|
+
await markSitemapCrawlPartial(event, nextSitemap.name, result.state);
|
|
253
|
+
if (debug) logger.info(`[cron] Sitemap round complete (${result.urls.length} URLs, ${result.state.frontier.length} frontier entries)`);
|
|
254
|
+
return {
|
|
255
|
+
name: nextSitemap.name,
|
|
256
|
+
pinged: true,
|
|
257
|
+
continuing: true,
|
|
258
|
+
pruned: 0
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
if (debug) logger.info(`[cron] Sitemap fetch complete (${result.urls.length} URLs)`);
|
|
262
|
+
// Success: mark as crawled with the total count across continuation rounds.
|
|
263
|
+
// Note: sitemap-seeder plugin may also call this via hook, but we call
|
|
264
|
+
// again in case the hook didn't fire (e.g., ASSETS.fetch bypasses hooks)
|
|
265
|
+
await markSitemapCrawled(event, nextSitemap.name, result.urlsObserved);
|
|
266
|
+
// Prune stale routes if configured, but only after a clean crawl. A failed or
|
|
267
|
+
// partial crawl (e.g. a child sitemap 404'd) means some routes' last_seen_at
|
|
268
|
+
// wasn't refreshed; pruning on that incomplete evidence could delete live
|
|
269
|
+
// routes whose sitemap simply failed to load this run.
|
|
270
|
+
let pruned = 0;
|
|
271
|
+
if (pruneTtl > 0) {
|
|
272
|
+
pruned = await pruneStaleRoutes(event, pruneTtl, result.startedAt, refreshWindowMs);
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
name: nextSitemap.name,
|
|
276
|
+
pinged: true,
|
|
277
|
+
pruned
|
|
278
|
+
};
|
|
208
279
|
}
|
|
@@ -1,51 +1,69 @@
|
|
|
1
1
|
function isNonNegativeInteger(value) {
|
|
2
|
-
|
|
2
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0;
|
|
3
3
|
}
|
|
4
4
|
function isWalkEntry(value) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (entry.source === "root")
|
|
11
|
-
return entry.depth === 0 && entry.parentUrl === void 0;
|
|
12
|
-
return entry.source === "index_child" && entry.depth > 0 && typeof entry.parentUrl === "string" && entry.parentUrl.length > 0;
|
|
5
|
+
if (!value || typeof value !== "object") return false;
|
|
6
|
+
const entry = value;
|
|
7
|
+
if (typeof entry.url !== "string" || entry.url.length === 0 || !isNonNegativeInteger(entry.depth)) return false;
|
|
8
|
+
if (entry.source === "root") return entry.depth === 0 && entry.parentUrl === undefined;
|
|
9
|
+
return entry.source === "index_child" && entry.depth > 0 && typeof entry.parentUrl === "string" && entry.parentUrl.length > 0;
|
|
13
10
|
}
|
|
14
11
|
function isStringArray(value) {
|
|
15
|
-
|
|
12
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string" && item.length > 0);
|
|
16
13
|
}
|
|
17
14
|
function parseState(value) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
15
|
+
if (!value || typeof value !== "object") return {
|
|
16
|
+
_tag: "error",
|
|
17
|
+
error: "Sitemap crawl state must be an object"
|
|
18
|
+
};
|
|
19
|
+
const state = value;
|
|
20
|
+
if (state._tag !== "continuation") return {
|
|
21
|
+
_tag: "error",
|
|
22
|
+
error: "Sitemap crawl state has an invalid tag"
|
|
23
|
+
};
|
|
24
|
+
if (!Array.isArray(state.frontier) || state.frontier.length === 0 || !state.frontier.every(isWalkEntry)) return {
|
|
25
|
+
_tag: "error",
|
|
26
|
+
error: "Sitemap crawl state has an invalid frontier"
|
|
27
|
+
};
|
|
28
|
+
if (!isStringArray(state.seenDocuments)) return {
|
|
29
|
+
_tag: "error",
|
|
30
|
+
error: "Sitemap crawl state has invalid seen documents"
|
|
31
|
+
};
|
|
32
|
+
if (!isNonNegativeInteger(state.documentsAttempted)) return {
|
|
33
|
+
_tag: "error",
|
|
34
|
+
error: "Sitemap crawl state has an invalid document count"
|
|
35
|
+
};
|
|
36
|
+
if (!isNonNegativeInteger(state.urlsObserved)) return {
|
|
37
|
+
_tag: "error",
|
|
38
|
+
error: "Sitemap crawl state has an invalid URL count"
|
|
39
|
+
};
|
|
40
|
+
if (!isNonNegativeInteger(state.rounds) || state.rounds === 0) return {
|
|
41
|
+
_tag: "error",
|
|
42
|
+
error: "Sitemap crawl state has an invalid round count"
|
|
43
|
+
};
|
|
44
|
+
if (!isNonNegativeInteger(state.startedAt)) return {
|
|
45
|
+
_tag: "error",
|
|
46
|
+
error: "Sitemap crawl state has an invalid start timestamp"
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
_tag: "ok",
|
|
50
|
+
state
|
|
51
|
+
};
|
|
36
52
|
}
|
|
37
53
|
export function parseSitemapCrawlState(value) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
if (value === null) return {
|
|
55
|
+
_tag: "ok",
|
|
56
|
+
state: null
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
return parseState(JSON.parse(value));
|
|
60
|
+
} catch (error) {
|
|
61
|
+
return {
|
|
62
|
+
_tag: "error",
|
|
63
|
+
error: error instanceof Error ? error.message : String(error)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
48
66
|
}
|
|
49
67
|
export function serializeSitemapCrawlState(state) {
|
|
50
|
-
|
|
68
|
+
return JSON.stringify(state);
|
|
51
69
|
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
const INDEXED_LASTMOD_MARKER = "<!-- nuxt-ai-ready:indexed-lastmod -->";
|
|
2
|
+
/** Mark dates added by this module without changing the public sitemap date. */
|
|
2
3
|
export function markIndexedSitemapLastmods(xml, enrichedUrls) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const escapedUrls = new Set([...enrichedUrls].map((url) => url.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'")));
|
|
5
|
+
return xml.replace(/<url>([\s\S]*?)<\/url>/g, (entry, body) => {
|
|
6
|
+
const loc = body.match(/<loc>([^<]*)<\/loc>/)?.[1];
|
|
7
|
+
return loc && escapedUrls.has(loc) ? entry.replace("<lastmod>", `${INDEXED_LASTMOD_MARKER}<lastmod>`) : entry;
|
|
8
|
+
});
|
|
8
9
|
}
|
|
10
|
+
/** The source crawl must never treat our indexed date as a CMS change. */
|
|
9
11
|
export function stripIndexedSitemapLastmods(body) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
let xml;
|
|
13
|
+
try {
|
|
14
|
+
xml = new TextDecoder("utf-8", { fatal: true }).decode(body);
|
|
15
|
+
} catch {
|
|
16
|
+
// Preserve invalid UTF-8 and compressed bytes for sitemapd to decode and report.
|
|
17
|
+
return body;
|
|
18
|
+
}
|
|
19
|
+
if (!xml.includes(INDEXED_LASTMOD_MARKER)) return body;
|
|
20
|
+
return new TextEncoder().encode(xml.replace(/<!-- nuxt-ai-ready:indexed-lastmod -->\s*<lastmod>[^<]*<\/lastmod>/g, ""));
|
|
19
21
|
}
|