@djangocfg/nextjs 2.1.575 → 2.1.577
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/config/index.d.mts +26 -1
- package/dist/config/index.mjs +10 -0
- package/dist/config/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/config/index.ts +3 -0
- package/src/config/indexnow.test.ts +23 -0
- package/src/config/indexnow.ts +27 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/nextjs",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.577",
|
|
4
4
|
"description": "Next.js server utilities: sitemap, health, OG images, contact forms, navigation, config",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nextjs",
|
|
@@ -149,9 +149,9 @@
|
|
|
149
149
|
"ai-docs": "tsx src/ai/cli.ts"
|
|
150
150
|
},
|
|
151
151
|
"peerDependencies": {
|
|
152
|
-
"@djangocfg/devtools": "^2.1.
|
|
153
|
-
"@djangocfg/i18n": "^2.1.
|
|
154
|
-
"@djangocfg/ui-core": "^2.1.
|
|
152
|
+
"@djangocfg/devtools": "^2.1.577",
|
|
153
|
+
"@djangocfg/i18n": "^2.1.577",
|
|
154
|
+
"@djangocfg/ui-core": "^2.1.577",
|
|
155
155
|
"next": "^16.2.2"
|
|
156
156
|
},
|
|
157
157
|
"peerDependenciesMeta": {
|
|
@@ -170,11 +170,11 @@
|
|
|
170
170
|
"semver": "^7.8.5"
|
|
171
171
|
},
|
|
172
172
|
"devDependencies": {
|
|
173
|
-
"@djangocfg/devtools": "^2.1.
|
|
174
|
-
"@djangocfg/i18n": "^2.1.
|
|
175
|
-
"@djangocfg/layouts": "^2.1.
|
|
176
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
177
|
-
"@djangocfg/ui-core": "^2.1.
|
|
173
|
+
"@djangocfg/devtools": "^2.1.577",
|
|
174
|
+
"@djangocfg/i18n": "^2.1.577",
|
|
175
|
+
"@djangocfg/layouts": "^2.1.577",
|
|
176
|
+
"@djangocfg/typescript-config": "^2.1.577",
|
|
177
|
+
"@djangocfg/ui-core": "^2.1.577",
|
|
178
178
|
"@types/node": "^25.9.5",
|
|
179
179
|
"@types/react": "19.2.15",
|
|
180
180
|
"@types/react-dom": "19.2.3",
|
package/src/config/index.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
|
|
4
|
+
// @ts-expect-error — Next's vendored copy ships no types; it is the matcher rewrites use.
|
|
5
|
+
import { pathToRegexp } from 'next/dist/compiled/path-to-regexp';
|
|
6
|
+
|
|
7
|
+
import { indexNowKeyRewrite } from './indexnow';
|
|
8
|
+
|
|
9
|
+
test('the rewrite matches a key at the root and nothing deeper', () => {
|
|
10
|
+
const { source } = indexNowKeyRewrite('https://api.example.com');
|
|
11
|
+
const re: RegExp = pathToRegexp(source, []);
|
|
12
|
+
assert.ok(re.test('/865178f53dba1db23f3fc4fe95e9b64a.txt'));
|
|
13
|
+
assert.ok(!re.test('/robots.txt'), 'under 8 chars is not a key');
|
|
14
|
+
assert.ok(!re.test('/a/865178f53dba1db23f3fc4fe95e9b64a.txt'));
|
|
15
|
+
assert.ok(!re.test('/has_underscore_.txt'));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('the destination is Django, without a doubled slash', () => {
|
|
19
|
+
assert.equal(
|
|
20
|
+
indexNowKeyRewrite('https://api.example.com/').destination,
|
|
21
|
+
'https://api.example.com/cfg/sitemap/indexnow/:key.txt',
|
|
22
|
+
);
|
|
23
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IndexNow key file, served by Django.
|
|
3
|
+
*
|
|
4
|
+
* The protocol proves host ownership by fetching `https://<host>/<key>.txt`.
|
|
5
|
+
* Django answers it at `/cfg/sitemap/indexnow/<key>.txt` from
|
|
6
|
+
* `IndexNowConfig` — only the configured key, every other name 404s — so the
|
|
7
|
+
* key lives in one place and the frontend ships no file.
|
|
8
|
+
*
|
|
9
|
+
* Put it in `fallback`: real public files and routes (`robots.txt`,
|
|
10
|
+
* `llms-full.txt`) match the same shape and must win.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { indexNowKeyRewrite } from '@djangocfg/nextjs/config';
|
|
15
|
+
*
|
|
16
|
+
* async rewrites() {
|
|
17
|
+
* return { beforeFiles: [], afterFiles: [], fallback: [indexNowKeyRewrite(API_URL)] };
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function indexNowKeyRewrite(apiUrl: string): { source: string; destination: string } {
|
|
22
|
+
return {
|
|
23
|
+
// The protocol's key alphabet and length, at the site root only.
|
|
24
|
+
source: '/:key([A-Za-z0-9-]{8,128}).txt',
|
|
25
|
+
destination: `${apiUrl.replace(/\/+$/, '')}/cfg/sitemap/indexnow/:key.txt`,
|
|
26
|
+
};
|
|
27
|
+
}
|