next-advanced-sitemap 1.1.2 → 1.1.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 +162 -39
- package/dist/index.cjs +51 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.js +51 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,23 +11,23 @@ While Next.js provides a built-in `MetadataRoute.Sitemap` utility, it currently
|
|
|
11
11
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
|
-
- **Google Images Support**:
|
|
15
|
-
- **Image Accessibility
|
|
16
|
-
- **Google Video Support**:
|
|
17
|
-
- **Video Engagement Metrics (v1.1.3
|
|
18
|
-
- **
|
|
19
|
-
- **Google
|
|
20
|
-
- **
|
|
21
|
-
- **
|
|
22
|
-
- **Auto-
|
|
23
|
-
- **
|
|
24
|
-
- **
|
|
25
|
-
- **Strict
|
|
26
|
-
- **
|
|
27
|
-
- **
|
|
28
|
-
- **
|
|
14
|
+
- **Google Images Support**: Complete indexation of visual assets with support for titles, captions, local SEO positioning, and copyright protections.
|
|
15
|
+
- **Image Accessibility Protection (v1.1.2)**: Advanced preventive protection against empty text strings or spaces (`.trim()`) in `title` and `caption` fields to completely eliminate malformed empty XML tokens.
|
|
16
|
+
- **Google Video Support**: Boost video search layouts and video-carousel presence on Google Search with complete structured data encapsulation.
|
|
17
|
+
- **Video Engagement Metrics & Validation (v1.1.3)**: Native integration of `<video:duration>` and `<video:view_count>` statistical metrics featuring deterministic float truncation (`Math.floor`) and strict bounding boundaries (0 to 28,800 seconds max).
|
|
18
|
+
- **Video Country & Device Restrictions (v1.1.4)**: Advanced access control policy injection via `<video:restriction>` and `<video:platform>` properties to strictly control video delivery layouts across global boundaries and distinct screen classes (`web`, `mobile`, `tv`).
|
|
19
|
+
- **Google Video Live Streaming (v1.1.1)**: Native injection of the `<video:live>` parameter to flag active real-time broadcasts and instantly trigger red **LIVE** badges on Google SERP matrices.
|
|
20
|
+
- **Google News Support**: Instant discovery for news publications with strict support for required news name, language tag, and publication date attributes.
|
|
21
|
+
- **Internationalization (Hreflang)**: Seamless rendering of `xhtml:link` relation tags to govern multi-regional and multilingual indexing across global markets.
|
|
22
|
+
- **Priority Auto-Sorting (v1.0.8)**: Optional deterministic descending sort (`1.0` down to `0.0`) based on entry weights to present your most strategic revenue-driving pages to crawlers first.
|
|
23
|
+
- **Auto-Trimming Sanitization (v1.0.7)**: Automatic `.trim()` execution on all URL structures to silently correct leading/trailing whitespace errors originating from CMS fields or raw databases.
|
|
24
|
+
- **Native Date Polymorphism (v1.0.6)**: Full support for native JavaScript `Date` objects inside all extensions—handling internal conversion and structural formatting automatically.
|
|
25
|
+
- **Strict SEO Enum Typing (v1.0.5)**: Compile-time validation and IDE autocompletion for `changefreq` and `priority` keys to completely lock out manual layout typos.
|
|
26
|
+
- **Strict Structural Validation (v1.0.4)**: Advanced URL parsing using the platform-native engine to intercept syntax errors and unencoded internal spaces before application deployment.
|
|
27
|
+
- **Auto-lastmod (v1.0.3)**: Optional automatic injection of the current system ISO date for entries missing an explicit `lastmod` tracking value.
|
|
28
|
+
- **Deep XML Metadata Escaping (v1.0.2)**: Enhanced, high-performance regex processor to safely handle complex special characters (`&`, `"`, `'`, `<`, `>`) inside titles, descriptions, and captions.
|
|
29
29
|
- **Custom TTL Cache-Control (v1.0.9)**: Direct control over sitemap caching persistence using a clean `maxAge` configuration option to lower crawl footprints on backend nodes.
|
|
30
|
-
- **Local SEO & Image Licensing (v1.1.0)**:
|
|
30
|
+
- **Local SEO & Image Licensing (v1.1.0)**: Support for `geo_location` parameters and programmatic `license` badges to trigger Google's image search retail overlay.
|
|
31
31
|
|
|
32
32
|
## Installation
|
|
33
33
|
|
|
@@ -55,15 +55,26 @@ export async function GET() {
|
|
|
55
55
|
]
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
|
-
url: 'https://fomadev.com/
|
|
58
|
+
url: 'https://fomadev.com/exclusive-movie',
|
|
59
59
|
priority: 0.9,
|
|
60
60
|
videos: [
|
|
61
61
|
{
|
|
62
|
-
thumbnail_loc: 'https://fomadev.com/thumbs/
|
|
63
|
-
title: 'FomaDev
|
|
64
|
-
description: 'Building production-grade
|
|
62
|
+
thumbnail_loc: 'https://fomadev.com/thumbs/movie.jpg',
|
|
63
|
+
title: 'FomaDev Premium Masterclass',
|
|
64
|
+
description: 'Building global production-grade architectures with Next.js.',
|
|
65
65
|
publication_date: new Date(),
|
|
66
|
-
|
|
66
|
+
duration: 7200,
|
|
67
|
+
view_count: 25000,
|
|
68
|
+
// v1.1.4: Strict Geographic Filtering & Capitalization Sanitization
|
|
69
|
+
restriction: {
|
|
70
|
+
relationship: 'allow',
|
|
71
|
+
countries: ['cd', 'fr', 'us'] // Automatically sanitized into 'CD FR US'
|
|
72
|
+
},
|
|
73
|
+
// v1.1.4: Native Screen-Class Targeting Controls
|
|
74
|
+
platform: {
|
|
75
|
+
relationship: 'deny',
|
|
76
|
+
platforms: ['tv'] // Deny indexing out for Smart TV layouts
|
|
77
|
+
}
|
|
67
78
|
}
|
|
68
79
|
]
|
|
69
80
|
},
|
|
@@ -117,59 +128,171 @@ Generates a standard Next.js `Response` object with the correct `application/xml
|
|
|
117
128
|
<tbody>
|
|
118
129
|
<tr>
|
|
119
130
|
<td><code>url</code></td>
|
|
120
|
-
<td
|
|
121
|
-
<td>
|
|
131
|
+
<td>string</td>
|
|
132
|
+
<td><strong>Required.</strong> Absolute target link (must begin with http:// or https://).</td>
|
|
122
133
|
</tr>
|
|
123
134
|
<tr>
|
|
124
135
|
<td><code>lastmod</code></td>
|
|
125
|
-
<td
|
|
126
|
-
<td>
|
|
136
|
+
<td>Date | string</td>
|
|
137
|
+
<td>Optional tracking timestamp reflecting last structural update.</td>
|
|
127
138
|
</tr>
|
|
128
139
|
<tr>
|
|
129
140
|
<td><code>changefreq</code></td>
|
|
130
|
-
<td
|
|
131
|
-
<td>
|
|
141
|
+
<td>SitemapChangeFreq</td>
|
|
142
|
+
<td>Optional hint keyword mapped to engine crawling loops</td>
|
|
132
143
|
</tr>
|
|
133
144
|
<tr>
|
|
134
145
|
<td><code>priority</code></td>
|
|
135
|
-
<td
|
|
136
|
-
<td>
|
|
146
|
+
<td>SitemapPriority</td>
|
|
147
|
+
<td>Optional weight coefficient bounding page value from 0.0 to 1.0.</td>
|
|
137
148
|
</tr>
|
|
138
149
|
<tr>
|
|
139
150
|
<td><code>images</code></td>
|
|
140
|
-
<td
|
|
141
|
-
<td>
|
|
151
|
+
<td>SitemapImage[]</td>
|
|
152
|
+
<td>Optional array containing structural metadata assets for Google Images.</td>
|
|
142
153
|
</tr>
|
|
143
154
|
<tr>
|
|
144
155
|
<td><code>videos</code></td>
|
|
145
|
-
<td
|
|
146
|
-
<td>
|
|
156
|
+
<td>SitemapVideo[]</td>
|
|
157
|
+
<td>Optional array conveying detailed schemas for rich video indexation.</td>
|
|
147
158
|
</tr>
|
|
148
159
|
<tr>
|
|
149
160
|
<td><code>news</code></td>
|
|
150
|
-
<td
|
|
151
|
-
<td>
|
|
161
|
+
<td>SitemapNews</td>
|
|
162
|
+
<td>Optional integration configuration complying with Google News indexing rules.</td>
|
|
152
163
|
</tr>
|
|
153
164
|
<tr>
|
|
154
165
|
<td><code>alternates</code></td>
|
|
155
|
-
<td
|
|
156
|
-
<td>
|
|
166
|
+
<td>SitemapAlternate[]</td>
|
|
167
|
+
<td>Optional translation links array serving Hreflang indexing loops.</td>
|
|
157
168
|
</tr>
|
|
158
169
|
<tr>
|
|
159
170
|
<td><code>geo_location</code></td>
|
|
160
|
-
<td
|
|
171
|
+
<td>string</td>
|
|
161
172
|
<td>(Optional) Geographic location string of the image (e.g., "Kinshasa, DRC").</td>
|
|
162
173
|
</tr>
|
|
163
174
|
<tr>
|
|
164
175
|
<td><code>license</code></td>
|
|
165
|
-
<td
|
|
176
|
+
<td>string</td>
|
|
166
177
|
<td>(Optional) Valid HTTP/HTTPS URL addressing the licensing rights or usage terms of the image asset.</td>
|
|
167
178
|
</tr>
|
|
168
179
|
</tbody>
|
|
169
180
|
</table>
|
|
170
181
|
|
|
182
|
+
### SitemapImage
|
|
183
|
+
|
|
184
|
+
<table>
|
|
185
|
+
<thead>
|
|
186
|
+
<tr>
|
|
187
|
+
<th>Property</th>
|
|
188
|
+
<th>Type</th>
|
|
189
|
+
<th>Description</th>
|
|
190
|
+
</tr>
|
|
191
|
+
</thead>
|
|
192
|
+
<tbody>
|
|
193
|
+
<tr>
|
|
194
|
+
<td><code>loc</code></td>
|
|
195
|
+
<td>string</td>
|
|
196
|
+
<td><strong>Required.</strong> The absolute URL targeting the source image asset.</td>
|
|
197
|
+
</tr>
|
|
198
|
+
<tr>
|
|
199
|
+
<td><code>title</code></td>
|
|
200
|
+
<td>string</td>
|
|
201
|
+
<td>Optional text representation describing the visual asset. Auto-trimmed.</td>
|
|
202
|
+
</tr>
|
|
203
|
+
<tr>
|
|
204
|
+
<td><code>caption</code></td>
|
|
205
|
+
<td>string</td>
|
|
206
|
+
<td>Optional descriptive context surrounding the element. Deep XML Escaped.</td>
|
|
207
|
+
</tr>
|
|
208
|
+
<tr>
|
|
209
|
+
<td><code>geo_location</code></td>
|
|
210
|
+
<td>string</td>
|
|
211
|
+
<td>Optional location reference (e.g., "Kinshasa, Democratic Republic of the Congo").</td>
|
|
212
|
+
</tr>
|
|
213
|
+
<tr>
|
|
214
|
+
<td><code>license</code></td>
|
|
215
|
+
<td>string</td>
|
|
216
|
+
<td>Optional absolute URL containing intellectual copyright terms or usage badges.</td>
|
|
217
|
+
</tr>
|
|
218
|
+
</tbody>
|
|
219
|
+
</table>
|
|
220
|
+
|
|
221
|
+
### SitemapVideo
|
|
222
|
+
|
|
223
|
+
<table>
|
|
224
|
+
<thead>
|
|
225
|
+
<tr>
|
|
226
|
+
<th>Property</th>
|
|
227
|
+
<th>Type</th>
|
|
228
|
+
<th>Description</th>
|
|
229
|
+
</tr>
|
|
230
|
+
</thead>
|
|
231
|
+
<tbody>
|
|
232
|
+
<tr>
|
|
233
|
+
<td><code>thumbnail_loc</code></td>
|
|
234
|
+
<td>string</td>
|
|
235
|
+
<td><strong>Required.</strong> The absolute URL targeting the source image asset.</td>
|
|
236
|
+
</tr>
|
|
237
|
+
<tr>
|
|
238
|
+
<td><code>title</code></td>
|
|
239
|
+
<td>string</td>
|
|
240
|
+
<td><strong>Required.</strong> The descriptive headline of the video asset. Escaped.</td>
|
|
241
|
+
</tr>
|
|
242
|
+
<tr>
|
|
243
|
+
<td><code>description</code></td>
|
|
244
|
+
<td>string</td>
|
|
245
|
+
<td><strong>Required.</strong> Summary text representing the video topic. Max 2048 chars.</td>
|
|
246
|
+
</tr>
|
|
247
|
+
<tr>
|
|
248
|
+
<td><code>publication_date</code></td>
|
|
249
|
+
<td>Date | string</td>
|
|
250
|
+
<td><strong>Required.</strong> Publication date object or raw formatted ISO string.</td>
|
|
251
|
+
</tr>
|
|
252
|
+
<tr>
|
|
253
|
+
<td><code>content_loc</code></td>
|
|
254
|
+
<td>string</td>
|
|
255
|
+
<td>Optional absolute URL targeting the raw video media stream container.</td>
|
|
256
|
+
</tr>
|
|
257
|
+
<tr>
|
|
258
|
+
<td><code>player_loc</code></td>
|
|
259
|
+
<td>string</td>
|
|
260
|
+
<td>Optional absolute URL linking out to an embeddable video player frame.</td>
|
|
261
|
+
</tr>
|
|
262
|
+
<tr>
|
|
263
|
+
<td><code>duration</code></td>
|
|
264
|
+
<td>number</td>
|
|
265
|
+
<td>Optional length in seconds. Must be an integer bounded between 0 and 28800.</td>
|
|
266
|
+
</tr>
|
|
267
|
+
<tr>
|
|
268
|
+
<td><code>view_count</code></td>
|
|
269
|
+
<td>number</td>
|
|
270
|
+
<td>Optional overall hit counter. Negative values strictly prohibited.</td>
|
|
271
|
+
</tr>
|
|
272
|
+
<tr>
|
|
273
|
+
<td><code>live</code></td>
|
|
274
|
+
<td>'yes' | 'no'</td>
|
|
275
|
+
<td>Optional switch triggering immediate Google SERP LIVE badges.</td>
|
|
276
|
+
</tr>
|
|
277
|
+
</tbody>
|
|
278
|
+
</table>
|
|
279
|
+
|
|
171
280
|
## Technical Implementation
|
|
172
281
|
|
|
282
|
+
### Video Distribution Rights & Geo-Blocking Safeguards (v1.1.4)
|
|
283
|
+
For streaming platforms, modern SaaS corporations, and decentralized content houses, geoblocking and device-specific index filtering are critical mechanisms needed to comply with broadcasting licenses and localized compliance laws. **v1.1.4** delivers high-performance runtime guardrails enforcing the exact schemas expected by Googlebot:
|
|
284
|
+
|
|
285
|
+
- **ISO 3166 Sanitation & Normalization**: Raw arrays housing country tokens are fully trimmed and mutated into pure uppercase codes automatically (e.g. `['cd', 'fr']` resolves seamlessly to `CD FR`). Length constraints ensure any invalid string length drops a granular error to block indexing corruption beforehand.
|
|
286
|
+
|
|
287
|
+
- **Screen Class Verification**: Platform listings undergo structural array verification to filter out illegal user strings. Only official Google target tokens (`web`, `mobile`, `tv`) are compiled into space-separated string structures.
|
|
288
|
+
|
|
289
|
+
### Strict Video Statistical Enforcement (v1.1.3)
|
|
290
|
+
Google's ingestion schema specifies rigid rules for video engagement parameters. Providing decimals or numbers outside structural limits can invalidate the entire sitemap file inside the Google Search Console.
|
|
291
|
+
|
|
292
|
+
- **Range Locking**: The generator enforces that any provided `duration` fits within a strict `0` to `28,800` seconds bracket (up to 8 hours). Breaking this threshold or inputting negative values immediately throws an descriptive runtime exception.
|
|
293
|
+
|
|
294
|
+
- **Decimal Truncation**: Both `duration` and `view_count` properties undergo automated conversion into integers using deterministic mathematical grounding (`Math.floor`). This allows systems to relay float-heavy numbers straight from analytics stores safely.
|
|
295
|
+
|
|
173
296
|
### Image Accessibility & E-commerce Protection
|
|
174
297
|
Large e-commerce platform backends or multi-vendor platforms frequently inject messy string data from user-generated fields—such as alternative text filled with raw spaces (`" "`) or unescaped description metadata containing special HTML entities (`&`, `<`, `>`). To achieve strict alignment with Googlebot accessibility schemas without risking layout parsing crashes, the engine implements a two-tier architectural protective filter in **v1.1.2**:
|
|
175
298
|
|
package/dist/index.cjs
CHANGED
|
@@ -179,15 +179,64 @@ function generateXml(entries, options = {}) {
|
|
|
179
179
|
`;
|
|
180
180
|
}
|
|
181
181
|
if (vid.duration !== void 0) {
|
|
182
|
-
|
|
182
|
+
const finalDuration = Math.floor(vid.duration);
|
|
183
|
+
if (finalDuration < 0 || finalDuration > 28800) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
`[next-advanced-sitemap] Invalid video duration: ${finalDuration}. Duration must be an integer between 0 and 28800 seconds (8 hours).`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
xml += ` <video:duration>${finalDuration}</video:duration>
|
|
183
189
|
`;
|
|
184
190
|
}
|
|
185
191
|
if (vid.view_count !== void 0) {
|
|
186
|
-
|
|
192
|
+
const finalViewCount = Math.floor(vid.view_count);
|
|
193
|
+
if (finalViewCount < 0) {
|
|
194
|
+
throw new Error(
|
|
195
|
+
`[next-advanced-sitemap] Invalid video view_count: ${finalViewCount}. View count cannot be negative.`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
xml += ` <video:view_count>${finalViewCount}</video:view_count>
|
|
187
199
|
`;
|
|
188
200
|
}
|
|
189
201
|
if (vid.live) {
|
|
190
202
|
xml += ` <video:live>${vid.live}</video:live>
|
|
203
|
+
`;
|
|
204
|
+
}
|
|
205
|
+
if (vid.restriction) {
|
|
206
|
+
if (!vid.restriction.countries || vid.restriction.countries.length === 0) {
|
|
207
|
+
throw new Error(
|
|
208
|
+
`[next-advanced-sitemap] Invalid video restriction: countries array cannot be empty.`
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
const cleanCountries = vid.restriction.countries.map((country) => {
|
|
212
|
+
const code = country.trim().toUpperCase();
|
|
213
|
+
if (code.length < 2 || code.length > 3) {
|
|
214
|
+
throw new Error(
|
|
215
|
+
`[next-advanced-sitemap] Invalid ISO country code detected: "${country}". Must be a valid ISO 3166 code.`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
return code;
|
|
219
|
+
});
|
|
220
|
+
const countriesStr = cleanCountries.join(" ");
|
|
221
|
+
xml += ` <video:restriction relationship="${vid.restriction.relationship}">${countriesStr}</video:restriction>
|
|
222
|
+
`;
|
|
223
|
+
}
|
|
224
|
+
if (vid.platform) {
|
|
225
|
+
if (!vid.platform.platforms || vid.platform.platforms.length === 0) {
|
|
226
|
+
throw new Error(
|
|
227
|
+
`[next-advanced-sitemap] Invalid video platform: platforms array cannot be empty.`
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
const validPlatforms = ["web", "mobile", "tv"];
|
|
231
|
+
for (const p of vid.platform.platforms) {
|
|
232
|
+
if (!validPlatforms.includes(p)) {
|
|
233
|
+
throw new Error(
|
|
234
|
+
`[next-advanced-sitemap] Invalid platform type: "${p}". Allowed values are 'web', 'mobile', or 'tv'.`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const platformsStr = vid.platform.platforms.join(" ");
|
|
239
|
+
xml += ` <video:platform relationship="${vid.platform.relationship}">${platformsStr}</video:platform>
|
|
191
240
|
`;
|
|
192
241
|
}
|
|
193
242
|
xml += ` </video:video>
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils/xml-escape.ts","../src/core/generator.ts"],"sourcesContent":["/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from './types/sitemap.js';\nimport { generateXml } from './core/generator.js';\n\nexport * from './types/sitemap.js';\n\n/**\n * Génère une réponse HTTP compatible Next.js (App Router) avec options de configuration.\n * v1.0.9 : Injection dynamique et personnalisable de l'en-tête Cache-Control via l'option maxAge\n * * @param entries - Liste des entrées du sitemap\n * @param options - Options de génération et de mise en cache (ex: autoLastmod, maxAge)\n * @returns Une instance de Response contenant le flux XML configuré\n */\nexport function getServerSitemapResponse(\n entries: SitemapEntry[], \n options: SitemapOptions = {}\n): Response {\n const xml = generateXml(entries, options);\n\n // Détermination de la stratégie de mise en cache (v1.0.9)\n const cacheControlHeader = options.maxAge !== undefined\n ? `public, max-age=${options.maxAge}, must-revalidate`\n : 'public, s-maxage=86400, stale-while-revalidate';\n\n return new Response(xml, {\n headers: {\n 'Content-Type': 'application/xml',\n 'Cache-Control': cacheControlHeader,\n },\n });\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\n/**\n * Convertit les caractères spéciaux en entités XML pour éviter la corruption du fichier.\n * Gère : <, >, &, \", '\n */\nexport function escapeXml(unsafe: string | undefined | null): string {\n if (!unsafe) return '';\n \n return unsafe.replace(/[<>&\"']/g, (c) => {\n switch (c) {\n case '<': return '<';\n case '>': return '>';\n case '&': return '&';\n case '\"': return '"';\n case \"'\": return ''';\n default: return c;\n }\n });\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from '../types/sitemap.js';\nimport { escapeXml } from '../utils/xml-escape.js';\n\n/**\n * Nettoie et valide de manière stricte le format et la structure d'une URL.\n * v1.0.7 : Intégration de l'Auto-Trimming (nettoyage des espaces de début et de fin)\n */\nfunction sanitizeAndValidateUrl(rawUrl: string, context: string): string {\n const url = rawUrl ? rawUrl.trim() : '';\n\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\n throw new Error(\n `[next-advanced-sitemap] Invalid URL in ${context}: \"${url}\". URLs must start with http:// or https://`\n );\n }\n\n if (url.includes(' ')) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n let isValid = false;\n if (typeof URL.canParse === 'function') {\n isValid = URL.canParse(url);\n } else {\n try {\n new URL(url);\n isValid = true;\n } catch {\n isValid = false;\n }\n }\n\n if (!isValid) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n return url;\n}\n\n/**\n * Génère le flux XML complet du sitemap incluant les extensions Images, Vidéos, News et Hreflang.\n * v1.1.2 : Métadonnées d'Accessibilité Images (caption & title optionnels, renforcés et nettoyés)\n * + Support sécurisé des statistiques vidéo (duration & view_count)\n */\nexport function generateXml(entries: SitemapEntry[], options: SitemapOptions = {}): string {\n const now = new Date().toISOString();\n let finalEntries = [...entries];\n\n if (options.sortByPriority) {\n finalEntries.sort((a, b) => {\n const priorityA = a.priority !== undefined ? (a.priority as number) : 0.5;\n const priorityB = b.priority !== undefined ? (b.priority as number) : 0.5;\n return priorityB - priorityA;\n });\n }\n \n let xml = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n`;\n xml += `<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\\n`;\n xml += ` xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"\\n`;\n xml += ` xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\"\\n`;\n xml += ` xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\"\\n`;\n xml += ` xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\\n`;\n\n for (const entry of finalEntries) {\n const cleanMainUrl = sanitizeAndValidateUrl(entry.url, 'main entry');\n\n xml += ` <url>\\n`;\n xml += ` <loc>${escapeXml(cleanMainUrl)}</loc>\\n`;\n\n if (entry.alternates?.length) {\n for (const alt of entry.alternates) {\n const cleanAltUrl = sanitizeAndValidateUrl(alt.href, 'alternate link');\n xml += ` <xhtml:link rel=\"alternate\" hreflang=\"${escapeXml(alt.hreflang)}\" href=\"${escapeXml(cleanAltUrl)}\" />\\n`;\n }\n }\n\n let lastmodValue = entry.lastmod;\n if (options.autoLastmod && !lastmodValue) {\n lastmodValue = now;\n }\n\n if (lastmodValue) {\n const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;\n xml += ` <lastmod>${date}</lastmod>\\n`;\n }\n\n if (entry.changefreq) {\n xml += ` <changefreq>${entry.changefreq}</changefreq>\\n`;\n }\n\n if (entry.priority !== undefined) {\n xml += ` <priority>${(entry.priority as number).toFixed(1)}</priority>\\n`;\n }\n\n // Extension Images - v1.1.2 renforcée\n if (entry.images?.length) {\n for (const img of entry.images) {\n const cleanImgUrl = sanitizeAndValidateUrl(img.loc, 'image location');\n \n xml += ` <image:image>\\n`;\n xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>\\n`;\n \n // ✨ v1.1.2 : .trim() préventif pour s'assurer qu'un texte blanc ne crée pas de balise invalide\n if (img.title && img.title.trim() !== '') {\n xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>\\n`;\n }\n if (img.caption && img.caption.trim() !== '') {\n xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>\\n`;\n }\n \n // SEO Local\n if (img.geo_location && img.geo_location.trim() !== '') {\n xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>\\n`;\n }\n \n // Gestion des Licences Google Images\n if (img.license) {\n const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, 'image license URL');\n xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>\\n`;\n }\n \n xml += ` </image:image>\\n`;\n }\n }\n\n // Extension Vidéos\n if (entry.videos?.length) {\n for (const vid of entry.videos) {\n const cleanThumbLoc = sanitizeAndValidateUrl(vid.thumbnail_loc, 'video thumbnail');\n const cleanContentLoc = vid.content_loc ? sanitizeAndValidateUrl(vid.content_loc, 'video content location') : undefined;\n const cleanPlayerLoc = vid.player_loc ? sanitizeAndValidateUrl(vid.player_loc, 'video player location') : undefined;\n\n xml += ` <video:video>\\n`;\n xml += ` <video:thumbnail_loc>${escapeXml(cleanThumbLoc)}</video:thumbnail_loc>\\n`;\n xml += ` <video:title>${escapeXml(vid.title)}</video:title>\\n`;\n xml += ` <video:description>${escapeXml(vid.description)}</video:description>\\n`;\n \n if (cleanContentLoc) xml += ` <video:content_loc>${escapeXml(cleanContentLoc)}</video:content_loc>\\n`;\n if (cleanPlayerLoc) xml += ` <video:player_loc>${escapeXml(cleanPlayerLoc)}</video:player_loc>\\n`;\n \n if (vid.publication_date) {\n const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;\n xml += ` <video:publication_date>${vDate}</video:publication_date>\\n`;\n }\n\n // Métadonnées de statistiques (v1.1.3 - Préparé et sécurisé)\n if (vid.duration !== undefined) {\n xml += ` <video:duration>${Math.floor(vid.duration)}</video:duration>\\n`;\n }\n if (vid.view_count !== undefined) {\n xml += ` <video:view_count>${Math.floor(vid.view_count)}</video:view_count>\\n`;\n }\n\n // Support du Live Streaming v1.1.1\n if (vid.live) {\n xml += ` <video:live>${vid.live}</video:live>\\n`;\n }\n\n xml += ` </video:video>\\n`;\n }\n }\n\n // Extension News\n if (entry.news) {\n const nDate = entry.news.publication_date instanceof Date ? entry.news.publication_date.toISOString() : entry.news.publication_date;\n xml += ` <news:news>\\n`;\n xml += ` <news:publication>\\n`;\n xml += ` <news:name>${escapeXml(entry.news.name)}</news:name>\\n`;\n xml += ` <news:language>${escapeXml(entry.news.language)}</news:language>\\n`;\n xml += ` </news:publication>\\n`;\n xml += ` <news:publication_date>${nDate}</news:publication_date>\\n`;\n xml += ` <news:title>${escapeXml(entry.news.title)}</news:title>\\n`;\n xml += ` </news:news>\\n`;\n }\n\n xml += ` </url>\\n`;\n }\n\n xml += `</urlset>`;\n return xml;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,SAAS,UAAU,QAA2C;AACnE,MAAI,CAAC,OAAQ,QAAO;AAEpB,SAAO,OAAO,QAAQ,YAAY,CAAC,MAAM;AACvC,YAAQ,GAAG;AAAA,MACT,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,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;AAAA,MACT;AAAA,IACF;AAGA,QAAI,MAAM,MAAM;AACd,YAAM,QAAQ,MAAM,KAAK,4BAA4B,OAAO,MAAM,KAAK,iBAAiB,YAAY,IAAI,MAAM,KAAK;AACnH,aAAO;AAAA;AACP,aAAO;AAAA;AACP,aAAO,sBAAsB,UAAU,MAAM,KAAK,IAAI,CAAC;AAAA;AACvD,aAAO,0BAA0B,UAAU,MAAM,KAAK,QAAQ,CAAC;AAAA;AAC/D,aAAO;AAAA;AACP,aAAO,gCAAgC,KAAK;AAAA;AAC5C,aAAO,qBAAqB,UAAU,MAAM,KAAK,KAAK,CAAC;AAAA;AACvD,aAAO;AAAA;AAAA,IACT;AAEA,WAAO;AAAA;AAAA,EACT;AAEA,SAAO;AACP,SAAO;AACT;;;AF5KO,SAAS,yBACd,SACA,UAA0B,CAAC,GACjB;AACV,QAAM,MAAM,YAAY,SAAS,OAAO;AAGxC,QAAM,qBAAqB,QAAQ,WAAW,SAC1C,mBAAmB,QAAQ,MAAM,sBACjC;AAEJ,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils/xml-escape.ts","../src/core/generator.ts"],"sourcesContent":["/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from './types/sitemap.js';\nimport { generateXml } from './core/generator.js';\n\nexport * from './types/sitemap.js';\n\n/**\n * Génère une réponse HTTP compatible Next.js (App Router) avec options de configuration.\n * v1.0.9 : Injection dynamique et personnalisable de l'en-tête Cache-Control via l'option maxAge\n * * @param entries - Liste des entrées du sitemap\n * @param options - Options de génération et de mise en cache (ex: autoLastmod, maxAge)\n * @returns Une instance de Response contenant le flux XML configuré\n */\nexport function getServerSitemapResponse(\n entries: SitemapEntry[], \n options: SitemapOptions = {}\n): Response {\n const xml = generateXml(entries, options);\n\n // Détermination de la stratégie de mise en cache (v1.0.9)\n const cacheControlHeader = options.maxAge !== undefined\n ? `public, max-age=${options.maxAge}, must-revalidate`\n : 'public, s-maxage=86400, stale-while-revalidate';\n\n return new Response(xml, {\n headers: {\n 'Content-Type': 'application/xml',\n 'Cache-Control': cacheControlHeader,\n },\n });\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\n/**\n * Convertit les caractères spéciaux en entités XML pour éviter la corruption du fichier.\n * Gère : <, >, &, \", '\n */\nexport function escapeXml(unsafe: string | undefined | null): string {\n if (!unsafe) return '';\n \n return unsafe.replace(/[<>&\"']/g, (c) => {\n switch (c) {\n case '<': return '<';\n case '>': return '>';\n case '&': return '&';\n case '\"': return '"';\n case \"'\": return ''';\n default: return c;\n }\n });\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from '../types/sitemap.js';\nimport { escapeXml } from '../utils/xml-escape.js';\n\n/**\n * Nettoie et valide de manière stricte le format et la structure d'une URL.\n * v1.0.7 : Intégration de l'Auto-Trimming (nettoyage des espaces de début et de fin)\n */\nfunction sanitizeAndValidateUrl(rawUrl: string, context: string): string {\n const url = rawUrl ? rawUrl.trim() : '';\n\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\n throw new Error(\n `[next-advanced-sitemap] Invalid URL in ${context}: \"${url}\". URLs must start with http:// or https://`\n );\n }\n\n if (url.includes(' ')) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n let isValid = false;\n if (typeof URL.canParse === 'function') {\n isValid = URL.canParse(url);\n } else {\n try {\n new URL(url);\n isValid = true;\n } catch {\n isValid = false;\n }\n }\n\n if (!isValid) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n return url;\n}\n\n/**\n * Génère le flux XML complet du sitemap incluant les extensions Images, Vidéos, News et Hreflang.\n * v1.1.4 : Prise en charge et validation stricte des restrictions pays (ISO 3166) et plateformes (web, mobile, tv)\n */\nexport function generateXml(entries: SitemapEntry[], options: SitemapOptions = {}): string {\n const now = new Date().toISOString();\n let finalEntries = [...entries];\n\n if (options.sortByPriority) {\n finalEntries.sort((a, b) => {\n const priorityA = a.priority !== undefined ? (a.priority as number) : 0.5;\n const priorityB = b.priority !== undefined ? (b.priority as number) : 0.5;\n return priorityB - priorityA;\n });\n }\n \n let xml = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n`;\n xml += `<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\\n`;\n xml += ` xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"\\n`;\n xml += ` xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\"\\n`;\n xml += ` xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\"\\n`;\n xml += ` xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\\n`;\n\n for (const entry of finalEntries) {\n const cleanMainUrl = sanitizeAndValidateUrl(entry.url, 'main entry');\n\n xml += ` <url>\\n`;\n xml += ` <loc>${escapeXml(cleanMainUrl)}</loc>\\n`;\n\n if (entry.alternates?.length) {\n for (const alt of entry.alternates) {\n const cleanAltUrl = sanitizeAndValidateUrl(alt.href, 'alternate link');\n xml += ` <xhtml:link rel=\"alternate\" hreflang=\"${escapeXml(alt.hreflang)}\" href=\"${escapeXml(cleanAltUrl)}\" />\\n`;\n }\n }\n\n let lastmodValue = entry.lastmod;\n if (options.autoLastmod && !lastmodValue) {\n lastmodValue = now;\n }\n\n if (lastmodValue) {\n const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;\n xml += ` <lastmod>${date}</lastmod>\\n`;\n }\n\n if (entry.changefreq) {\n xml += ` <changefreq>${entry.changefreq}</changefreq>\\n`;\n }\n\n if (entry.priority !== undefined) {\n xml += ` <priority>${(entry.priority as number).toFixed(1)}</priority>\\n`;\n }\n\n // Extension Images\n if (entry.images?.length) {\n for (const img of entry.images) {\n const cleanImgUrl = sanitizeAndValidateUrl(img.loc, 'image location');\n \n xml += ` <image:image>\\n`;\n xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>\\n`;\n \n if (img.title && img.title.trim() !== '') {\n xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>\\n`;\n }\n if (img.caption && img.caption.trim() !== '') {\n xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>\\n`;\n }\n \n if (img.geo_location && img.geo_location.trim() !== '') {\n xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>\\n`;\n }\n \n if (img.license) {\n const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, 'image license URL');\n xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>\\n`;\n }\n \n xml += ` </image:image>\\n`;\n }\n }\n\n // Extension Vidéos\n if (entry.videos?.length) {\n for (const vid of entry.videos) {\n const cleanThumbLoc = sanitizeAndValidateUrl(vid.thumbnail_loc, 'video thumbnail');\n const cleanContentLoc = vid.content_loc ? sanitizeAndValidateUrl(vid.content_loc, 'video content location') : undefined;\n const cleanPlayerLoc = vid.player_loc ? sanitizeAndValidateUrl(vid.player_loc, 'video player location') : undefined;\n\n xml += ` <video:video>\\n`;\n xml += ` <video:thumbnail_loc>${escapeXml(cleanThumbLoc)}</video:thumbnail_loc>\\n`;\n xml += ` <video:title>${escapeXml(vid.title)}</video:title>\\n`;\n xml += ` <video:description>${escapeXml(vid.description)}</video:description>\\n`;\n \n if (cleanContentLoc) xml += ` <video:content_loc>${escapeXml(cleanContentLoc)}</video:content_loc>\\n`;\n if (cleanPlayerLoc) xml += ` <video:player_loc>${escapeXml(cleanPlayerLoc)}</video:player_loc>\\n`;\n \n if (vid.publication_date) {\n const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;\n xml += ` <video:publication_date>${vDate}</video:publication_date>\\n`;\n }\n\n if (vid.duration !== undefined) {\n const finalDuration = Math.floor(vid.duration);\n if (finalDuration < 0 || finalDuration > 28800) {\n throw new Error(\n `[next-advanced-sitemap] Invalid video duration: ${finalDuration}. Duration must be an integer between 0 and 28800 seconds (8 hours).`\n );\n }\n xml += ` <video:duration>${finalDuration}</video:duration>\\n`;\n }\n\n if (vid.view_count !== undefined) {\n const finalViewCount = Math.floor(vid.view_count);\n if (finalViewCount < 0) {\n throw new Error(\n `[next-advanced-sitemap] Invalid video view_count: ${finalViewCount}. View count cannot be negative.`\n );\n }\n xml += ` <video:view_count>${finalViewCount}</video:view_count>\\n`;\n }\n\n if (vid.live) {\n xml += ` <video:live>${vid.live}</video:live>\\n`;\n }\n\n // ✨ Validation et Sérialisation des Restrictions Pays (v1.1.4)\n if (vid.restriction) {\n if (!vid.restriction.countries || vid.restriction.countries.length === 0) {\n throw new Error(\n `[next-advanced-sitemap] Invalid video restriction: countries array cannot be empty.`\n );\n }\n\n const cleanCountries = vid.restriction.countries.map(country => {\n const code = country.trim().toUpperCase();\n if (code.length < 2 || code.length > 3) {\n throw new Error(\n `[next-advanced-sitemap] Invalid ISO country code detected: \"${country}\". Must be a valid ISO 3166 code.`\n );\n }\n return code;\n });\n\n const countriesStr = cleanCountries.join(' ');\n xml += ` <video:restriction relationship=\"${vid.restriction.relationship}\">${countriesStr}</video:restriction>\\n`;\n }\n\n // ✨ Validation et Sérialisation des Plateformes (v1.1.4)\n if (vid.platform) {\n if (!vid.platform.platforms || vid.platform.platforms.length === 0) {\n throw new Error(\n `[next-advanced-sitemap] Invalid video platform: platforms array cannot be empty.`\n );\n }\n\n const validPlatforms = ['web', 'mobile', 'tv'];\n for (const p of vid.platform.platforms) {\n if (!validPlatforms.includes(p)) {\n throw new Error(\n `[next-advanced-sitemap] Invalid platform type: \"${p}\". Allowed values are 'web', 'mobile', or 'tv'.`\n );\n }\n }\n\n const platformsStr = vid.platform.platforms.join(' ');\n xml += ` <video:platform relationship=\"${vid.platform.relationship}\">${platformsStr}</video:platform>\\n`;\n }\n\n xml += ` </video:video>\\n`;\n }\n }\n\n // Extension News\n if (entry.news) {\n const nDate = entry.news.publication_date instanceof Date ? entry.news.publication_date.toISOString() : entry.news.publication_date;\n xml += ` <news:news>\\n`;\n xml += ` <news:publication>\\n`;\n xml += ` <news:name>${escapeXml(entry.news.name)}</news:name>\\n`;\n xml += ` <news:language>${escapeXml(entry.news.language)}</news:language>\\n`;\n xml += ` </news:publication>\\n`;\n xml += ` <news:publication_date>${nDate}</news:publication_date>\\n`;\n xml += ` <news:title>${escapeXml(entry.news.title)}</news:title>\\n`;\n xml += ` </news:news>\\n`;\n }\n\n xml += ` </url>\\n`;\n }\n\n xml += `</urlset>`;\n return xml;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,SAAS,UAAU,QAA2C;AACnE,MAAI,CAAC,OAAQ,QAAO;AAEpB,SAAO,OAAO,QAAQ,YAAY,CAAC,MAAM;AACvC,YAAQ,GAAG;AAAA,MACT,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB;AAAS,eAAO;AAAA,IAClB;AAAA,EACF,CAAC;AACH;;;ACVA,SAAS,uBAAuB,QAAgB,SAAyB;AACvE,QAAM,MAAM,SAAS,OAAO,KAAK,IAAI;AAErC,MAAI,CAAC,IAAI,WAAW,SAAS,KAAK,CAAC,IAAI,WAAW,UAAU,GAAG;AAC7D,UAAM,IAAI;AAAA,MACR,0CAA0C,OAAO,MAAM,GAAG;AAAA,IAC5D;AAAA,EACF;AAEA,MAAI,IAAI,SAAS,GAAG,GAA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A,WAAO;AAAA;AAAA,EACT;AAEA,SAAO;AACP,SAAO;AACT;;;AF9NO,SAAS,yBACd,SACA,UAA0B,CAAC,GACjB;AACV,QAAM,MAAM,YAAY,SAAS,OAAO;AAGxC,QAAM,qBAAqB,QAAQ,WAAW,SAC1C,mBAAmB,QAAQ,MAAM,sBACjC;AAEJ,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -29,6 +29,22 @@ interface SitemapImage {
|
|
|
29
29
|
/** (Optional) v1.1.0: URL pointant vers les conditions d'utilisation ou le contrat de licence de l'image. */
|
|
30
30
|
license?: string;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Interface pour les restrictions géographiques des vidéos (v1.1.4)
|
|
34
|
+
*/
|
|
35
|
+
interface VideoRestriction {
|
|
36
|
+
relationship: 'allow' | 'deny';
|
|
37
|
+
/** Tableau de codes pays ISO 3166-1 alpha-2 (ex: ['FR', 'US', 'CA']) */
|
|
38
|
+
countries: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Interface pour les restrictions de plateformes des vidéos (v1.1.4)
|
|
42
|
+
*/
|
|
43
|
+
interface VideoPlatform {
|
|
44
|
+
relationship: 'allow' | 'deny';
|
|
45
|
+
/** Tableau de plateformes autorisées ou interdites */
|
|
46
|
+
platforms: ('web' | 'mobile' | 'tv')[];
|
|
47
|
+
}
|
|
32
48
|
/**
|
|
33
49
|
* Interface pour les vidéos dans le sitemap
|
|
34
50
|
* @see https://developers.google.com/search/docs/crawling-indexing/sitemaps/video-sitemaps
|
|
@@ -39,12 +55,18 @@ interface SitemapVideo {
|
|
|
39
55
|
description: string;
|
|
40
56
|
content_loc?: string;
|
|
41
57
|
player_loc?: string;
|
|
42
|
-
duration?: number;
|
|
43
|
-
view_count?: number;
|
|
44
58
|
publication_date?: Date | string;
|
|
45
59
|
family_friendly?: 'yes' | 'no';
|
|
46
60
|
/** (Optional) v1.1.1: Indique si la vidéo est une diffusion en direct ('yes' ou 'no'). */
|
|
47
61
|
live?: 'yes' | 'no';
|
|
62
|
+
/** (Optional) v1.1.3: La durée de la vidéo en secondes. */
|
|
63
|
+
duration?: number;
|
|
64
|
+
/** (Optional) v1.1.3: Le nombre de vues de la vidéo. */
|
|
65
|
+
view_count?: number;
|
|
66
|
+
/** (Optional) v1.1.4: Restriction géographique de diffusion (ISO 3166-1 alpha-2). */
|
|
67
|
+
restriction?: VideoRestriction;
|
|
68
|
+
/** (Optional) v1.1.4: Restriction selon le type d'appareil / plateforme. */
|
|
69
|
+
platform?: VideoPlatform;
|
|
48
70
|
}
|
|
49
71
|
/**
|
|
50
72
|
* Interface pour Google News
|
|
@@ -101,4 +123,4 @@ interface SitemapOptions {
|
|
|
101
123
|
*/
|
|
102
124
|
declare function getServerSitemapResponse(entries: SitemapEntry[], options?: SitemapOptions): Response;
|
|
103
125
|
|
|
104
|
-
export { type SitemapAlternate, type SitemapChangeFreq, type SitemapEntry, type SitemapImage, type SitemapNews, type SitemapOptions, type SitemapPriority, type SitemapVideo, getServerSitemapResponse };
|
|
126
|
+
export { type SitemapAlternate, type SitemapChangeFreq, type SitemapEntry, type SitemapImage, type SitemapNews, type SitemapOptions, type SitemapPriority, type SitemapVideo, type VideoPlatform, type VideoRestriction, getServerSitemapResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,22 @@ interface SitemapImage {
|
|
|
29
29
|
/** (Optional) v1.1.0: URL pointant vers les conditions d'utilisation ou le contrat de licence de l'image. */
|
|
30
30
|
license?: string;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Interface pour les restrictions géographiques des vidéos (v1.1.4)
|
|
34
|
+
*/
|
|
35
|
+
interface VideoRestriction {
|
|
36
|
+
relationship: 'allow' | 'deny';
|
|
37
|
+
/** Tableau de codes pays ISO 3166-1 alpha-2 (ex: ['FR', 'US', 'CA']) */
|
|
38
|
+
countries: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Interface pour les restrictions de plateformes des vidéos (v1.1.4)
|
|
42
|
+
*/
|
|
43
|
+
interface VideoPlatform {
|
|
44
|
+
relationship: 'allow' | 'deny';
|
|
45
|
+
/** Tableau de plateformes autorisées ou interdites */
|
|
46
|
+
platforms: ('web' | 'mobile' | 'tv')[];
|
|
47
|
+
}
|
|
32
48
|
/**
|
|
33
49
|
* Interface pour les vidéos dans le sitemap
|
|
34
50
|
* @see https://developers.google.com/search/docs/crawling-indexing/sitemaps/video-sitemaps
|
|
@@ -39,12 +55,18 @@ interface SitemapVideo {
|
|
|
39
55
|
description: string;
|
|
40
56
|
content_loc?: string;
|
|
41
57
|
player_loc?: string;
|
|
42
|
-
duration?: number;
|
|
43
|
-
view_count?: number;
|
|
44
58
|
publication_date?: Date | string;
|
|
45
59
|
family_friendly?: 'yes' | 'no';
|
|
46
60
|
/** (Optional) v1.1.1: Indique si la vidéo est une diffusion en direct ('yes' ou 'no'). */
|
|
47
61
|
live?: 'yes' | 'no';
|
|
62
|
+
/** (Optional) v1.1.3: La durée de la vidéo en secondes. */
|
|
63
|
+
duration?: number;
|
|
64
|
+
/** (Optional) v1.1.3: Le nombre de vues de la vidéo. */
|
|
65
|
+
view_count?: number;
|
|
66
|
+
/** (Optional) v1.1.4: Restriction géographique de diffusion (ISO 3166-1 alpha-2). */
|
|
67
|
+
restriction?: VideoRestriction;
|
|
68
|
+
/** (Optional) v1.1.4: Restriction selon le type d'appareil / plateforme. */
|
|
69
|
+
platform?: VideoPlatform;
|
|
48
70
|
}
|
|
49
71
|
/**
|
|
50
72
|
* Interface pour Google News
|
|
@@ -101,4 +123,4 @@ interface SitemapOptions {
|
|
|
101
123
|
*/
|
|
102
124
|
declare function getServerSitemapResponse(entries: SitemapEntry[], options?: SitemapOptions): Response;
|
|
103
125
|
|
|
104
|
-
export { type SitemapAlternate, type SitemapChangeFreq, type SitemapEntry, type SitemapImage, type SitemapNews, type SitemapOptions, type SitemapPriority, type SitemapVideo, getServerSitemapResponse };
|
|
126
|
+
export { type SitemapAlternate, type SitemapChangeFreq, type SitemapEntry, type SitemapImage, type SitemapNews, type SitemapOptions, type SitemapPriority, type SitemapVideo, type VideoPlatform, type VideoRestriction, getServerSitemapResponse };
|
package/dist/index.js
CHANGED
|
@@ -153,15 +153,64 @@ function generateXml(entries, options = {}) {
|
|
|
153
153
|
`;
|
|
154
154
|
}
|
|
155
155
|
if (vid.duration !== void 0) {
|
|
156
|
-
|
|
156
|
+
const finalDuration = Math.floor(vid.duration);
|
|
157
|
+
if (finalDuration < 0 || finalDuration > 28800) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`[next-advanced-sitemap] Invalid video duration: ${finalDuration}. Duration must be an integer between 0 and 28800 seconds (8 hours).`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
xml += ` <video:duration>${finalDuration}</video:duration>
|
|
157
163
|
`;
|
|
158
164
|
}
|
|
159
165
|
if (vid.view_count !== void 0) {
|
|
160
|
-
|
|
166
|
+
const finalViewCount = Math.floor(vid.view_count);
|
|
167
|
+
if (finalViewCount < 0) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`[next-advanced-sitemap] Invalid video view_count: ${finalViewCount}. View count cannot be negative.`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
xml += ` <video:view_count>${finalViewCount}</video:view_count>
|
|
161
173
|
`;
|
|
162
174
|
}
|
|
163
175
|
if (vid.live) {
|
|
164
176
|
xml += ` <video:live>${vid.live}</video:live>
|
|
177
|
+
`;
|
|
178
|
+
}
|
|
179
|
+
if (vid.restriction) {
|
|
180
|
+
if (!vid.restriction.countries || vid.restriction.countries.length === 0) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
`[next-advanced-sitemap] Invalid video restriction: countries array cannot be empty.`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const cleanCountries = vid.restriction.countries.map((country) => {
|
|
186
|
+
const code = country.trim().toUpperCase();
|
|
187
|
+
if (code.length < 2 || code.length > 3) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`[next-advanced-sitemap] Invalid ISO country code detected: "${country}". Must be a valid ISO 3166 code.`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return code;
|
|
193
|
+
});
|
|
194
|
+
const countriesStr = cleanCountries.join(" ");
|
|
195
|
+
xml += ` <video:restriction relationship="${vid.restriction.relationship}">${countriesStr}</video:restriction>
|
|
196
|
+
`;
|
|
197
|
+
}
|
|
198
|
+
if (vid.platform) {
|
|
199
|
+
if (!vid.platform.platforms || vid.platform.platforms.length === 0) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
`[next-advanced-sitemap] Invalid video platform: platforms array cannot be empty.`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
const validPlatforms = ["web", "mobile", "tv"];
|
|
205
|
+
for (const p of vid.platform.platforms) {
|
|
206
|
+
if (!validPlatforms.includes(p)) {
|
|
207
|
+
throw new Error(
|
|
208
|
+
`[next-advanced-sitemap] Invalid platform type: "${p}". Allowed values are 'web', 'mobile', or 'tv'.`
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const platformsStr = vid.platform.platforms.join(" ");
|
|
213
|
+
xml += ` <video:platform relationship="${vid.platform.relationship}">${platformsStr}</video:platform>
|
|
165
214
|
`;
|
|
166
215
|
}
|
|
167
216
|
xml += ` </video:video>
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/xml-escape.ts","../src/core/generator.ts","../src/index.ts"],"sourcesContent":["/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\n/**\n * Convertit les caractères spéciaux en entités XML pour éviter la corruption du fichier.\n * Gère : <, >, &, \", '\n */\nexport function escapeXml(unsafe: string | undefined | null): string {\n if (!unsafe) return '';\n \n return unsafe.replace(/[<>&\"']/g, (c) => {\n switch (c) {\n case '<': return '<';\n case '>': return '>';\n case '&': return '&';\n case '\"': return '"';\n case \"'\": return ''';\n default: return c;\n }\n });\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from '../types/sitemap.js';\nimport { escapeXml } from '../utils/xml-escape.js';\n\n/**\n * Nettoie et valide de manière stricte le format et la structure d'une URL.\n * v1.0.7 : Intégration de l'Auto-Trimming (nettoyage des espaces de début et de fin)\n */\nfunction sanitizeAndValidateUrl(rawUrl: string, context: string): string {\n const url = rawUrl ? rawUrl.trim() : '';\n\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\n throw new Error(\n `[next-advanced-sitemap] Invalid URL in ${context}: \"${url}\". URLs must start with http:// or https://`\n );\n }\n\n if (url.includes(' ')) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n let isValid = false;\n if (typeof URL.canParse === 'function') {\n isValid = URL.canParse(url);\n } else {\n try {\n new URL(url);\n isValid = true;\n } catch {\n isValid = false;\n }\n }\n\n if (!isValid) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n return url;\n}\n\n/**\n * Génère le flux XML complet du sitemap incluant les extensions Images, Vidéos, News et Hreflang.\n * v1.1.2 : Métadonnées d'Accessibilité Images (caption & title optionnels, renforcés et nettoyés)\n * + Support sécurisé des statistiques vidéo (duration & view_count)\n */\nexport function generateXml(entries: SitemapEntry[], options: SitemapOptions = {}): string {\n const now = new Date().toISOString();\n let finalEntries = [...entries];\n\n if (options.sortByPriority) {\n finalEntries.sort((a, b) => {\n const priorityA = a.priority !== undefined ? (a.priority as number) : 0.5;\n const priorityB = b.priority !== undefined ? (b.priority as number) : 0.5;\n return priorityB - priorityA;\n });\n }\n \n let xml = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n`;\n xml += `<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\\n`;\n xml += ` xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"\\n`;\n xml += ` xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\"\\n`;\n xml += ` xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\"\\n`;\n xml += ` xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\\n`;\n\n for (const entry of finalEntries) {\n const cleanMainUrl = sanitizeAndValidateUrl(entry.url, 'main entry');\n\n xml += ` <url>\\n`;\n xml += ` <loc>${escapeXml(cleanMainUrl)}</loc>\\n`;\n\n if (entry.alternates?.length) {\n for (const alt of entry.alternates) {\n const cleanAltUrl = sanitizeAndValidateUrl(alt.href, 'alternate link');\n xml += ` <xhtml:link rel=\"alternate\" hreflang=\"${escapeXml(alt.hreflang)}\" href=\"${escapeXml(cleanAltUrl)}\" />\\n`;\n }\n }\n\n let lastmodValue = entry.lastmod;\n if (options.autoLastmod && !lastmodValue) {\n lastmodValue = now;\n }\n\n if (lastmodValue) {\n const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;\n xml += ` <lastmod>${date}</lastmod>\\n`;\n }\n\n if (entry.changefreq) {\n xml += ` <changefreq>${entry.changefreq}</changefreq>\\n`;\n }\n\n if (entry.priority !== undefined) {\n xml += ` <priority>${(entry.priority as number).toFixed(1)}</priority>\\n`;\n }\n\n // Extension Images - v1.1.2 renforcée\n if (entry.images?.length) {\n for (const img of entry.images) {\n const cleanImgUrl = sanitizeAndValidateUrl(img.loc, 'image location');\n \n xml += ` <image:image>\\n`;\n xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>\\n`;\n \n // ✨ v1.1.2 : .trim() préventif pour s'assurer qu'un texte blanc ne crée pas de balise invalide\n if (img.title && img.title.trim() !== '') {\n xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>\\n`;\n }\n if (img.caption && img.caption.trim() !== '') {\n xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>\\n`;\n }\n \n // SEO Local\n if (img.geo_location && img.geo_location.trim() !== '') {\n xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>\\n`;\n }\n \n // Gestion des Licences Google Images\n if (img.license) {\n const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, 'image license URL');\n xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>\\n`;\n }\n \n xml += ` </image:image>\\n`;\n }\n }\n\n // Extension Vidéos\n if (entry.videos?.length) {\n for (const vid of entry.videos) {\n const cleanThumbLoc = sanitizeAndValidateUrl(vid.thumbnail_loc, 'video thumbnail');\n const cleanContentLoc = vid.content_loc ? sanitizeAndValidateUrl(vid.content_loc, 'video content location') : undefined;\n const cleanPlayerLoc = vid.player_loc ? sanitizeAndValidateUrl(vid.player_loc, 'video player location') : undefined;\n\n xml += ` <video:video>\\n`;\n xml += ` <video:thumbnail_loc>${escapeXml(cleanThumbLoc)}</video:thumbnail_loc>\\n`;\n xml += ` <video:title>${escapeXml(vid.title)}</video:title>\\n`;\n xml += ` <video:description>${escapeXml(vid.description)}</video:description>\\n`;\n \n if (cleanContentLoc) xml += ` <video:content_loc>${escapeXml(cleanContentLoc)}</video:content_loc>\\n`;\n if (cleanPlayerLoc) xml += ` <video:player_loc>${escapeXml(cleanPlayerLoc)}</video:player_loc>\\n`;\n \n if (vid.publication_date) {\n const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;\n xml += ` <video:publication_date>${vDate}</video:publication_date>\\n`;\n }\n\n // Métadonnées de statistiques (v1.1.3 - Préparé et sécurisé)\n if (vid.duration !== undefined) {\n xml += ` <video:duration>${Math.floor(vid.duration)}</video:duration>\\n`;\n }\n if (vid.view_count !== undefined) {\n xml += ` <video:view_count>${Math.floor(vid.view_count)}</video:view_count>\\n`;\n }\n\n // Support du Live Streaming v1.1.1\n if (vid.live) {\n xml += ` <video:live>${vid.live}</video:live>\\n`;\n }\n\n xml += ` </video:video>\\n`;\n }\n }\n\n // Extension News\n if (entry.news) {\n const nDate = entry.news.publication_date instanceof Date ? entry.news.publication_date.toISOString() : entry.news.publication_date;\n xml += ` <news:news>\\n`;\n xml += ` <news:publication>\\n`;\n xml += ` <news:name>${escapeXml(entry.news.name)}</news:name>\\n`;\n xml += ` <news:language>${escapeXml(entry.news.language)}</news:language>\\n`;\n xml += ` </news:publication>\\n`;\n xml += ` <news:publication_date>${nDate}</news:publication_date>\\n`;\n xml += ` <news:title>${escapeXml(entry.news.title)}</news:title>\\n`;\n xml += ` </news:news>\\n`;\n }\n\n xml += ` </url>\\n`;\n }\n\n xml += `</urlset>`;\n return xml;\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from './types/sitemap.js';\nimport { generateXml } from './core/generator.js';\n\nexport * from './types/sitemap.js';\n\n/**\n * Génère une réponse HTTP compatible Next.js (App Router) avec options de configuration.\n * v1.0.9 : Injection dynamique et personnalisable de l'en-tête Cache-Control via l'option maxAge\n * * @param entries - Liste des entrées du sitemap\n * @param options - Options de génération et de mise en cache (ex: autoLastmod, maxAge)\n * @returns Une instance de Response contenant le flux XML configuré\n */\nexport function getServerSitemapResponse(\n entries: SitemapEntry[], \n options: SitemapOptions = {}\n): Response {\n const xml = generateXml(entries, options);\n\n // Détermination de la stratégie de mise en cache (v1.0.9)\n const cacheControlHeader = options.maxAge !== undefined\n ? `public, max-age=${options.maxAge}, must-revalidate`\n : 'public, s-maxage=86400, stale-while-revalidate';\n\n return new Response(xml, {\n headers: {\n 'Content-Type': 'application/xml',\n 'Cache-Control': cacheControlHeader,\n },\n });\n}"],"mappings":";AASO,SAAS,UAAU,QAA2C;AACnE,MAAI,CAAC,OAAQ,QAAO;AAE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,IAAI,UAAU,CAAC;AAAA;AAAA,QAC9D;AAGA,YAAI,IAAI,MAAM;AACZ,iBAAO,qBAAqB,IAAI,IAAI;AAAA;AAAA,QACtC;AAEA,eAAO;AAAA;AAAA,MACT;AAAA,IACF;AAGA,QAAI,MAAM,MAAM;AACd,YAAM,QAAQ,MAAM,KAAK,4BAA4B,OAAO,MAAM,KAAK,iBAAiB,YAAY,IAAI,MAAM,KAAK;AACnH,aAAO;AAAA;AACP,aAAO;AAAA;AACP,aAAO,sBAAsB,UAAU,MAAM,KAAK,IAAI,CAAC;AAAA;AACvD,aAAO,0BAA0B,UAAU,MAAM,KAAK,QAAQ,CAAC;AAAA;AAC/D,aAAO;AAAA;AACP,aAAO,gCAAgC,KAAK;AAAA;AAC5C,aAAO,qBAAqB,UAAU,MAAM,KAAK,KAAK,CAAC;AAAA;AACvD,aAAO;AAAA;AAAA,IACT;AAEA,WAAO;AAAA;AAAA,EACT;AAEA,SAAO;AACP,SAAO;AACT;;;AC5KO,SAAS,yBACd,SACA,UAA0B,CAAC,GACjB;AACV,QAAM,MAAM,YAAY,SAAS,OAAO;AAGxC,QAAM,qBAAqB,QAAQ,WAAW,SAC1C,mBAAmB,QAAQ,MAAM,sBACjC;AAEJ,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/xml-escape.ts","../src/core/generator.ts","../src/index.ts"],"sourcesContent":["/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\n/**\n * Convertit les caractères spéciaux en entités XML pour éviter la corruption du fichier.\n * Gère : <, >, &, \", '\n */\nexport function escapeXml(unsafe: string | undefined | null): string {\n if (!unsafe) return '';\n \n return unsafe.replace(/[<>&\"']/g, (c) => {\n switch (c) {\n case '<': return '<';\n case '>': return '>';\n case '&': return '&';\n case '\"': return '"';\n case \"'\": return ''';\n default: return c;\n }\n });\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from '../types/sitemap.js';\nimport { escapeXml } from '../utils/xml-escape.js';\n\n/**\n * Nettoie et valide de manière stricte le format et la structure d'une URL.\n * v1.0.7 : Intégration de l'Auto-Trimming (nettoyage des espaces de début et de fin)\n */\nfunction sanitizeAndValidateUrl(rawUrl: string, context: string): string {\n const url = rawUrl ? rawUrl.trim() : '';\n\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\n throw new Error(\n `[next-advanced-sitemap] Invalid URL in ${context}: \"${url}\". URLs must start with http:// or https://`\n );\n }\n\n if (url.includes(' ')) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n let isValid = false;\n if (typeof URL.canParse === 'function') {\n isValid = URL.canParse(url);\n } else {\n try {\n new URL(url);\n isValid = true;\n } catch {\n isValid = false;\n }\n }\n\n if (!isValid) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n return url;\n}\n\n/**\n * Génère le flux XML complet du sitemap incluant les extensions Images, Vidéos, News et Hreflang.\n * v1.1.4 : Prise en charge et validation stricte des restrictions pays (ISO 3166) et plateformes (web, mobile, tv)\n */\nexport function generateXml(entries: SitemapEntry[], options: SitemapOptions = {}): string {\n const now = new Date().toISOString();\n let finalEntries = [...entries];\n\n if (options.sortByPriority) {\n finalEntries.sort((a, b) => {\n const priorityA = a.priority !== undefined ? (a.priority as number) : 0.5;\n const priorityB = b.priority !== undefined ? (b.priority as number) : 0.5;\n return priorityB - priorityA;\n });\n }\n \n let xml = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n`;\n xml += `<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\\n`;\n xml += ` xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"\\n`;\n xml += ` xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\"\\n`;\n xml += ` xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\"\\n`;\n xml += ` xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\\n`;\n\n for (const entry of finalEntries) {\n const cleanMainUrl = sanitizeAndValidateUrl(entry.url, 'main entry');\n\n xml += ` <url>\\n`;\n xml += ` <loc>${escapeXml(cleanMainUrl)}</loc>\\n`;\n\n if (entry.alternates?.length) {\n for (const alt of entry.alternates) {\n const cleanAltUrl = sanitizeAndValidateUrl(alt.href, 'alternate link');\n xml += ` <xhtml:link rel=\"alternate\" hreflang=\"${escapeXml(alt.hreflang)}\" href=\"${escapeXml(cleanAltUrl)}\" />\\n`;\n }\n }\n\n let lastmodValue = entry.lastmod;\n if (options.autoLastmod && !lastmodValue) {\n lastmodValue = now;\n }\n\n if (lastmodValue) {\n const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;\n xml += ` <lastmod>${date}</lastmod>\\n`;\n }\n\n if (entry.changefreq) {\n xml += ` <changefreq>${entry.changefreq}</changefreq>\\n`;\n }\n\n if (entry.priority !== undefined) {\n xml += ` <priority>${(entry.priority as number).toFixed(1)}</priority>\\n`;\n }\n\n // Extension Images\n if (entry.images?.length) {\n for (const img of entry.images) {\n const cleanImgUrl = sanitizeAndValidateUrl(img.loc, 'image location');\n \n xml += ` <image:image>\\n`;\n xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>\\n`;\n \n if (img.title && img.title.trim() !== '') {\n xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>\\n`;\n }\n if (img.caption && img.caption.trim() !== '') {\n xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>\\n`;\n }\n \n if (img.geo_location && img.geo_location.trim() !== '') {\n xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>\\n`;\n }\n \n if (img.license) {\n const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, 'image license URL');\n xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>\\n`;\n }\n \n xml += ` </image:image>\\n`;\n }\n }\n\n // Extension Vidéos\n if (entry.videos?.length) {\n for (const vid of entry.videos) {\n const cleanThumbLoc = sanitizeAndValidateUrl(vid.thumbnail_loc, 'video thumbnail');\n const cleanContentLoc = vid.content_loc ? sanitizeAndValidateUrl(vid.content_loc, 'video content location') : undefined;\n const cleanPlayerLoc = vid.player_loc ? sanitizeAndValidateUrl(vid.player_loc, 'video player location') : undefined;\n\n xml += ` <video:video>\\n`;\n xml += ` <video:thumbnail_loc>${escapeXml(cleanThumbLoc)}</video:thumbnail_loc>\\n`;\n xml += ` <video:title>${escapeXml(vid.title)}</video:title>\\n`;\n xml += ` <video:description>${escapeXml(vid.description)}</video:description>\\n`;\n \n if (cleanContentLoc) xml += ` <video:content_loc>${escapeXml(cleanContentLoc)}</video:content_loc>\\n`;\n if (cleanPlayerLoc) xml += ` <video:player_loc>${escapeXml(cleanPlayerLoc)}</video:player_loc>\\n`;\n \n if (vid.publication_date) {\n const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;\n xml += ` <video:publication_date>${vDate}</video:publication_date>\\n`;\n }\n\n if (vid.duration !== undefined) {\n const finalDuration = Math.floor(vid.duration);\n if (finalDuration < 0 || finalDuration > 28800) {\n throw new Error(\n `[next-advanced-sitemap] Invalid video duration: ${finalDuration}. Duration must be an integer between 0 and 28800 seconds (8 hours).`\n );\n }\n xml += ` <video:duration>${finalDuration}</video:duration>\\n`;\n }\n\n if (vid.view_count !== undefined) {\n const finalViewCount = Math.floor(vid.view_count);\n if (finalViewCount < 0) {\n throw new Error(\n `[next-advanced-sitemap] Invalid video view_count: ${finalViewCount}. View count cannot be negative.`\n );\n }\n xml += ` <video:view_count>${finalViewCount}</video:view_count>\\n`;\n }\n\n if (vid.live) {\n xml += ` <video:live>${vid.live}</video:live>\\n`;\n }\n\n // ✨ Validation et Sérialisation des Restrictions Pays (v1.1.4)\n if (vid.restriction) {\n if (!vid.restriction.countries || vid.restriction.countries.length === 0) {\n throw new Error(\n `[next-advanced-sitemap] Invalid video restriction: countries array cannot be empty.`\n );\n }\n\n const cleanCountries = vid.restriction.countries.map(country => {\n const code = country.trim().toUpperCase();\n if (code.length < 2 || code.length > 3) {\n throw new Error(\n `[next-advanced-sitemap] Invalid ISO country code detected: \"${country}\". Must be a valid ISO 3166 code.`\n );\n }\n return code;\n });\n\n const countriesStr = cleanCountries.join(' ');\n xml += ` <video:restriction relationship=\"${vid.restriction.relationship}\">${countriesStr}</video:restriction>\\n`;\n }\n\n // ✨ Validation et Sérialisation des Plateformes (v1.1.4)\n if (vid.platform) {\n if (!vid.platform.platforms || vid.platform.platforms.length === 0) {\n throw new Error(\n `[next-advanced-sitemap] Invalid video platform: platforms array cannot be empty.`\n );\n }\n\n const validPlatforms = ['web', 'mobile', 'tv'];\n for (const p of vid.platform.platforms) {\n if (!validPlatforms.includes(p)) {\n throw new Error(\n `[next-advanced-sitemap] Invalid platform type: \"${p}\". Allowed values are 'web', 'mobile', or 'tv'.`\n );\n }\n }\n\n const platformsStr = vid.platform.platforms.join(' ');\n xml += ` <video:platform relationship=\"${vid.platform.relationship}\">${platformsStr}</video:platform>\\n`;\n }\n\n xml += ` </video:video>\\n`;\n }\n }\n\n // Extension News\n if (entry.news) {\n const nDate = entry.news.publication_date instanceof Date ? entry.news.publication_date.toISOString() : entry.news.publication_date;\n xml += ` <news:news>\\n`;\n xml += ` <news:publication>\\n`;\n xml += ` <news:name>${escapeXml(entry.news.name)}</news:name>\\n`;\n xml += ` <news:language>${escapeXml(entry.news.language)}</news:language>\\n`;\n xml += ` </news:publication>\\n`;\n xml += ` <news:publication_date>${nDate}</news:publication_date>\\n`;\n xml += ` <news:title>${escapeXml(entry.news.title)}</news:title>\\n`;\n xml += ` </news:news>\\n`;\n }\n\n xml += ` </url>\\n`;\n }\n\n xml += `</urlset>`;\n return xml;\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from './types/sitemap.js';\nimport { generateXml } from './core/generator.js';\n\nexport * from './types/sitemap.js';\n\n/**\n * Génère une réponse HTTP compatible Next.js (App Router) avec options de configuration.\n * v1.0.9 : Injection dynamique et personnalisable de l'en-tête Cache-Control via l'option maxAge\n * * @param entries - Liste des entrées du sitemap\n * @param options - Options de génération et de mise en cache (ex: autoLastmod, maxAge)\n * @returns Une instance de Response contenant le flux XML configuré\n */\nexport function getServerSitemapResponse(\n entries: SitemapEntry[], \n options: SitemapOptions = {}\n): Response {\n const xml = generateXml(entries, options);\n\n // Détermination de la stratégie de mise en cache (v1.0.9)\n const cacheControlHeader = options.maxAge !== undefined\n ? `public, max-age=${options.maxAge}, must-revalidate`\n : 'public, s-maxage=86400, stale-while-revalidate';\n\n return new Response(xml, {\n headers: {\n 'Content-Type': 'application/xml',\n 'Cache-Control': cacheControlHeader,\n },\n });\n}"],"mappings":";AASO,SAAS,UAAU,QAA2C;AACnE,MAAI,CAAC,OAAQ,QAAO;AAEpB,SAAO,OAAO,QAAQ,YAAY,CAAC,MAAM;AACvC,YAAQ,GAAG;AAAA,MACT,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB;AAAS,eAAO;AAAA,IAClB;AAAA,EACF,CAAC;AACH;;;ACVA,SAAS,uBAAuB,QAAgB,SAAyB;AACvE,QAAM,MAAM,SAAS,OAAO,KAAK,IAAI;AAErC,MAAI,CAAC,IAAI,WAAW,SAAS,KAAK,CAAC,IAAI,WAAW,UAAU,GAAG;AAC7D,UAAM,IAAI;AAAA,MACR,0CAA0C,O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AAqB,UAAU,MAAM,KAAK,KAAK,CAAC;AAAA;AACvD,aAAO;AAAA;AAAA,IACT;AAEA,WAAO;AAAA;AAAA,EACT;AAEA,SAAO;AACP,SAAO;AACT;;;AC9NO,SAAS,yBACd,SACA,UAA0B,CAAC,GACjB;AACV,QAAM,MAAM,YAAY,SAAS,OAAO;AAGxC,QAAM,qBAAqB,QAAQ,WAAW,SAC1C,mBAAmB,QAAQ,MAAM,sBACjC;AAEJ,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-advanced-sitemap",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Advanced sitemap generator for Next.js. Powerful support for Google Images, Video, News, and Hreflang (multilingual). Type-safe, zero-dependency, and built for App Router.",
|
|
6
6
|
"main": "./dist/index.cjs",
|