astro-indexnow 2.3.2 β 2.3.4
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/README.MD +40 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -18
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -6,7 +6,7 @@ to **IndexNow** after each build.
|
|
|
6
6
|
This package is designed for **modern CI/CD pipelines**, **Docker-based deployments**, and
|
|
7
7
|
**large static sites**, while remaining fully deterministic and explicit.
|
|
8
8
|
|
|
9
|
-
> **Current release:** v2.3.
|
|
9
|
+
> **Current release:** v2.3.4
|
|
10
10
|
> **Stateful by design. `changed` by default, `all` available. Batch-safe. CI-aware.**
|
|
11
11
|
|
|
12
12
|
---
|
|
@@ -29,6 +29,8 @@ Instead of waiting for crawlers, your site tells search engines exactly which UR
|
|
|
29
29
|
- π¦ **Batches submissions** safely (IndexNow 10,000 URL limit)
|
|
30
30
|
- π Optional `submissionMode` lets you choose `changed` or `all`
|
|
31
31
|
- π§ͺ Optional `dryRun` plans submissions without sending requests
|
|
32
|
+
- π£ Optional `logMode` controls verbosity with `quiet`, `normal`, and `verbose`
|
|
33
|
+
- π¦ Optional `batchSize` lets you lower the submit batch size for testing
|
|
32
34
|
- π§ͺ Fully **CI/CD and Docker safe**
|
|
33
35
|
- π No secrets prompted, stored, or mutated
|
|
34
36
|
- π§© No client-side or runtime code added
|
|
@@ -238,6 +240,25 @@ indexnow({
|
|
|
238
240
|
|
|
239
241
|
---
|
|
240
242
|
|
|
243
|
+
### `logMode` (optional)
|
|
244
|
+
|
|
245
|
+
Type: `"quiet" | "normal" | "verbose"`
|
|
246
|
+
Default: `"normal"`
|
|
247
|
+
|
|
248
|
+
Controls how much the integration logs:
|
|
249
|
+
|
|
250
|
+
- `quiet` suppresses info and warning logs
|
|
251
|
+
- `normal` keeps high-level info and warnings, but not URL lists
|
|
252
|
+
- `verbose` includes cache, diff, and the full planned URL list
|
|
253
|
+
|
|
254
|
+
```js
|
|
255
|
+
indexnow({
|
|
256
|
+
logMode: "verbose",
|
|
257
|
+
})
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
241
262
|
### `cacheDir` (optional)
|
|
242
263
|
|
|
243
264
|
Type: `string`
|
|
@@ -267,6 +288,24 @@ indexnow({
|
|
|
267
288
|
|
|
268
289
|
---
|
|
269
290
|
|
|
291
|
+
### `batchSize` (optional)
|
|
292
|
+
|
|
293
|
+
Type: `number`
|
|
294
|
+
Default: `10000`
|
|
295
|
+
|
|
296
|
+
Controls how many URLs are submitted per IndexNow request.
|
|
297
|
+
|
|
298
|
+
- The default matches IndexNowβs documented limit
|
|
299
|
+
- Lower values are useful for testing or constrained environments
|
|
300
|
+
|
|
301
|
+
```js
|
|
302
|
+
indexnow({
|
|
303
|
+
batchSize: 100,
|
|
304
|
+
})
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
270
309
|
## IndexNow Limits & Batching
|
|
271
310
|
|
|
272
311
|
- IndexNow allows **up to 10,000 URLs per request**
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ export interface IndexNowOptions {
|
|
|
5
5
|
enabled?: boolean;
|
|
6
6
|
cacheDir?: string;
|
|
7
7
|
dryRun?: boolean;
|
|
8
|
+
logMode?: "quiet" | "normal" | "verbose";
|
|
8
9
|
submissionMode?: "changed" | "all";
|
|
10
|
+
batchSize?: number;
|
|
9
11
|
}
|
|
10
12
|
export default function indexNow(options?: IndexNowOptions): AstroIntegration;
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAM9C,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAM9C,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;IACzC,cAAc,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC9B,OAAO,GAAE,eAAoB,GAC5B,gBAAgB,CA0PlB"}
|
package/dist/index.js
CHANGED
|
@@ -11,19 +11,22 @@ export default function indexNow(options = {}) {
|
|
|
11
11
|
: path.join(projectRoot, CACHE_FILENAME);
|
|
12
12
|
const INDEXNOW_ENDPOINT = "https://api.indexnow.org/indexnow";
|
|
13
13
|
const INDEXNOW_BATCH_SIZE = 10_000;
|
|
14
|
+
const batchSize = typeof options.batchSize === "number" && options.batchSize > 0
|
|
15
|
+
? Math.floor(options.batchSize)
|
|
16
|
+
: INDEXNOW_BATCH_SIZE;
|
|
14
17
|
/* =========================================================
|
|
15
18
|
Helpers
|
|
16
19
|
========================================================= */
|
|
17
20
|
function ensureCacheFile(logger) {
|
|
18
21
|
const dir = path.dirname(cachePath);
|
|
19
22
|
if (!fs.existsSync(dir)) {
|
|
20
|
-
logger.debug(`
|
|
23
|
+
logger.debug(`creating cache directory: ${dir}`);
|
|
21
24
|
fs.mkdirSync(dir, { recursive: true });
|
|
22
25
|
}
|
|
23
26
|
const exists = fs.existsSync(cachePath);
|
|
24
|
-
logger.debug(`
|
|
27
|
+
logger.debug(`cache exists: ${exists} (${cachePath})`);
|
|
25
28
|
if (!exists) {
|
|
26
|
-
logger.debug("
|
|
29
|
+
logger.debug("creating cache file");
|
|
27
30
|
fs.writeFileSync(cachePath, "{}", "utf8");
|
|
28
31
|
}
|
|
29
32
|
}
|
|
@@ -34,17 +37,17 @@ export default function indexNow(options = {}) {
|
|
|
34
37
|
return `sha256:${hash.digest("hex")}`;
|
|
35
38
|
}
|
|
36
39
|
function loadCache(logger) {
|
|
37
|
-
logger.debug("
|
|
40
|
+
logger.debug("loading cache file");
|
|
38
41
|
try {
|
|
39
42
|
return JSON.parse(fs.readFileSync(cachePath, "utf8"));
|
|
40
43
|
}
|
|
41
44
|
catch {
|
|
42
|
-
logger.warn("
|
|
45
|
+
logger.warn("cache file unreadable, resetting");
|
|
43
46
|
return {};
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
function saveCache(logger, data) {
|
|
47
|
-
logger.debug("
|
|
50
|
+
logger.debug("writing cache file");
|
|
48
51
|
fs.writeFileSync(cachePath, JSON.stringify(data, null, 2), "utf8");
|
|
49
52
|
}
|
|
50
53
|
function chunk(array, size) {
|
|
@@ -54,6 +57,24 @@ export default function indexNow(options = {}) {
|
|
|
54
57
|
}
|
|
55
58
|
return chunks;
|
|
56
59
|
}
|
|
60
|
+
function isQuiet() {
|
|
61
|
+
return options.logMode === "quiet";
|
|
62
|
+
}
|
|
63
|
+
function isVerbose() {
|
|
64
|
+
return options.logMode === "verbose";
|
|
65
|
+
}
|
|
66
|
+
function logInfo(logger, message) {
|
|
67
|
+
if (!isQuiet())
|
|
68
|
+
logger.info(message);
|
|
69
|
+
}
|
|
70
|
+
function logWarn(logger, message) {
|
|
71
|
+
if (!isQuiet())
|
|
72
|
+
logger.warn(message);
|
|
73
|
+
}
|
|
74
|
+
function logVerbose(logger, message) {
|
|
75
|
+
if (isVerbose())
|
|
76
|
+
logger.info(message);
|
|
77
|
+
}
|
|
57
78
|
/* =========================================================
|
|
58
79
|
Integration
|
|
59
80
|
========================================================= */
|
|
@@ -67,7 +88,7 @@ export default function indexNow(options = {}) {
|
|
|
67
88
|
site =
|
|
68
89
|
options.siteUrl ??
|
|
69
90
|
(config.site ? config.site.replace(/\/$/, "") : null);
|
|
70
|
-
logger
|
|
91
|
+
logVerbose(logger, `project root: ${projectRoot}`);
|
|
71
92
|
ensureCacheFile(logger);
|
|
72
93
|
},
|
|
73
94
|
/* -----------------------------------------------
|
|
@@ -75,7 +96,7 @@ export default function indexNow(options = {}) {
|
|
|
75
96
|
----------------------------------------------- */
|
|
76
97
|
"astro:build:done": async ({ dir, logger }) => {
|
|
77
98
|
if (options.enabled === false) {
|
|
78
|
-
logger
|
|
99
|
+
logInfo(logger, "disabled");
|
|
79
100
|
return;
|
|
80
101
|
}
|
|
81
102
|
if (!options.key) {
|
|
@@ -109,30 +130,38 @@ export default function indexNow(options = {}) {
|
|
|
109
130
|
}
|
|
110
131
|
}
|
|
111
132
|
walk(outDir);
|
|
112
|
-
logger
|
|
133
|
+
logVerbose(logger, "page diff:");
|
|
113
134
|
for (const url of Object.keys(nextCache)) {
|
|
114
135
|
const state = previousCache[url] === nextCache[url]
|
|
115
136
|
? "unchanged"
|
|
116
137
|
: "new/changed";
|
|
117
|
-
|
|
138
|
+
if (isVerbose()) {
|
|
139
|
+
logVerbose(logger, ` - ${url} (${state})`);
|
|
140
|
+
}
|
|
118
141
|
}
|
|
119
142
|
const urlsToSubmit = options.submissionMode === "all"
|
|
120
143
|
? Object.keys(nextCache)
|
|
121
144
|
: changedUrls;
|
|
122
145
|
if (urlsToSubmit.length === 0) {
|
|
123
|
-
logger
|
|
146
|
+
logInfo(logger, "no changed URLs detected, skipping submission");
|
|
124
147
|
saveCache(logger, nextCache);
|
|
125
148
|
return;
|
|
126
149
|
}
|
|
127
|
-
const batches = chunk(urlsToSubmit,
|
|
128
|
-
logger
|
|
150
|
+
const batches = chunk(urlsToSubmit, batchSize);
|
|
151
|
+
logInfo(logger, `submitting ${urlsToSubmit.length} URL(s) in ${batches.length} batch(es) [mode=${options.submissionMode ?? "changed"}, batchSize=${batchSize}]`);
|
|
152
|
+
if (isVerbose()) {
|
|
153
|
+
logVerbose(logger, "planned URL list:");
|
|
154
|
+
for (const url of urlsToSubmit) {
|
|
155
|
+
logVerbose(logger, ` - ${url}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
129
158
|
if (options.dryRun) {
|
|
130
|
-
logger
|
|
159
|
+
logInfo(logger, "dry run enabled, skipping submission");
|
|
131
160
|
return;
|
|
132
161
|
}
|
|
133
162
|
for (let i = 0; i < batches.length; i++) {
|
|
134
163
|
const batch = batches[i];
|
|
135
|
-
logger
|
|
164
|
+
logVerbose(logger, `submitting batch ${i + 1}/${batches.length} (${batch.length} URLs)`);
|
|
136
165
|
try {
|
|
137
166
|
const response = await fetch(INDEXNOW_ENDPOINT, {
|
|
138
167
|
method: "POST",
|
|
@@ -145,15 +174,15 @@ export default function indexNow(options = {}) {
|
|
|
145
174
|
}),
|
|
146
175
|
});
|
|
147
176
|
if (!response.ok) {
|
|
148
|
-
logger
|
|
177
|
+
logWarn(logger, `batch ${i + 1} failed (${response.status})`);
|
|
149
178
|
}
|
|
150
179
|
}
|
|
151
180
|
catch {
|
|
152
|
-
logger
|
|
181
|
+
logWarn(logger, `batch ${i + 1} submission failed (network error)`);
|
|
153
182
|
}
|
|
154
183
|
}
|
|
155
184
|
saveCache(logger, nextCache);
|
|
156
|
-
logger
|
|
185
|
+
logInfo(logger, `IndexNow submission complete`);
|
|
157
186
|
},
|
|
158
187
|
},
|
|
159
188
|
};
|