astro-indexnow 0.0.2 → 0.0.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 +172 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -3
- package/package.json +4 -3
- package/dist/setup.d.ts +0 -2
- package/dist/setup.d.ts.map +0 -1
- package/dist/setup.js +0 -21
package/README.md
CHANGED
|
@@ -1,8 +1,177 @@
|
|
|
1
1
|
# astro-indexnow
|
|
2
2
|
|
|
3
|
-
Astro integration that automatically submits changed pages to IndexNow
|
|
3
|
+
An Astro integration that automatically submits **changed pages** to **IndexNow**
|
|
4
|
+
after each build, helping search engines discover updates faster.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Designed to follow Astro’s official integration patterns (like `@astrojs/sitemap`):
|
|
7
|
+
- No interactive prompts
|
|
8
|
+
- No secret injection
|
|
9
|
+
- Explicit, config-driven usage
|
|
10
|
+
- CI-safe and deterministic
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## What is IndexNow?
|
|
15
|
+
|
|
16
|
+
[IndexNow](https://www.indexnow.org/) is a protocol supported by search engines
|
|
17
|
+
like **Bing** and **Yandex** that allows websites to proactively notify them
|
|
18
|
+
when URLs are added, updated, or deleted.
|
|
19
|
+
|
|
20
|
+
Instead of waiting for crawlers, your site tells search engines exactly
|
|
21
|
+
what changed.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- 🚀 Submits URLs to IndexNow **at build time**
|
|
28
|
+
- 🔁 Only submits **changed pages** (no unnecessary resubmits)
|
|
29
|
+
- 🔒 No secrets stored or prompted — fully explicit config
|
|
30
|
+
- 🧠 Uses Astro’s `site` config as the canonical base URL
|
|
31
|
+
- 🧪 Safe for CI/CD pipelines
|
|
32
|
+
- 🧩 Zero runtime impact
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install astro-indexnow
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
or using Astro’s helper:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npx astro add astro-indexnow
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
> Note: Like other Astro integrations, `astro add` installs the integration
|
|
49
|
+
> but does not inject configuration values. See usage below.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
`astro-indexnow` follows the **same configuration pattern as `@astrojs/sitemap`**.
|
|
56
|
+
|
|
57
|
+
### 1) Configure your site URL
|
|
58
|
+
|
|
59
|
+
IndexNow requires a fully qualified, canonical site URL.
|
|
60
|
+
|
|
61
|
+
In `astro.config.mjs`:
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
import { defineConfig } from "astro/config";
|
|
65
|
+
import indexNow from "astro-indexnow";
|
|
66
|
+
|
|
67
|
+
export default defineConfig({
|
|
68
|
+
site: "https://example.com",
|
|
69
|
+
|
|
70
|
+
integrations: [
|
|
71
|
+
indexNow({
|
|
72
|
+
key: "YOUR_INDEXNOW_API_KEY",
|
|
73
|
+
}),
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### 2) Using environment variables (recommended)
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
indexNow({
|
|
84
|
+
key: process.env.INDEXNOW_KEY,
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
This keeps secrets out of version control and works cleanly in CI.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Configuration Options
|
|
93
|
+
|
|
94
|
+
### `key` (required)
|
|
95
|
+
|
|
96
|
+
Type: `string`
|
|
97
|
+
|
|
98
|
+
Your IndexNow API key.
|
|
99
|
+
|
|
100
|
+
You can generate a key at:
|
|
101
|
+
- https://www.indexnow.org/
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### `site` (required, from Astro config)
|
|
106
|
+
|
|
107
|
+
Type: `string`
|
|
108
|
+
|
|
109
|
+
The integration reads the site’s canonical URL from:
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
defineConfig({
|
|
113
|
+
site: "https://example.com"
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
This **must** start with `http://` or `https://`.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## How It Works
|
|
122
|
+
|
|
123
|
+
At build time, the integration:
|
|
124
|
+
|
|
125
|
+
1. Reads Astro’s output directory
|
|
126
|
+
2. Collects all generated page URLs
|
|
127
|
+
3. Hashes and compares them to the previous build
|
|
128
|
+
4. Submits **only changed URLs** to IndexNow
|
|
129
|
+
5. Saves state for the next build
|
|
130
|
+
|
|
131
|
+
No runtime code is added to your site.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## CI / Deployment
|
|
136
|
+
|
|
137
|
+
This integration is designed to work cleanly in CI environments.
|
|
138
|
+
|
|
139
|
+
Example:
|
|
6
140
|
|
|
7
141
|
```bash
|
|
8
|
-
|
|
142
|
+
INDEXNOW_KEY=your-key astro build
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
No prompts. No interactivity. Fully deterministic.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Limitations
|
|
150
|
+
|
|
151
|
+
- IndexNow submissions only run on `astro build`
|
|
152
|
+
- Requires `site` to be configured
|
|
153
|
+
- Requires a valid IndexNow key
|
|
154
|
+
- Uninstalling the package does not automatically remove config
|
|
155
|
+
(same behaviour as other Astro integrations)
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Inspiration & Philosophy
|
|
160
|
+
|
|
161
|
+
This integration intentionally mirrors the behaviour of
|
|
162
|
+
official Astro integrations such as:
|
|
163
|
+
|
|
164
|
+
- `@astrojs/sitemap`
|
|
165
|
+
|
|
166
|
+
Astro integrations are designed to:
|
|
167
|
+
- avoid mutating user config implicitly
|
|
168
|
+
- avoid prompting for secrets
|
|
169
|
+
- rely on explicit configuration
|
|
170
|
+
|
|
171
|
+
`astro-indexnow` follows these principles strictly.
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT
|
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;
|
|
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;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC9B,OAAO,EAAE,eAAe,GACvB,gBAAgB,CAsElB"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,54 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
1
4
|
export default function indexNow(options) {
|
|
5
|
+
let site = null;
|
|
2
6
|
return {
|
|
3
7
|
name: "astro-indexnow",
|
|
4
8
|
hooks: {
|
|
5
|
-
"astro:
|
|
9
|
+
"astro:config:setup": ({ config }) => {
|
|
10
|
+
site =
|
|
11
|
+
options.siteUrl ??
|
|
12
|
+
(config.site ? config.site.replace(/\/$/, "") : null);
|
|
13
|
+
},
|
|
14
|
+
"astro:build:done": async ({ dir }) => {
|
|
6
15
|
if (options?.enabled === false) {
|
|
7
16
|
console.log("[astro-indexnow] disabled");
|
|
8
17
|
return;
|
|
9
18
|
}
|
|
10
19
|
if (!options?.key) {
|
|
11
|
-
throw new Error("[astro-indexnow] Missing IndexNow key.
|
|
20
|
+
throw new Error("[astro-indexnow] Missing IndexNow key. Provide it in astro.config.mjs.");
|
|
21
|
+
}
|
|
22
|
+
if (!site) {
|
|
23
|
+
throw new Error("[astro-indexnow] Missing `site` in astro.config.mjs (or siteUrl option).");
|
|
24
|
+
}
|
|
25
|
+
const outDir = fileURLToPath(dir);
|
|
26
|
+
const urls = [];
|
|
27
|
+
function walk(currentDir) {
|
|
28
|
+
const entries = fs.readdirSync(currentDir, {
|
|
29
|
+
withFileTypes: true,
|
|
30
|
+
});
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
33
|
+
if (entry.isDirectory()) {
|
|
34
|
+
walk(fullPath);
|
|
35
|
+
}
|
|
36
|
+
if (entry.isFile() && entry.name === "index.html") {
|
|
37
|
+
const relativePath = path
|
|
38
|
+
.relative(outDir, fullPath)
|
|
39
|
+
.replace(/index\.html$/, "")
|
|
40
|
+
.replace(/\\/g, "/");
|
|
41
|
+
const url = site + "/" + relativePath.replace(/^\/+/, "");
|
|
42
|
+
urls.push(url);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
walk(outDir);
|
|
47
|
+
// TEMP: verify detection (next step replaces this)
|
|
48
|
+
console.log("[astro-indexnow] detected pages:");
|
|
49
|
+
for (const url of urls) {
|
|
50
|
+
console.log(" -", url);
|
|
12
51
|
}
|
|
13
|
-
console.log("[astro-indexnow] build completed");
|
|
14
52
|
},
|
|
15
53
|
},
|
|
16
54
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-indexnow",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Astro integration to submit changed pages to IndexNow automatically",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
|
-
".": "./dist/index.js"
|
|
8
|
-
"./setup": "./dist/setup.js"
|
|
7
|
+
".": "./dist/index.js"
|
|
9
8
|
},
|
|
10
9
|
"files": [
|
|
11
10
|
"dist"
|
|
@@ -24,6 +23,8 @@
|
|
|
24
23
|
"astro": "^4.0.0 || ^5.0.0"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
26
|
+
"@types/node": "^25.0.3",
|
|
27
|
+
"astro-integration-kit": "^0.19.1",
|
|
27
28
|
"typescript": "^5.0.0"
|
|
28
29
|
}
|
|
29
30
|
}
|
package/dist/setup.d.ts
DELETED
package/dist/setup.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,wBAA8B,KAAK,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,GAAG,iBAuBlE"}
|
package/dist/setup.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export default async function setup({ addIntegration, prompt }) {
|
|
2
|
-
const key = await prompt({
|
|
3
|
-
name: "key",
|
|
4
|
-
type: "text",
|
|
5
|
-
message: "Enter your IndexNow API key:",
|
|
6
|
-
validate: (value) => value ? true : "IndexNow key is required",
|
|
7
|
-
});
|
|
8
|
-
const siteUrl = await prompt({
|
|
9
|
-
name: "siteUrl",
|
|
10
|
-
type: "text",
|
|
11
|
-
message: "Site URL (e.g. https://example.com):",
|
|
12
|
-
});
|
|
13
|
-
addIntegration({
|
|
14
|
-
name: "astro-indexnow",
|
|
15
|
-
import: "astro-indexnow",
|
|
16
|
-
options: {
|
|
17
|
-
key,
|
|
18
|
-
siteUrl: siteUrl || undefined,
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
}
|