astro-indexnow 0.0.4 → 0.0.5
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/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AstroIntegration } from "astro";
|
|
2
2
|
export interface IndexNowOptions {
|
|
3
|
-
key
|
|
3
|
+
key?: string;
|
|
4
4
|
siteUrl?: string;
|
|
5
5
|
enabled?: boolean;
|
|
6
6
|
}
|
|
7
|
-
export default function indexNow(options
|
|
7
|
+
export default function indexNow(options?: IndexNowOptions): AstroIntegration;
|
|
8
8
|
//# 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;AAK9C,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAK9C,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC9B,OAAO,GAAE,eAAoB,GAC5B,gBAAgB,CA0GlB"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
|
-
export default function indexNow(options) {
|
|
4
|
+
export default function indexNow(options = {}) {
|
|
5
5
|
let site = null;
|
|
6
6
|
return {
|
|
7
7
|
name: "astro-indexnow",
|
|
@@ -12,11 +12,11 @@ export default function indexNow(options) {
|
|
|
12
12
|
(config.site ? config.site.replace(/\/$/, "") : null);
|
|
13
13
|
},
|
|
14
14
|
"astro:build:done": async ({ dir }) => {
|
|
15
|
-
if (options
|
|
15
|
+
if (options.enabled === false) {
|
|
16
16
|
console.log("[astro-indexnow] disabled");
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
if (!options
|
|
19
|
+
if (!options.key) {
|
|
20
20
|
throw new Error("[astro-indexnow] Missing IndexNow key. Provide it in astro.config.mjs.");
|
|
21
21
|
}
|
|
22
22
|
if (!site) {
|
|
@@ -44,11 +44,38 @@ export default function indexNow(options) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
walk(outDir);
|
|
47
|
-
//
|
|
47
|
+
// ✅ KEEP EXISTING LOGGING
|
|
48
48
|
console.log("[astro-indexnow] detected pages:");
|
|
49
49
|
for (const url of urls) {
|
|
50
50
|
console.log(" -", url);
|
|
51
51
|
}
|
|
52
|
+
if (urls.length === 0) {
|
|
53
|
+
console.log("[astro-indexnow] no pages detected, skipping submission");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// ✅ INDEXNOW SUBMISSION (new)
|
|
57
|
+
try {
|
|
58
|
+
const response = await fetch("https://api.indexnow.org/indexnow", {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: {
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
},
|
|
63
|
+
body: JSON.stringify({
|
|
64
|
+
host: new URL(site).host,
|
|
65
|
+
key: options.key,
|
|
66
|
+
keyLocation: `${site}/${options.key}.txt`,
|
|
67
|
+
urlList: urls,
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
console.warn(`[astro-indexnow] IndexNow request failed (${response.status})`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
console.log(`[astro-indexnow] successfully submitted ${urls.length} URLs to IndexNow`);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.warn("[astro-indexnow] IndexNow submission failed (network error)");
|
|
78
|
+
}
|
|
52
79
|
},
|
|
53
80
|
},
|
|
54
81
|
};
|