nuxt-ai-ready 0.7.0 → 0.7.1
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/module.d.mts +2 -6
- package/dist/module.json +1 -1
- package/dist/module.mjs +33 -23
- package/dist/runtime/mcp.d.ts +25 -0
- package/dist/runtime/mcp.js +5 -0
- package/dist/runtime/server/routes/__ai-ready/cron.get.d.ts +5 -0
- package/dist/runtime/server/routes/__ai-ready/cron.get.js +3 -0
- package/dist/runtime/server/routes/__ai-ready/indexnow.post.js +4 -4
- package/dist/runtime/server/routes/__ai-ready/poll.post.js +2 -2
- package/dist/runtime/server/routes/__ai-ready/prune.post.js +2 -2
- package/dist/runtime/server/routes/__ai-ready/status.get.js +1 -1
- package/dist/runtime/server/tasks/ai-ready-cron.d.ts +2 -0
- package/dist/runtime/server/tasks/ai-ready-cron.js +17 -0
- package/dist/runtime/server/utils/indexnow.d.ts +0 -5
- package/dist/runtime/server/utils/indexnow.js +2 -2
- package/dist/runtime/server/utils/runCron.d.ts +20 -0
- package/dist/runtime/server/utils/runCron.js +32 -0
- package/dist/runtime/types.d.ts +21 -39
- package/mcp.d.ts +4 -0
- package/package.json +7 -2
- package/dist/runtime/server/tasks/ai-ready-index.d.ts +0 -11
- package/dist/runtime/server/tasks/ai-ready-index.js +0 -39
package/dist/module.d.mts
CHANGED
|
@@ -43,14 +43,10 @@ interface ModulePublicRuntimeConfig {
|
|
|
43
43
|
enabled: boolean;
|
|
44
44
|
ttl: number;
|
|
45
45
|
batchSize: number;
|
|
46
|
-
secret?: string;
|
|
47
46
|
pruneTtl: number;
|
|
48
47
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
key?: string;
|
|
52
|
-
host?: string;
|
|
53
|
-
};
|
|
48
|
+
runtimeSyncSecret?: string;
|
|
49
|
+
indexNowKey?: string;
|
|
54
50
|
}
|
|
55
51
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
56
52
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -541,16 +541,27 @@ const module$1 = defineNuxtModule({
|
|
|
541
541
|
nuxt.hooks.hook("nitro:config", (nitroConfig) => {
|
|
542
542
|
nitroConfig.experimental = nitroConfig.experimental || {};
|
|
543
543
|
nitroConfig.experimental.asyncContext = true;
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
544
|
+
if (config.cron) {
|
|
545
|
+
const cronSchedule = "* * * * *";
|
|
546
|
+
const isVercel = nitroConfig.preset === "vercel" || nitroConfig.preset === "vercel-edge";
|
|
547
|
+
if (isVercel) {
|
|
548
|
+
nitroConfig.vercel = nitroConfig.vercel || {};
|
|
549
|
+
nitroConfig.vercel.config = nitroConfig.vercel.config || {};
|
|
550
|
+
nitroConfig.vercel.config.crons = nitroConfig.vercel.config.crons || [];
|
|
551
|
+
nitroConfig.vercel.config.crons.push({
|
|
552
|
+
schedule: cronSchedule,
|
|
553
|
+
path: "/__ai-ready/cron"
|
|
554
|
+
});
|
|
555
|
+
} else {
|
|
556
|
+
nitroConfig.experimental.tasks = true;
|
|
557
|
+
nitroConfig.tasks = nitroConfig.tasks || {};
|
|
558
|
+
nitroConfig.tasks["ai-ready:cron"] = {
|
|
559
|
+
handler: resolve("./runtime/server/tasks/ai-ready-cron")
|
|
560
|
+
};
|
|
561
|
+
nitroConfig.scheduledTasks = nitroConfig.scheduledTasks || {};
|
|
562
|
+
nitroConfig.scheduledTasks[cronSchedule] = nitroConfig.scheduledTasks[cronSchedule] || [];
|
|
563
|
+
nitroConfig.scheduledTasks[cronSchedule].push("ai-ready:cron");
|
|
564
|
+
}
|
|
554
565
|
}
|
|
555
566
|
nitroConfig.virtual = nitroConfig.virtual || {};
|
|
556
567
|
nitroConfig.virtual["#ai-ready-virtual/read-page-data.mjs"] = `
|
|
@@ -592,9 +603,9 @@ export async function readPageDataFromFilesystem() {
|
|
|
592
603
|
export const errorRoutes = []`;
|
|
593
604
|
});
|
|
594
605
|
const database = refineDatabaseConfig(config.database || {}, nuxt.options.rootDir);
|
|
595
|
-
const
|
|
596
|
-
const
|
|
597
|
-
const
|
|
606
|
+
const runtimeSyncConfig = typeof config.runtimeSync === "object" ? config.runtimeSync : {};
|
|
607
|
+
const runtimeSyncEnabled = !!config.runtimeSync || !!config.cron;
|
|
608
|
+
const indexNowKey = config.indexNowKey || process.env.NUXT_AI_READY_INDEX_NOW_KEY;
|
|
598
609
|
nuxt.options.runtimeConfig["nuxt-ai-ready"] = {
|
|
599
610
|
version: version || "0.0.0",
|
|
600
611
|
debug: config.debug || false,
|
|
@@ -609,16 +620,12 @@ export const errorRoutes = []`;
|
|
|
609
620
|
database,
|
|
610
621
|
runtimeSync: {
|
|
611
622
|
enabled: runtimeSyncEnabled,
|
|
612
|
-
ttl:
|
|
613
|
-
batchSize:
|
|
614
|
-
|
|
615
|
-
pruneTtl: config.runtimeSync?.pruneTtl ?? 0
|
|
623
|
+
ttl: runtimeSyncConfig.ttl ?? 3600,
|
|
624
|
+
batchSize: runtimeSyncConfig.batchSize ?? 20,
|
|
625
|
+
pruneTtl: runtimeSyncConfig.pruneTtl ?? 0
|
|
616
626
|
},
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
key: indexNowKey,
|
|
620
|
-
host: config.indexNow?.host || "api.indexnow.org"
|
|
621
|
-
} : void 0
|
|
627
|
+
runtimeSyncSecret: config.runtimeSyncSecret,
|
|
628
|
+
indexNowKey
|
|
622
629
|
};
|
|
623
630
|
nuxt.options.nitro.plugins = nuxt.options.nitro.plugins || [];
|
|
624
631
|
nuxt.options.nitro.plugins.push(resolve("./runtime/server/plugins/db-restore"));
|
|
@@ -648,13 +655,16 @@ export const errorRoutes = []`;
|
|
|
648
655
|
addServerHandler({ route: "/__ai-ready/poll", method: "post", handler: resolve("./runtime/server/routes/__ai-ready/poll.post") });
|
|
649
656
|
addServerHandler({ route: "/__ai-ready/prune", method: "post", handler: resolve("./runtime/server/routes/__ai-ready/prune.post") });
|
|
650
657
|
}
|
|
651
|
-
if (
|
|
658
|
+
if (indexNowKey) {
|
|
652
659
|
addServerHandler({ route: `/${indexNowKey}.txt`, handler: resolve("./runtime/server/routes/indexnow-key.get") });
|
|
653
660
|
addServerHandler({ route: "/__ai-ready/indexnow", method: "post", handler: resolve("./runtime/server/routes/__ai-ready/indexnow.post") });
|
|
654
661
|
if (!runtimeSyncEnabled) {
|
|
655
662
|
addServerHandler({ route: "/__ai-ready/status", handler: resolve("./runtime/server/routes/__ai-ready/status.get") });
|
|
656
663
|
}
|
|
657
664
|
}
|
|
665
|
+
if (config.cron) {
|
|
666
|
+
addServerHandler({ route: "/__ai-ready/cron", handler: resolve("./runtime/server/routes/__ai-ready/cron.get") });
|
|
667
|
+
}
|
|
658
668
|
const isStatic = nuxt.options.nitro.static || nuxt.options._generate || false;
|
|
659
669
|
const hasPrerenderedRoutes = nuxt.options.nitro.prerender?.routes?.length;
|
|
660
670
|
const isSPA = nuxt.options.ssr === false;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const tools: readonly [import("@nuxtjs/mcp-toolkit").McpToolDefinition<Readonly<{
|
|
2
|
+
[k: string]: import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>;
|
|
3
|
+
}>, Readonly<{
|
|
4
|
+
[k: string]: import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>;
|
|
5
|
+
}>>, import("@nuxtjs/mcp-toolkit").McpToolDefinition<Readonly<{
|
|
6
|
+
[k: string]: import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>;
|
|
7
|
+
}>, Readonly<{
|
|
8
|
+
[k: string]: import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>;
|
|
9
|
+
}>>];
|
|
10
|
+
export declare const resources: readonly [{
|
|
11
|
+
uri: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
metadata: {
|
|
15
|
+
mimeType: string;
|
|
16
|
+
};
|
|
17
|
+
cache: "1h";
|
|
18
|
+
handler(uri: URL): Promise<{
|
|
19
|
+
contents: {
|
|
20
|
+
uri: string;
|
|
21
|
+
mimeType: string;
|
|
22
|
+
text: string;
|
|
23
|
+
}[];
|
|
24
|
+
}>;
|
|
25
|
+
}];
|
|
@@ -3,13 +3,13 @@ import { useRuntimeConfig } from "nitropack/runtime";
|
|
|
3
3
|
import { syncToIndexNow } from "../../utils/indexnow.js";
|
|
4
4
|
export default eventHandler(async (event) => {
|
|
5
5
|
const config = useRuntimeConfig(event)["nuxt-ai-ready"];
|
|
6
|
-
if (!config.
|
|
7
|
-
throw createError({ statusCode: 400, message: "IndexNow not
|
|
6
|
+
if (!config.indexNowKey) {
|
|
7
|
+
throw createError({ statusCode: 400, message: "IndexNow not configured" });
|
|
8
8
|
}
|
|
9
9
|
const query = getQuery(event);
|
|
10
|
-
if (config.
|
|
10
|
+
if (config.runtimeSyncSecret) {
|
|
11
11
|
const secret = query.secret;
|
|
12
|
-
if (secret !== config.
|
|
12
|
+
if (secret !== config.runtimeSyncSecret) {
|
|
13
13
|
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -4,9 +4,9 @@ import { batchIndexPages } from "../../utils/batchIndex.js";
|
|
|
4
4
|
export default eventHandler(async (event) => {
|
|
5
5
|
const config = useRuntimeConfig()["nuxt-ai-ready"];
|
|
6
6
|
const query = getQuery(event);
|
|
7
|
-
if (config.
|
|
7
|
+
if (config.runtimeSyncSecret) {
|
|
8
8
|
const secret = query.secret;
|
|
9
|
-
if (secret !== config.
|
|
9
|
+
if (secret !== config.runtimeSyncSecret) {
|
|
10
10
|
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -5,9 +5,9 @@ export default eventHandler(async (event) => {
|
|
|
5
5
|
const config = useRuntimeConfig()["nuxt-ai-ready"];
|
|
6
6
|
const query = getQuery(event);
|
|
7
7
|
const dry = query.dry === "true" || query.dry === "1";
|
|
8
|
-
if (!dry && config.
|
|
8
|
+
if (!dry && config.runtimeSyncSecret) {
|
|
9
9
|
const secret = query.secret;
|
|
10
|
-
if (secret !== config.
|
|
10
|
+
if (secret !== config.runtimeSyncSecret) {
|
|
11
11
|
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -12,7 +12,7 @@ export default eventHandler(async (event) => {
|
|
|
12
12
|
indexed: total - pending,
|
|
13
13
|
pending
|
|
14
14
|
};
|
|
15
|
-
if (config.
|
|
15
|
+
if (config.indexNowKey) {
|
|
16
16
|
const [indexNowPending, indexNowStats] = await Promise.all([
|
|
17
17
|
countPagesNeedingIndexNowSync(event),
|
|
18
18
|
getIndexNowStats(event)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineTask } from "nitropack/runtime";
|
|
2
|
+
import { runCron } from "../utils/runCron.js";
|
|
3
|
+
export default defineTask({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "ai-ready:cron",
|
|
6
|
+
description: "Scheduled task for AI Ready - runs indexing and IndexNow sync"
|
|
7
|
+
},
|
|
8
|
+
async run({ payload }) {
|
|
9
|
+
const mockEvent = {
|
|
10
|
+
$fetch: globalThis.$fetch
|
|
11
|
+
};
|
|
12
|
+
const result = await runCron(mockEvent, {
|
|
13
|
+
batchSize: payload?.limit
|
|
14
|
+
});
|
|
15
|
+
return { result };
|
|
16
|
+
}
|
|
17
|
+
});
|
|
@@ -38,7 +38,7 @@ export async function submitToIndexNow(routes, config, siteUrl) {
|
|
|
38
38
|
export async function syncToIndexNow(event, limit = 100) {
|
|
39
39
|
const config = useRuntimeConfig(event)["nuxt-ai-ready"];
|
|
40
40
|
const siteConfig = useSiteConfig();
|
|
41
|
-
if (!config.
|
|
41
|
+
if (!config.indexNowKey) {
|
|
42
42
|
return { success: false, submitted: 0, remaining: 0, error: "IndexNow not configured" };
|
|
43
43
|
}
|
|
44
44
|
if (!siteConfig.url) {
|
|
@@ -49,7 +49,7 @@ export async function syncToIndexNow(event, limit = 100) {
|
|
|
49
49
|
return { success: true, submitted: 0, remaining: 0 };
|
|
50
50
|
}
|
|
51
51
|
const routes = pages.map((p) => p.route);
|
|
52
|
-
const result = await submitToIndexNow(routes, config.
|
|
52
|
+
const result = await submitToIndexNow(routes, { key: config.indexNowKey }, siteConfig.url);
|
|
53
53
|
if (result.success) {
|
|
54
54
|
await markIndexNowSynced(event, routes);
|
|
55
55
|
await updateIndexNowStats(event, routes.length);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
export interface CronResult {
|
|
3
|
+
index?: {
|
|
4
|
+
indexed: number;
|
|
5
|
+
remaining: number;
|
|
6
|
+
errors?: string[];
|
|
7
|
+
complete: boolean;
|
|
8
|
+
};
|
|
9
|
+
indexNow?: {
|
|
10
|
+
submitted: number;
|
|
11
|
+
remaining: number;
|
|
12
|
+
error?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Run cron job logic - shared between scheduled task and HTTP endpoint
|
|
17
|
+
*/
|
|
18
|
+
export declare function runCron(event: H3Event, options?: {
|
|
19
|
+
batchSize?: number;
|
|
20
|
+
}): Promise<CronResult>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
2
|
+
import { batchIndexPages } from "./batchIndex.js";
|
|
3
|
+
import { syncToIndexNow } from "./indexnow.js";
|
|
4
|
+
export async function runCron(event, options) {
|
|
5
|
+
const config = useRuntimeConfig()["nuxt-ai-ready"];
|
|
6
|
+
const results = {};
|
|
7
|
+
if (config.runtimeSync.enabled) {
|
|
8
|
+
const limit = options?.batchSize ?? config.runtimeSync.batchSize;
|
|
9
|
+
const indexResult = await batchIndexPages(event, {
|
|
10
|
+
limit,
|
|
11
|
+
all: false
|
|
12
|
+
});
|
|
13
|
+
results.index = {
|
|
14
|
+
indexed: indexResult.indexed,
|
|
15
|
+
remaining: indexResult.remaining,
|
|
16
|
+
errors: indexResult.errors.length > 0 ? indexResult.errors : void 0,
|
|
17
|
+
complete: indexResult.complete
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (config.indexNowKey) {
|
|
21
|
+
const indexNowResult = await syncToIndexNow(event, 100).catch((err) => {
|
|
22
|
+
console.warn("[ai-ready:cron] IndexNow sync failed:", err.message);
|
|
23
|
+
return { success: false, submitted: 0, remaining: 0, error: err.message };
|
|
24
|
+
});
|
|
25
|
+
results.indexNow = {
|
|
26
|
+
submitted: indexNowResult.submitted,
|
|
27
|
+
remaining: indexNowResult.remaining,
|
|
28
|
+
error: indexNowResult.error
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return results;
|
|
32
|
+
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -103,18 +103,31 @@ export interface ModuleOptions {
|
|
|
103
103
|
*/
|
|
104
104
|
authToken?: string;
|
|
105
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* Enable scheduled cron task (runs every minute)
|
|
108
|
+
* When true, automatically enables runtimeSync for background indexing
|
|
109
|
+
* Also runs IndexNow sync if indexNowKey is configured
|
|
110
|
+
*/
|
|
111
|
+
cron?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* IndexNow API key for instant search engine notifications
|
|
114
|
+
* When set, enables IndexNow submissions to Bing, Yandex, Naver, Seznam
|
|
115
|
+
* Get one from https://www.bing.com/indexnow
|
|
116
|
+
* Can also be set via NUXT_AI_READY_INDEX_NOW_KEY env var
|
|
117
|
+
*/
|
|
118
|
+
indexNowKey?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Secret token for authenticating runtime sync endpoints
|
|
121
|
+
* When set, requires ?secret=<token> query param for poll/prune/indexnow endpoints
|
|
122
|
+
*/
|
|
123
|
+
runtimeSyncSecret?: string;
|
|
106
124
|
/**
|
|
107
125
|
* Runtime sync configuration (opt-in for dynamic content sites)
|
|
108
126
|
* When enabled, pages are re-indexed at runtime from sitemap
|
|
109
|
-
*
|
|
127
|
+
* Set to `true` for defaults or object to customize
|
|
128
|
+
* @default false - prerendered data is used
|
|
110
129
|
*/
|
|
111
|
-
runtimeSync?: {
|
|
112
|
-
/**
|
|
113
|
-
* Enable runtime sync
|
|
114
|
-
* When false (default), runtime uses prerendered data only
|
|
115
|
-
* @default false
|
|
116
|
-
*/
|
|
117
|
-
enabled?: boolean;
|
|
130
|
+
runtimeSync?: boolean | {
|
|
118
131
|
/**
|
|
119
132
|
* TTL for refresh in seconds (sitemap + page re-indexing)
|
|
120
133
|
* Controls how often to refresh sitemap routes and re-index stale pages
|
|
@@ -126,16 +139,6 @@ export interface ModuleOptions {
|
|
|
126
139
|
* @default 20
|
|
127
140
|
*/
|
|
128
141
|
batchSize?: number;
|
|
129
|
-
/**
|
|
130
|
-
* Cron expression for scheduled indexing (e.g. every 5 minutes)
|
|
131
|
-
* When set, enables automatic background indexing via Nitro task
|
|
132
|
-
*/
|
|
133
|
-
cron?: string;
|
|
134
|
-
/**
|
|
135
|
-
* Secret token for authenticating poll endpoint
|
|
136
|
-
* When set, requires ?secret=<token> query param
|
|
137
|
-
*/
|
|
138
|
-
secret?: string;
|
|
139
142
|
/**
|
|
140
143
|
* TTL for pruning stale routes in seconds
|
|
141
144
|
* Routes not seen in sitemap for longer than this are deleted
|
|
@@ -144,27 +147,6 @@ export interface ModuleOptions {
|
|
|
144
147
|
*/
|
|
145
148
|
pruneTtl?: number;
|
|
146
149
|
};
|
|
147
|
-
/**
|
|
148
|
-
* IndexNow configuration for instant search engine notifications
|
|
149
|
-
* Submits changed URLs to Bing, Yandex, Naver, Seznam via IndexNow protocol
|
|
150
|
-
*/
|
|
151
|
-
indexNow?: {
|
|
152
|
-
/**
|
|
153
|
-
* Enable IndexNow submissions
|
|
154
|
-
* @default false
|
|
155
|
-
*/
|
|
156
|
-
enabled?: boolean;
|
|
157
|
-
/**
|
|
158
|
-
* Your IndexNow API key
|
|
159
|
-
* Get one from https://www.bing.com/indexnow
|
|
160
|
-
*/
|
|
161
|
-
key?: string;
|
|
162
|
-
/**
|
|
163
|
-
* IndexNow endpoint host
|
|
164
|
-
* @default 'api.indexnow.org'
|
|
165
|
-
*/
|
|
166
|
-
host?: string;
|
|
167
|
-
};
|
|
168
150
|
}
|
|
169
151
|
/**
|
|
170
152
|
* Page-level entry for discovery and metadata queries
|
package/mcp.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-ai-ready",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"description": "Best practice AI & LLM discoverability for Nuxt sites.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -25,11 +25,16 @@
|
|
|
25
25
|
".": {
|
|
26
26
|
"types": "./dist/types.d.mts",
|
|
27
27
|
"import": "./dist/module.mjs"
|
|
28
|
+
},
|
|
29
|
+
"./mcp": {
|
|
30
|
+
"types": "./mcp.d.ts",
|
|
31
|
+
"import": "./dist/runtime/mcp.js"
|
|
28
32
|
}
|
|
29
33
|
},
|
|
30
34
|
"main": "./dist/module.mjs",
|
|
31
35
|
"files": [
|
|
32
|
-
"dist"
|
|
36
|
+
"dist",
|
|
37
|
+
"mcp.d.ts"
|
|
33
38
|
],
|
|
34
39
|
"peerDependencies": {
|
|
35
40
|
"@nuxtjs/sitemap": "^7.0.0",
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { defineTask, useRuntimeConfig } from "nitropack/runtime";
|
|
2
|
-
import { batchIndexPages } from "../utils/batchIndex.js";
|
|
3
|
-
import { syncToIndexNow } from "../utils/indexnow.js";
|
|
4
|
-
export default defineTask({
|
|
5
|
-
meta: {
|
|
6
|
-
name: "ai-ready:index",
|
|
7
|
-
description: "Index pending pages for AI Ready"
|
|
8
|
-
},
|
|
9
|
-
async run({ payload }) {
|
|
10
|
-
const config = useRuntimeConfig()["nuxt-ai-ready"];
|
|
11
|
-
const limit = payload?.limit ?? config.runtimeSync.batchSize;
|
|
12
|
-
const mockEvent = {
|
|
13
|
-
$fetch: globalThis.$fetch
|
|
14
|
-
};
|
|
15
|
-
const result = await batchIndexPages(mockEvent, {
|
|
16
|
-
limit,
|
|
17
|
-
all: false
|
|
18
|
-
});
|
|
19
|
-
let indexNowResult;
|
|
20
|
-
if (config.indexNow?.enabled) {
|
|
21
|
-
indexNowResult = await syncToIndexNow(mockEvent, 100).catch((err) => {
|
|
22
|
-
console.warn("[ai-ready:index] IndexNow sync failed:", err.message);
|
|
23
|
-
return { success: false, submitted: 0, error: err.message };
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
result: {
|
|
28
|
-
indexed: result.indexed,
|
|
29
|
-
remaining: result.remaining,
|
|
30
|
-
errors: result.errors,
|
|
31
|
-
complete: result.complete,
|
|
32
|
-
indexNow: indexNowResult ? {
|
|
33
|
-
submitted: indexNowResult.submitted,
|
|
34
|
-
error: indexNowResult.error
|
|
35
|
-
} : void 0
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
});
|