next-advanced-sitemap 1.1.4 → 1.1.6
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 +27 -2
- package/dist/index.cjs +207 -142
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +207 -142
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,9 +13,11 @@ While Next.js provides a built-in `MetadataRoute.Sitemap` utility, it currently
|
|
|
13
13
|
|
|
14
14
|
- **Google Images Support**: Complete indexation of visual assets with support for titles, captions, local SEO positioning, and copyright protections.
|
|
15
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
|
+
- **Video Monetization Models & Prices (v1.1.6)**: Support for `<video:price>` parameters allowing VOD systems, streaming apps, and online academies to append clear monetary tags (`currency`, `value`, `type: rent/own`) directly into Google video indexing carousels.
|
|
16
17
|
- **Google Video Support**: Boost video search layouts and video-carousel presence on Google Search with complete structured data encapsulation.
|
|
17
|
-
- **Video
|
|
18
|
+
- **Video Subscription & Paywall Guardrails (v1.1.5)**: Native integration of the `<video:requires_subscription>` tag to signal premium paywall barriers or free-tier states, preventing user-frustration search algorithmic penalties.
|
|
18
19
|
- **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`).
|
|
20
|
+
- **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).
|
|
19
21
|
- **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
22
|
- **Google News Support**: Instant discovery for news publications with strict support for required news name, language tag, and publication date attributes.
|
|
21
23
|
- **Internationalization (Hreflang)**: Seamless rendering of `xhtml:link` relation tags to govern multi-regional and multilingual indexing across global markets.
|
|
@@ -65,6 +67,8 @@ export async function GET() {
|
|
|
65
67
|
publication_date: new Date(),
|
|
66
68
|
duration: 7200,
|
|
67
69
|
view_count: 25000,
|
|
70
|
+
// v1.1.5: Flexible Paywall Registration (Accepts boolean or strict 'yes' | 'no')
|
|
71
|
+
requires_subscription: true,
|
|
68
72
|
// v1.1.4: Strict Geographic Filtering & Capitalization Sanitization
|
|
69
73
|
restriction: {
|
|
70
74
|
relationship: 'allow',
|
|
@@ -84,7 +88,7 @@ export async function GET() {
|
|
|
84
88
|
images: [
|
|
85
89
|
{
|
|
86
90
|
loc: 'https://fomadev.com/images/product.png',
|
|
87
|
-
title: '
|
|
91
|
+
title: ' Premium Wireless Keyboard ', // v1.1.2: Auto-trimmed preventively
|
|
88
92
|
caption: 'Close-up shot of our custom mechanical keyboard layout with XML characters like & or <', // v1.1.2: Deep XML Escaping
|
|
89
93
|
geo_location: 'Kinshasa, Democratic Republic of the Congo', // v1.1.0 Local SEO
|
|
90
94
|
license: 'https://fomadev.com/terms/licensing' // v1.1.0 Badging
|
|
@@ -274,11 +278,32 @@ Generates a standard Next.js `Response` object with the correct `application/xml
|
|
|
274
278
|
<td>'yes' | 'no'</td>
|
|
275
279
|
<td>Optional switch triggering immediate Google SERP LIVE badges.</td>
|
|
276
280
|
</tr>
|
|
281
|
+
<tr>
|
|
282
|
+
<td><code>price</code></td>
|
|
283
|
+
<td>VideoPrice</td>
|
|
284
|
+
<td>Optional metadata structure attaching commercial purchase parameters to standard Google video rich cards.</td>
|
|
285
|
+
</tr>
|
|
277
286
|
</tbody>
|
|
278
287
|
</table>
|
|
279
288
|
|
|
280
289
|
## Technical Implementation
|
|
281
290
|
|
|
291
|
+
### Video Pay-Per-View & VOD Pricing Architecture (v1.1.6)
|
|
292
|
+
For on-demand streaming infrastructures, private bootcamps, and e-learning engines, exposing precise transactional pricing properties to crawlers structures Google's rich metadata carousels. **v1.1.6** implements strict formatting pipelines to meet internal Google Search Console parameters:
|
|
293
|
+
|
|
294
|
+
- **ISO 4217 Auto-Normalization**: Currency codes are uniformly trimmed and transformed to mandatory uppercase formats (e.g. `currency: 'eur'` standardizes to `currency="EUR"`). Strings mismatching the exact 3-character international standard are rejected instantly.
|
|
295
|
+
- **Float Price Rounding**: Transaction values automatically pass through an integrated decimal standardizer mapping raw database values into clean, 2-digit floating formats (`.toFixed(2)`) to ensure layout parser compliance.
|
|
296
|
+
- **Transactional Intent Filtering**: The structure locks the optional transactional property down to strict literal string unions (`'rent'` | `'own'`) to avoid invalid data entry.
|
|
297
|
+
|
|
298
|
+
### Paywall Registration & Subscription Guardrails (v1.1.5)
|
|
299
|
+
For media syndicates, educational organizations, and video streaming architectures utilizing monetization paywalls, misconfiguring premium access markers can lead to harsh ranking reductions due to misleading click funnels (user frustration loops). **v1.1.5** abstracts this integration completely:
|
|
300
|
+
|
|
301
|
+
- **Polymorphic Flag Binding**: Developers can feed standard TypeScript boolean primitives (`true`/`false`) smoothly during layout binding, or explicitly pass native schema tokens (`'yes'` / `'no'`).
|
|
302
|
+
|
|
303
|
+
- **Data Normalization Engine**: The compiler captures boolean states and automatically renders them into standard Googlebot-compliant entity wrappers behind the scenes.
|
|
304
|
+
|
|
305
|
+
- **Fail-Fast Boundary Validation**: Inputting mixed type variables instantly triggers an architectural parsing error at runtime to halt invalid XML distribution formats before deployment.
|
|
306
|
+
|
|
282
307
|
### Video Distribution Rights & Geo-Blocking Safeguards (v1.1.4)
|
|
283
308
|
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
309
|
|
package/dist/index.cjs
CHANGED
|
@@ -45,7 +45,7 @@ function escapeXml(unsafe) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
// src/core/
|
|
48
|
+
// src/core/builders/url-builder.ts
|
|
49
49
|
function sanitizeAndValidateUrl(rawUrl, context) {
|
|
50
50
|
const url = rawUrl ? rawUrl.trim() : "";
|
|
51
51
|
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
@@ -76,192 +76,257 @@ function sanitizeAndValidateUrl(rawUrl, context) {
|
|
|
76
76
|
}
|
|
77
77
|
return url;
|
|
78
78
|
}
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
finalEntries.sort((a, b) => {
|
|
84
|
-
const priorityA = a.priority !== void 0 ? a.priority : 0.5;
|
|
85
|
-
const priorityB = b.priority !== void 0 ? b.priority : 0.5;
|
|
86
|
-
return priorityB - priorityA;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
let xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
79
|
+
function buildUrlBaseXml(entry, options, nowIso) {
|
|
80
|
+
let xml = "";
|
|
81
|
+
const cleanMainUrl = sanitizeAndValidateUrl(entry.url, "main entry");
|
|
82
|
+
xml += ` <loc>${escapeXml(cleanMainUrl)}</loc>
|
|
90
83
|
`;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
if (entry.alternates?.length) {
|
|
85
|
+
for (const alt of entry.alternates) {
|
|
86
|
+
const cleanAltUrl = sanitizeAndValidateUrl(alt.href, "alternate link");
|
|
87
|
+
xml += ` <xhtml:link rel="alternate" hreflang="${escapeXml(alt.hreflang)}" href="${escapeXml(cleanAltUrl)}" />
|
|
94
88
|
`;
|
|
95
|
-
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
let lastmodValue = entry.lastmod;
|
|
92
|
+
if (options.autoLastmod && !lastmodValue) {
|
|
93
|
+
lastmodValue = nowIso;
|
|
94
|
+
}
|
|
95
|
+
if (lastmodValue) {
|
|
96
|
+
const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;
|
|
97
|
+
xml += ` <lastmod>${date}</lastmod>
|
|
96
98
|
`;
|
|
97
|
-
|
|
99
|
+
}
|
|
100
|
+
if (entry.changefreq) {
|
|
101
|
+
xml += ` <changefreq>${entry.changefreq}</changefreq>
|
|
98
102
|
`;
|
|
99
|
-
|
|
103
|
+
}
|
|
104
|
+
if (entry.priority !== void 0) {
|
|
105
|
+
xml += ` <priority>${entry.priority.toFixed(1)}</priority>
|
|
100
106
|
`;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
}
|
|
108
|
+
return xml;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/core/builders/image-builder.ts
|
|
112
|
+
function buildImageXml(images) {
|
|
113
|
+
if (!images?.length) return "";
|
|
114
|
+
let xml = "";
|
|
115
|
+
for (const img of images) {
|
|
116
|
+
const cleanImgUrl = sanitizeAndValidateUrl(img.loc, "image location");
|
|
117
|
+
xml += ` <image:image>
|
|
104
118
|
`;
|
|
105
|
-
xml += `
|
|
119
|
+
xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>
|
|
106
120
|
`;
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
const cleanAltUrl = sanitizeAndValidateUrl(alt.href, "alternate link");
|
|
110
|
-
xml += ` <xhtml:link rel="alternate" hreflang="${escapeXml(alt.hreflang)}" href="${escapeXml(cleanAltUrl)}" />
|
|
121
|
+
if (img.title && img.title.trim() !== "") {
|
|
122
|
+
xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>
|
|
111
123
|
`;
|
|
112
|
-
}
|
|
113
124
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
lastmodValue = now;
|
|
117
|
-
}
|
|
118
|
-
if (lastmodValue) {
|
|
119
|
-
const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;
|
|
120
|
-
xml += ` <lastmod>${date}</lastmod>
|
|
125
|
+
if (img.caption && img.caption.trim() !== "") {
|
|
126
|
+
xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>
|
|
121
127
|
`;
|
|
122
128
|
}
|
|
123
|
-
if (
|
|
124
|
-
xml += `
|
|
129
|
+
if (img.geo_location && img.geo_location.trim() !== "") {
|
|
130
|
+
xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>
|
|
125
131
|
`;
|
|
126
132
|
}
|
|
127
|
-
if (
|
|
128
|
-
|
|
133
|
+
if (img.license) {
|
|
134
|
+
const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, "image license URL");
|
|
135
|
+
xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>
|
|
129
136
|
`;
|
|
130
137
|
}
|
|
131
|
-
|
|
132
|
-
for (const img of entry.images) {
|
|
133
|
-
const cleanImgUrl = sanitizeAndValidateUrl(img.loc, "image location");
|
|
134
|
-
xml += ` <image:image>
|
|
138
|
+
xml += ` </image:image>
|
|
135
139
|
`;
|
|
136
|
-
|
|
140
|
+
}
|
|
141
|
+
return xml;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/core/builders/video-builder.ts
|
|
145
|
+
function buildVideoXml(videos) {
|
|
146
|
+
if (!videos?.length) return "";
|
|
147
|
+
let xml = "";
|
|
148
|
+
for (const vid of videos) {
|
|
149
|
+
const cleanThumbLoc = sanitizeAndValidateUrl(vid.thumbnail_loc, "video thumbnail");
|
|
150
|
+
const cleanContentLoc = vid.content_loc ? sanitizeAndValidateUrl(vid.content_loc, "video content location") : void 0;
|
|
151
|
+
const cleanPlayerLoc = vid.player_loc ? sanitizeAndValidateUrl(vid.player_loc, "video player location") : void 0;
|
|
152
|
+
xml += ` <video:video>
|
|
137
153
|
`;
|
|
138
|
-
|
|
139
|
-
xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>
|
|
154
|
+
xml += ` <video:thumbnail_loc>${escapeXml(cleanThumbLoc)}</video:thumbnail_loc>
|
|
140
155
|
`;
|
|
141
|
-
|
|
142
|
-
if (img.caption && img.caption.trim() !== "") {
|
|
143
|
-
xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>
|
|
156
|
+
xml += ` <video:title>${escapeXml(vid.title)}</video:title>
|
|
144
157
|
`;
|
|
145
|
-
|
|
146
|
-
if (img.geo_location && img.geo_location.trim() !== "") {
|
|
147
|
-
xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>
|
|
158
|
+
xml += ` <video:description>${escapeXml(vid.description)}</video:description>
|
|
148
159
|
`;
|
|
149
|
-
|
|
150
|
-
if (img.license) {
|
|
151
|
-
const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, "image license URL");
|
|
152
|
-
xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>
|
|
160
|
+
if (cleanContentLoc) xml += ` <video:content_loc>${escapeXml(cleanContentLoc)}</video:content_loc>
|
|
153
161
|
`;
|
|
154
|
-
|
|
155
|
-
xml += ` </image:image>
|
|
162
|
+
if (cleanPlayerLoc) xml += ` <video:player_loc>${escapeXml(cleanPlayerLoc)}</video:player_loc>
|
|
156
163
|
`;
|
|
164
|
+
if (vid.publication_date) {
|
|
165
|
+
const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;
|
|
166
|
+
xml += ` <video:publication_date>${vDate}</video:publication_date>
|
|
167
|
+
`;
|
|
168
|
+
}
|
|
169
|
+
if (vid.duration !== void 0) {
|
|
170
|
+
const finalDuration = Math.floor(vid.duration);
|
|
171
|
+
if (finalDuration < 0 || finalDuration > 28800) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
`[next-advanced-sitemap] Invalid video duration: ${finalDuration}. Duration must be an integer between 0 and 28800 seconds (8 hours).`
|
|
174
|
+
);
|
|
157
175
|
}
|
|
176
|
+
xml += ` <video:duration>${finalDuration}</video:duration>
|
|
177
|
+
`;
|
|
158
178
|
}
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
179
|
+
if (vid.view_count !== void 0) {
|
|
180
|
+
const finalViewCount = Math.floor(vid.view_count);
|
|
181
|
+
if (finalViewCount < 0) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`[next-advanced-sitemap] Invalid video view_count: ${finalViewCount}. View count cannot be negative.`
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
xml += ` <video:view_count>${finalViewCount}</video:view_count>
|
|
165
187
|
`;
|
|
166
|
-
|
|
188
|
+
}
|
|
189
|
+
if (vid.live) {
|
|
190
|
+
xml += ` <video:live>${vid.live}</video:live>
|
|
167
191
|
`;
|
|
168
|
-
|
|
192
|
+
}
|
|
193
|
+
if (vid.restriction) {
|
|
194
|
+
if (!vid.restriction.countries || vid.restriction.countries.length === 0) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`[next-advanced-sitemap] Invalid video restriction: countries array cannot be empty.`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
const cleanCountries = vid.restriction.countries.map((country) => {
|
|
200
|
+
const code = country.trim().toUpperCase();
|
|
201
|
+
if (code.length < 2 || code.length > 3) {
|
|
202
|
+
throw new Error(
|
|
203
|
+
`[next-advanced-sitemap] Invalid ISO country code detected: "${country}". Must be a valid ISO 3166 code.`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return code;
|
|
207
|
+
});
|
|
208
|
+
const countriesStr = cleanCountries.join(" ");
|
|
209
|
+
xml += ` <video:restriction relationship="${vid.restriction.relationship}">${countriesStr}</video:restriction>
|
|
169
210
|
`;
|
|
170
|
-
|
|
211
|
+
}
|
|
212
|
+
if (vid.platform) {
|
|
213
|
+
if (!vid.platform.platforms || vid.platform.platforms.length === 0) {
|
|
214
|
+
throw new Error(
|
|
215
|
+
`[next-advanced-sitemap] Invalid video platform: platforms array cannot be empty.`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
const validPlatforms = ["web", "mobile", "tv"];
|
|
219
|
+
for (const p of vid.platform.platforms) {
|
|
220
|
+
if (!validPlatforms.includes(p)) {
|
|
221
|
+
throw new Error(
|
|
222
|
+
`[next-advanced-sitemap] Invalid platform type: "${p}". Allowed values are 'web', 'mobile', or 'tv'.`
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const platformsStr = vid.platform.platforms.join(" ");
|
|
227
|
+
xml += ` <video:platform relationship="${vid.platform.relationship}">${platformsStr}</video:platform>
|
|
171
228
|
`;
|
|
172
|
-
|
|
229
|
+
}
|
|
230
|
+
if (vid.requires_subscription !== void 0) {
|
|
231
|
+
let subValue;
|
|
232
|
+
if (typeof vid.requires_subscription === "boolean") {
|
|
233
|
+
subValue = vid.requires_subscription ? "yes" : "no";
|
|
234
|
+
} else if (vid.requires_subscription === "yes" || vid.requires_subscription === "no") {
|
|
235
|
+
subValue = vid.requires_subscription;
|
|
236
|
+
} else {
|
|
237
|
+
throw new Error(
|
|
238
|
+
`[next-advanced-sitemap] Invalid value for requires_subscription: "${vid.requires_subscription}". Expected boolean or strict string 'yes' | 'no'.`
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
xml += ` <video:requires_subscription>${subValue}</video:requires_subscription>
|
|
173
242
|
`;
|
|
174
|
-
|
|
243
|
+
}
|
|
244
|
+
if (vid.price) {
|
|
245
|
+
const { value, currency, type } = vid.price;
|
|
246
|
+
if (value === void 0 || value < 0) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`[next-advanced-sitemap] Invalid video price value: "${value}". Value must be a positive number.`
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
const cleanCurrency = currency ? currency.trim().toUpperCase() : "";
|
|
252
|
+
if (cleanCurrency.length !== 3) {
|
|
253
|
+
throw new Error(
|
|
254
|
+
`[next-advanced-sitemap] Invalid ISO 4217 currency code: "${currency}". Currency must be exactly a 3-letter code.`
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
let priceXml = ` <video:price currency="${cleanCurrency}"`;
|
|
258
|
+
if (type) {
|
|
259
|
+
if (type !== "rent" && type !== "own") {
|
|
260
|
+
throw new Error(
|
|
261
|
+
`[next-advanced-sitemap] Invalid price type: "${type}". Allowed values are 'rent' or 'own'.`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
priceXml += ` type="${type}"`;
|
|
265
|
+
}
|
|
266
|
+
priceXml += `>${value.toFixed(2)}</video:price>
|
|
175
267
|
`;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
268
|
+
xml += priceXml;
|
|
269
|
+
}
|
|
270
|
+
xml += ` </video:video>
|
|
179
271
|
`;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
272
|
+
}
|
|
273
|
+
return xml;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// src/core/builders/news-builder.ts
|
|
277
|
+
function buildNewsXml(news) {
|
|
278
|
+
if (!news) return "";
|
|
279
|
+
const nDate = news.publication_date instanceof Date ? news.publication_date.toISOString() : news.publication_date;
|
|
280
|
+
let xml = "";
|
|
281
|
+
xml += ` <news:news>
|
|
189
282
|
`;
|
|
190
|
-
|
|
191
|
-
if (vid.view_count !== void 0) {
|
|
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>
|
|
283
|
+
xml += ` <news:publication>
|
|
199
284
|
`;
|
|
200
|
-
}
|
|
201
|
-
if (vid.live) {
|
|
202
|
-
xml += ` <video:live>${vid.live}</video:live>
|
|
285
|
+
xml += ` <news:name>${escapeXml(news.name)}</news:name>
|
|
203
286
|
`;
|
|
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>
|
|
287
|
+
xml += ` <news:language>${escapeXml(news.language)}</news:language>
|
|
222
288
|
`;
|
|
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>
|
|
289
|
+
xml += ` </news:publication>
|
|
240
290
|
`;
|
|
241
|
-
|
|
242
|
-
xml += ` </video:video>
|
|
291
|
+
xml += ` <news:publication_date>${nDate}</news:publication_date>
|
|
243
292
|
`;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
if (entry.news) {
|
|
247
|
-
const nDate = entry.news.publication_date instanceof Date ? entry.news.publication_date.toISOString() : entry.news.publication_date;
|
|
248
|
-
xml += ` <news:news>
|
|
293
|
+
xml += ` <news:title>${escapeXml(news.title)}</news:title>
|
|
249
294
|
`;
|
|
250
|
-
|
|
295
|
+
xml += ` </news:news>
|
|
251
296
|
`;
|
|
252
|
-
|
|
297
|
+
return xml;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/core/generator.ts
|
|
301
|
+
function generateXml(entries, options = {}) {
|
|
302
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
303
|
+
let finalEntries = [...entries];
|
|
304
|
+
if (options.sortByPriority) {
|
|
305
|
+
finalEntries.sort((a, b) => {
|
|
306
|
+
const priorityA = a.priority !== void 0 ? a.priority : 0.5;
|
|
307
|
+
const priorityB = b.priority !== void 0 ? b.priority : 0.5;
|
|
308
|
+
return priorityB - priorityA;
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
let xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
253
312
|
`;
|
|
254
|
-
|
|
313
|
+
xml += `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
255
314
|
`;
|
|
256
|
-
|
|
315
|
+
xml += ` xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
|
|
257
316
|
`;
|
|
258
|
-
|
|
317
|
+
xml += ` xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
|
|
259
318
|
`;
|
|
260
|
-
|
|
319
|
+
xml += ` xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
|
|
261
320
|
`;
|
|
262
|
-
|
|
321
|
+
xml += ` xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
263
322
|
`;
|
|
264
|
-
|
|
323
|
+
for (const entry of finalEntries) {
|
|
324
|
+
xml += ` <url>
|
|
325
|
+
`;
|
|
326
|
+
xml += buildUrlBaseXml(entry, options, now);
|
|
327
|
+
xml += buildImageXml(entry.images);
|
|
328
|
+
xml += buildVideoXml(entry.videos);
|
|
329
|
+
xml += buildNewsXml(entry.news);
|
|
265
330
|
xml += ` </url>
|
|
266
331
|
`;
|
|
267
332
|
}
|
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.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 x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,IAAI,SAAS,WAAW;AACtC,gBAAI,CAAC,eAAe,SAAS,CAAC,GAAG;AAC/B,oBAAM,IAAI;AAAA,gBACR,mDAAmD,CAAC;AAAA,cACtD;AAAA,YACF;AAAA,UACF;AAEA,gBAAM,eAAe,IAAI,SAAS,UAAU,KAAK,GAAG;AACpD,iBAAO,uCAAuC,IAAI,SAAS,YAAY,KAAK,YAAY;AAAA;AAAA,QAC1F;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;;;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":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils/xml-escape.ts","../src/core/builders/url-builder.ts","../src/core/builders/image-builder.ts","../src/core/builders/video-builder.ts","../src/core/builders/news-builder.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 */\nexport function 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 bloc XML de base pour un nœud URL (loc, alternates, lastmod, changefreq, priority).\n */\nexport function buildUrlBaseXml(entry: SitemapEntry, options: SitemapOptions, nowIso: string): string {\n let xml = '';\n \n const cleanMainUrl = sanitizeAndValidateUrl(entry.url, 'main entry');\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 = nowIso;\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 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 } from '../../types/sitemap.js';\nimport { escapeXml } from '../../utils/xml-escape.js';\nimport { sanitizeAndValidateUrl } from './url-builder.js';\n\nexport function buildImageXml(images: SitemapEntry['images']): string {\n if (!images?.length) return '';\n\n let xml = '';\n for (const img of 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 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 } from '../../types/sitemap.js';\nimport { escapeXml } from '../../utils/xml-escape.js';\nimport { sanitizeAndValidateUrl } from './url-builder.js';\n\nexport function buildVideoXml(videos: SitemapEntry['videos']): string {\n if (!videos?.length) return '';\n\n let xml = '';\n for (const vid of 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 // ✨ Validation et Sérialisation de la durée (0 - 28800s)\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 // ✨ Validation et Sérialisation du nombre de vues (>= 0)\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 if (vid.requires_subscription !== undefined) {\n let subValue: 'yes' | 'no';\n\n if (typeof vid.requires_subscription === 'boolean') {\n subValue = vid.requires_subscription ? 'yes' : 'no';\n } else if (vid.requires_subscription === 'yes' || vid.requires_subscription === 'no') {\n subValue = vid.requires_subscription;\n } else {\n throw new Error(\n `[next-advanced-sitemap] Invalid value for requires_subscription: \"${vid.requires_subscription}\". Expected boolean or strict string 'yes' | 'no'.`\n );\n }\n\n xml += ` <video:requires_subscription>${subValue}</video:requires_subscription>\\n`;\n }\n\n // ✨ Validation et Sérialisation des Prix et Achats (v1.1.6)\n if (vid.price) {\n const { value, currency, type } = vid.price;\n\n if (value === undefined || value < 0) {\n throw new Error(\n `[next-advanced-sitemap] Invalid video price value: \"${value}\". Value must be a positive number.`\n );\n }\n\n const cleanCurrency = currency ? currency.trim().toUpperCase() : '';\n if (cleanCurrency.length !== 3) {\n throw new Error(\n `[next-advanced-sitemap] Invalid ISO 4217 currency code: \"${currency}\". Currency must be exactly a 3-letter code.`\n );\n }\n\n let priceXml = ` <video:price currency=\"${cleanCurrency}\"`;\n if (type) {\n if (type !== 'rent' && type !== 'own') {\n throw new Error(\n `[next-advanced-sitemap] Invalid price type: \"${type}\". Allowed values are 'rent' or 'own'.`\n );\n }\n priceXml += ` type=\"${type}\"`;\n }\n priceXml += `>${value.toFixed(2)}</video:price>\\n`;\n \n xml += priceXml;\n }\n\n xml += ` </video:video>\\n`;\n }\n \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 } from '../../types/sitemap.js';\nimport { escapeXml } from '../../utils/xml-escape.js';\n\nexport function buildNewsXml(news: SitemapEntry['news']): string {\n if (!news) return '';\n\n const nDate = news.publication_date instanceof Date ? news.publication_date.toISOString() : news.publication_date;\n \n let xml = '';\n xml += ` <news:news>\\n`;\n xml += ` <news:publication>\\n`;\n xml += ` <news:name>${escapeXml(news.name)}</news:name>\\n`;\n xml += ` <news:language>${escapeXml(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(news.title)}</news:title>\\n`;\n xml += ` </news:news>\\n`;\n \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 { buildUrlBaseXml } from './builders/url-builder.js';\nimport { buildImageXml } from './builders/image-builder.js';\nimport { buildVideoXml } from './builders/video-builder.js';\nimport { buildNewsXml } from './builders/news-builder.js';\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 : Version découplée et hautement modulaire.\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 xml += ` <url>\\n`;\n \n // 1. Éléments de base et hreflang alternatifs\n xml += buildUrlBaseXml(entry, options, now);\n\n // 2. Extension Images Google\n xml += buildImageXml(entry.images);\n\n // 3. Extension Vidéos Google (Validations v1.1.3 & v1.1.4 intégrées)\n xml += buildVideoXml(entry.videos);\n\n // 4. Extension News Google\n xml += buildNewsXml(entry.news);\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;;;ACVO,SAAS,uBAAuB,QAAgB,SAAyB;AAC9E,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,GAAG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E9B,WAAO;AAAA;AAAA,EACT;AAEA,SAAO;AACP,SAAO;AACT;;;ANrCO,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
|
@@ -45,6 +45,14 @@ interface VideoPlatform {
|
|
|
45
45
|
/** Tableau de plateformes autorisées ou interdites */
|
|
46
46
|
platforms: ('web' | 'mobile' | 'tv')[];
|
|
47
47
|
}
|
|
48
|
+
interface VideoPrice {
|
|
49
|
+
/** Valeur numérique du prix (ex: 9.99) */
|
|
50
|
+
value: number;
|
|
51
|
+
/** Code de devise ISO 4217 à 3 lettres (ex: 'USD', 'EUR', 'CDF') */
|
|
52
|
+
currency: string;
|
|
53
|
+
/** Optionnel : Type de transaction, soit 'rent' (location) ou 'own' (achat) */
|
|
54
|
+
type?: 'rent' | 'own';
|
|
55
|
+
}
|
|
48
56
|
/**
|
|
49
57
|
* Interface pour les vidéos dans le sitemap
|
|
50
58
|
* @see https://developers.google.com/search/docs/crawling-indexing/sitemaps/video-sitemaps
|
|
@@ -67,6 +75,17 @@ interface SitemapVideo {
|
|
|
67
75
|
restriction?: VideoRestriction;
|
|
68
76
|
/** (Optional) v1.1.4: Restriction selon le type d'appareil / plateforme. */
|
|
69
77
|
platform?: VideoPlatform;
|
|
78
|
+
/**
|
|
79
|
+
* v1.1.5 : Indique si l'accès à la vidéo nécessite un abonnement payant.
|
|
80
|
+
* Accepte true/false ou de manière stricte 'yes'/'no'.
|
|
81
|
+
* @see https://developers.google.com/search/docs/crawling-indexing/sitemaps/video-sitemaps
|
|
82
|
+
*/
|
|
83
|
+
requires_subscription?: boolean | 'yes' | 'no';
|
|
84
|
+
/**
|
|
85
|
+
* v1.1.6 : Tarification de la vidéo pour l'achat ou la location (VOD).
|
|
86
|
+
* @see https://developers.google.com/search/docs/crawling-indexing/sitemaps/video-sitemaps
|
|
87
|
+
*/
|
|
88
|
+
price?: VideoPrice;
|
|
70
89
|
}
|
|
71
90
|
/**
|
|
72
91
|
* Interface pour Google News
|
|
@@ -123,4 +142,4 @@ interface SitemapOptions {
|
|
|
123
142
|
*/
|
|
124
143
|
declare function getServerSitemapResponse(entries: SitemapEntry[], options?: SitemapOptions): Response;
|
|
125
144
|
|
|
126
|
-
export { type SitemapAlternate, type SitemapChangeFreq, type SitemapEntry, type SitemapImage, type SitemapNews, type SitemapOptions, type SitemapPriority, type SitemapVideo, type VideoPlatform, type VideoRestriction, getServerSitemapResponse };
|
|
145
|
+
export { type SitemapAlternate, type SitemapChangeFreq, type SitemapEntry, type SitemapImage, type SitemapNews, type SitemapOptions, type SitemapPriority, type SitemapVideo, type VideoPlatform, type VideoPrice, type VideoRestriction, getServerSitemapResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -45,6 +45,14 @@ interface VideoPlatform {
|
|
|
45
45
|
/** Tableau de plateformes autorisées ou interdites */
|
|
46
46
|
platforms: ('web' | 'mobile' | 'tv')[];
|
|
47
47
|
}
|
|
48
|
+
interface VideoPrice {
|
|
49
|
+
/** Valeur numérique du prix (ex: 9.99) */
|
|
50
|
+
value: number;
|
|
51
|
+
/** Code de devise ISO 4217 à 3 lettres (ex: 'USD', 'EUR', 'CDF') */
|
|
52
|
+
currency: string;
|
|
53
|
+
/** Optionnel : Type de transaction, soit 'rent' (location) ou 'own' (achat) */
|
|
54
|
+
type?: 'rent' | 'own';
|
|
55
|
+
}
|
|
48
56
|
/**
|
|
49
57
|
* Interface pour les vidéos dans le sitemap
|
|
50
58
|
* @see https://developers.google.com/search/docs/crawling-indexing/sitemaps/video-sitemaps
|
|
@@ -67,6 +75,17 @@ interface SitemapVideo {
|
|
|
67
75
|
restriction?: VideoRestriction;
|
|
68
76
|
/** (Optional) v1.1.4: Restriction selon le type d'appareil / plateforme. */
|
|
69
77
|
platform?: VideoPlatform;
|
|
78
|
+
/**
|
|
79
|
+
* v1.1.5 : Indique si l'accès à la vidéo nécessite un abonnement payant.
|
|
80
|
+
* Accepte true/false ou de manière stricte 'yes'/'no'.
|
|
81
|
+
* @see https://developers.google.com/search/docs/crawling-indexing/sitemaps/video-sitemaps
|
|
82
|
+
*/
|
|
83
|
+
requires_subscription?: boolean | 'yes' | 'no';
|
|
84
|
+
/**
|
|
85
|
+
* v1.1.6 : Tarification de la vidéo pour l'achat ou la location (VOD).
|
|
86
|
+
* @see https://developers.google.com/search/docs/crawling-indexing/sitemaps/video-sitemaps
|
|
87
|
+
*/
|
|
88
|
+
price?: VideoPrice;
|
|
70
89
|
}
|
|
71
90
|
/**
|
|
72
91
|
* Interface pour Google News
|
|
@@ -123,4 +142,4 @@ interface SitemapOptions {
|
|
|
123
142
|
*/
|
|
124
143
|
declare function getServerSitemapResponse(entries: SitemapEntry[], options?: SitemapOptions): Response;
|
|
125
144
|
|
|
126
|
-
export { type SitemapAlternate, type SitemapChangeFreq, type SitemapEntry, type SitemapImage, type SitemapNews, type SitemapOptions, type SitemapPriority, type SitemapVideo, type VideoPlatform, type VideoRestriction, getServerSitemapResponse };
|
|
145
|
+
export { type SitemapAlternate, type SitemapChangeFreq, type SitemapEntry, type SitemapImage, type SitemapNews, type SitemapOptions, type SitemapPriority, type SitemapVideo, type VideoPlatform, type VideoPrice, type VideoRestriction, getServerSitemapResponse };
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ function escapeXml(unsafe) {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
// src/core/
|
|
22
|
+
// src/core/builders/url-builder.ts
|
|
23
23
|
function sanitizeAndValidateUrl(rawUrl, context) {
|
|
24
24
|
const url = rawUrl ? rawUrl.trim() : "";
|
|
25
25
|
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
@@ -50,192 +50,257 @@ function sanitizeAndValidateUrl(rawUrl, context) {
|
|
|
50
50
|
}
|
|
51
51
|
return url;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
finalEntries.sort((a, b) => {
|
|
58
|
-
const priorityA = a.priority !== void 0 ? a.priority : 0.5;
|
|
59
|
-
const priorityB = b.priority !== void 0 ? b.priority : 0.5;
|
|
60
|
-
return priorityB - priorityA;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
let xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
53
|
+
function buildUrlBaseXml(entry, options, nowIso) {
|
|
54
|
+
let xml = "";
|
|
55
|
+
const cleanMainUrl = sanitizeAndValidateUrl(entry.url, "main entry");
|
|
56
|
+
xml += ` <loc>${escapeXml(cleanMainUrl)}</loc>
|
|
64
57
|
`;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
if (entry.alternates?.length) {
|
|
59
|
+
for (const alt of entry.alternates) {
|
|
60
|
+
const cleanAltUrl = sanitizeAndValidateUrl(alt.href, "alternate link");
|
|
61
|
+
xml += ` <xhtml:link rel="alternate" hreflang="${escapeXml(alt.hreflang)}" href="${escapeXml(cleanAltUrl)}" />
|
|
68
62
|
`;
|
|
69
|
-
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
let lastmodValue = entry.lastmod;
|
|
66
|
+
if (options.autoLastmod && !lastmodValue) {
|
|
67
|
+
lastmodValue = nowIso;
|
|
68
|
+
}
|
|
69
|
+
if (lastmodValue) {
|
|
70
|
+
const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;
|
|
71
|
+
xml += ` <lastmod>${date}</lastmod>
|
|
70
72
|
`;
|
|
71
|
-
|
|
73
|
+
}
|
|
74
|
+
if (entry.changefreq) {
|
|
75
|
+
xml += ` <changefreq>${entry.changefreq}</changefreq>
|
|
72
76
|
`;
|
|
73
|
-
|
|
77
|
+
}
|
|
78
|
+
if (entry.priority !== void 0) {
|
|
79
|
+
xml += ` <priority>${entry.priority.toFixed(1)}</priority>
|
|
74
80
|
`;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
}
|
|
82
|
+
return xml;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/core/builders/image-builder.ts
|
|
86
|
+
function buildImageXml(images) {
|
|
87
|
+
if (!images?.length) return "";
|
|
88
|
+
let xml = "";
|
|
89
|
+
for (const img of images) {
|
|
90
|
+
const cleanImgUrl = sanitizeAndValidateUrl(img.loc, "image location");
|
|
91
|
+
xml += ` <image:image>
|
|
78
92
|
`;
|
|
79
|
-
xml += `
|
|
93
|
+
xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>
|
|
80
94
|
`;
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
const cleanAltUrl = sanitizeAndValidateUrl(alt.href, "alternate link");
|
|
84
|
-
xml += ` <xhtml:link rel="alternate" hreflang="${escapeXml(alt.hreflang)}" href="${escapeXml(cleanAltUrl)}" />
|
|
95
|
+
if (img.title && img.title.trim() !== "") {
|
|
96
|
+
xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>
|
|
85
97
|
`;
|
|
86
|
-
}
|
|
87
98
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
lastmodValue = now;
|
|
91
|
-
}
|
|
92
|
-
if (lastmodValue) {
|
|
93
|
-
const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;
|
|
94
|
-
xml += ` <lastmod>${date}</lastmod>
|
|
99
|
+
if (img.caption && img.caption.trim() !== "") {
|
|
100
|
+
xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>
|
|
95
101
|
`;
|
|
96
102
|
}
|
|
97
|
-
if (
|
|
98
|
-
xml += `
|
|
103
|
+
if (img.geo_location && img.geo_location.trim() !== "") {
|
|
104
|
+
xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>
|
|
99
105
|
`;
|
|
100
106
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
107
|
+
if (img.license) {
|
|
108
|
+
const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, "image license URL");
|
|
109
|
+
xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>
|
|
103
110
|
`;
|
|
104
111
|
}
|
|
105
|
-
|
|
106
|
-
for (const img of entry.images) {
|
|
107
|
-
const cleanImgUrl = sanitizeAndValidateUrl(img.loc, "image location");
|
|
108
|
-
xml += ` <image:image>
|
|
112
|
+
xml += ` </image:image>
|
|
109
113
|
`;
|
|
110
|
-
|
|
114
|
+
}
|
|
115
|
+
return xml;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/core/builders/video-builder.ts
|
|
119
|
+
function buildVideoXml(videos) {
|
|
120
|
+
if (!videos?.length) return "";
|
|
121
|
+
let xml = "";
|
|
122
|
+
for (const vid of videos) {
|
|
123
|
+
const cleanThumbLoc = sanitizeAndValidateUrl(vid.thumbnail_loc, "video thumbnail");
|
|
124
|
+
const cleanContentLoc = vid.content_loc ? sanitizeAndValidateUrl(vid.content_loc, "video content location") : void 0;
|
|
125
|
+
const cleanPlayerLoc = vid.player_loc ? sanitizeAndValidateUrl(vid.player_loc, "video player location") : void 0;
|
|
126
|
+
xml += ` <video:video>
|
|
111
127
|
`;
|
|
112
|
-
|
|
113
|
-
xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>
|
|
128
|
+
xml += ` <video:thumbnail_loc>${escapeXml(cleanThumbLoc)}</video:thumbnail_loc>
|
|
114
129
|
`;
|
|
115
|
-
|
|
116
|
-
if (img.caption && img.caption.trim() !== "") {
|
|
117
|
-
xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>
|
|
130
|
+
xml += ` <video:title>${escapeXml(vid.title)}</video:title>
|
|
118
131
|
`;
|
|
119
|
-
|
|
120
|
-
if (img.geo_location && img.geo_location.trim() !== "") {
|
|
121
|
-
xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>
|
|
132
|
+
xml += ` <video:description>${escapeXml(vid.description)}</video:description>
|
|
122
133
|
`;
|
|
123
|
-
|
|
124
|
-
if (img.license) {
|
|
125
|
-
const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, "image license URL");
|
|
126
|
-
xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>
|
|
134
|
+
if (cleanContentLoc) xml += ` <video:content_loc>${escapeXml(cleanContentLoc)}</video:content_loc>
|
|
127
135
|
`;
|
|
128
|
-
|
|
129
|
-
xml += ` </image:image>
|
|
136
|
+
if (cleanPlayerLoc) xml += ` <video:player_loc>${escapeXml(cleanPlayerLoc)}</video:player_loc>
|
|
130
137
|
`;
|
|
138
|
+
if (vid.publication_date) {
|
|
139
|
+
const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;
|
|
140
|
+
xml += ` <video:publication_date>${vDate}</video:publication_date>
|
|
141
|
+
`;
|
|
142
|
+
}
|
|
143
|
+
if (vid.duration !== void 0) {
|
|
144
|
+
const finalDuration = Math.floor(vid.duration);
|
|
145
|
+
if (finalDuration < 0 || finalDuration > 28800) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`[next-advanced-sitemap] Invalid video duration: ${finalDuration}. Duration must be an integer between 0 and 28800 seconds (8 hours).`
|
|
148
|
+
);
|
|
131
149
|
}
|
|
150
|
+
xml += ` <video:duration>${finalDuration}</video:duration>
|
|
151
|
+
`;
|
|
132
152
|
}
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
153
|
+
if (vid.view_count !== void 0) {
|
|
154
|
+
const finalViewCount = Math.floor(vid.view_count);
|
|
155
|
+
if (finalViewCount < 0) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`[next-advanced-sitemap] Invalid video view_count: ${finalViewCount}. View count cannot be negative.`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
xml += ` <video:view_count>${finalViewCount}</video:view_count>
|
|
139
161
|
`;
|
|
140
|
-
|
|
162
|
+
}
|
|
163
|
+
if (vid.live) {
|
|
164
|
+
xml += ` <video:live>${vid.live}</video:live>
|
|
141
165
|
`;
|
|
142
|
-
|
|
166
|
+
}
|
|
167
|
+
if (vid.restriction) {
|
|
168
|
+
if (!vid.restriction.countries || vid.restriction.countries.length === 0) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`[next-advanced-sitemap] Invalid video restriction: countries array cannot be empty.`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
const cleanCountries = vid.restriction.countries.map((country) => {
|
|
174
|
+
const code = country.trim().toUpperCase();
|
|
175
|
+
if (code.length < 2 || code.length > 3) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`[next-advanced-sitemap] Invalid ISO country code detected: "${country}". Must be a valid ISO 3166 code.`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
return code;
|
|
181
|
+
});
|
|
182
|
+
const countriesStr = cleanCountries.join(" ");
|
|
183
|
+
xml += ` <video:restriction relationship="${vid.restriction.relationship}">${countriesStr}</video:restriction>
|
|
143
184
|
`;
|
|
144
|
-
|
|
185
|
+
}
|
|
186
|
+
if (vid.platform) {
|
|
187
|
+
if (!vid.platform.platforms || vid.platform.platforms.length === 0) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`[next-advanced-sitemap] Invalid video platform: platforms array cannot be empty.`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
const validPlatforms = ["web", "mobile", "tv"];
|
|
193
|
+
for (const p of vid.platform.platforms) {
|
|
194
|
+
if (!validPlatforms.includes(p)) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`[next-advanced-sitemap] Invalid platform type: "${p}". Allowed values are 'web', 'mobile', or 'tv'.`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const platformsStr = vid.platform.platforms.join(" ");
|
|
201
|
+
xml += ` <video:platform relationship="${vid.platform.relationship}">${platformsStr}</video:platform>
|
|
145
202
|
`;
|
|
146
|
-
|
|
203
|
+
}
|
|
204
|
+
if (vid.requires_subscription !== void 0) {
|
|
205
|
+
let subValue;
|
|
206
|
+
if (typeof vid.requires_subscription === "boolean") {
|
|
207
|
+
subValue = vid.requires_subscription ? "yes" : "no";
|
|
208
|
+
} else if (vid.requires_subscription === "yes" || vid.requires_subscription === "no") {
|
|
209
|
+
subValue = vid.requires_subscription;
|
|
210
|
+
} else {
|
|
211
|
+
throw new Error(
|
|
212
|
+
`[next-advanced-sitemap] Invalid value for requires_subscription: "${vid.requires_subscription}". Expected boolean or strict string 'yes' | 'no'.`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
xml += ` <video:requires_subscription>${subValue}</video:requires_subscription>
|
|
147
216
|
`;
|
|
148
|
-
|
|
217
|
+
}
|
|
218
|
+
if (vid.price) {
|
|
219
|
+
const { value, currency, type } = vid.price;
|
|
220
|
+
if (value === void 0 || value < 0) {
|
|
221
|
+
throw new Error(
|
|
222
|
+
`[next-advanced-sitemap] Invalid video price value: "${value}". Value must be a positive number.`
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
const cleanCurrency = currency ? currency.trim().toUpperCase() : "";
|
|
226
|
+
if (cleanCurrency.length !== 3) {
|
|
227
|
+
throw new Error(
|
|
228
|
+
`[next-advanced-sitemap] Invalid ISO 4217 currency code: "${currency}". Currency must be exactly a 3-letter code.`
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
let priceXml = ` <video:price currency="${cleanCurrency}"`;
|
|
232
|
+
if (type) {
|
|
233
|
+
if (type !== "rent" && type !== "own") {
|
|
234
|
+
throw new Error(
|
|
235
|
+
`[next-advanced-sitemap] Invalid price type: "${type}". Allowed values are 'rent' or 'own'.`
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
priceXml += ` type="${type}"`;
|
|
239
|
+
}
|
|
240
|
+
priceXml += `>${value.toFixed(2)}</video:price>
|
|
149
241
|
`;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
242
|
+
xml += priceXml;
|
|
243
|
+
}
|
|
244
|
+
xml += ` </video:video>
|
|
153
245
|
`;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
246
|
+
}
|
|
247
|
+
return xml;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/core/builders/news-builder.ts
|
|
251
|
+
function buildNewsXml(news) {
|
|
252
|
+
if (!news) return "";
|
|
253
|
+
const nDate = news.publication_date instanceof Date ? news.publication_date.toISOString() : news.publication_date;
|
|
254
|
+
let xml = "";
|
|
255
|
+
xml += ` <news:news>
|
|
163
256
|
`;
|
|
164
|
-
|
|
165
|
-
if (vid.view_count !== void 0) {
|
|
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>
|
|
257
|
+
xml += ` <news:publication>
|
|
173
258
|
`;
|
|
174
|
-
}
|
|
175
|
-
if (vid.live) {
|
|
176
|
-
xml += ` <video:live>${vid.live}</video:live>
|
|
259
|
+
xml += ` <news:name>${escapeXml(news.name)}</news:name>
|
|
177
260
|
`;
|
|
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>
|
|
261
|
+
xml += ` <news:language>${escapeXml(news.language)}</news:language>
|
|
196
262
|
`;
|
|
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>
|
|
263
|
+
xml += ` </news:publication>
|
|
214
264
|
`;
|
|
215
|
-
|
|
216
|
-
xml += ` </video:video>
|
|
265
|
+
xml += ` <news:publication_date>${nDate}</news:publication_date>
|
|
217
266
|
`;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (entry.news) {
|
|
221
|
-
const nDate = entry.news.publication_date instanceof Date ? entry.news.publication_date.toISOString() : entry.news.publication_date;
|
|
222
|
-
xml += ` <news:news>
|
|
267
|
+
xml += ` <news:title>${escapeXml(news.title)}</news:title>
|
|
223
268
|
`;
|
|
224
|
-
|
|
269
|
+
xml += ` </news:news>
|
|
225
270
|
`;
|
|
226
|
-
|
|
271
|
+
return xml;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/core/generator.ts
|
|
275
|
+
function generateXml(entries, options = {}) {
|
|
276
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
277
|
+
let finalEntries = [...entries];
|
|
278
|
+
if (options.sortByPriority) {
|
|
279
|
+
finalEntries.sort((a, b) => {
|
|
280
|
+
const priorityA = a.priority !== void 0 ? a.priority : 0.5;
|
|
281
|
+
const priorityB = b.priority !== void 0 ? b.priority : 0.5;
|
|
282
|
+
return priorityB - priorityA;
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
let xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
227
286
|
`;
|
|
228
|
-
|
|
287
|
+
xml += `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
229
288
|
`;
|
|
230
|
-
|
|
289
|
+
xml += ` xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
|
|
231
290
|
`;
|
|
232
|
-
|
|
291
|
+
xml += ` xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
|
|
233
292
|
`;
|
|
234
|
-
|
|
293
|
+
xml += ` xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
|
|
235
294
|
`;
|
|
236
|
-
|
|
295
|
+
xml += ` xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
237
296
|
`;
|
|
238
|
-
|
|
297
|
+
for (const entry of finalEntries) {
|
|
298
|
+
xml += ` <url>
|
|
299
|
+
`;
|
|
300
|
+
xml += buildUrlBaseXml(entry, options, now);
|
|
301
|
+
xml += buildImageXml(entry.images);
|
|
302
|
+
xml += buildVideoXml(entry.videos);
|
|
303
|
+
xml += buildNewsXml(entry.news);
|
|
239
304
|
xml += ` </url>
|
|
240
305
|
`;
|
|
241
306
|
}
|
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.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,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A,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;;;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":[]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/xml-escape.ts","../src/core/builders/url-builder.ts","../src/core/builders/image-builder.ts","../src/core/builders/video-builder.ts","../src/core/builders/news-builder.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 */\nexport function 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 bloc XML de base pour un nœud URL (loc, alternates, lastmod, changefreq, priority).\n */\nexport function buildUrlBaseXml(entry: SitemapEntry, options: SitemapOptions, nowIso: string): string {\n let xml = '';\n \n const cleanMainUrl = sanitizeAndValidateUrl(entry.url, 'main entry');\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 = nowIso;\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 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 } from '../../types/sitemap.js';\nimport { escapeXml } from '../../utils/xml-escape.js';\nimport { sanitizeAndValidateUrl } from './url-builder.js';\n\nexport function buildImageXml(images: SitemapEntry['images']): string {\n if (!images?.length) return '';\n\n let xml = '';\n for (const img of 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 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 } from '../../types/sitemap.js';\nimport { escapeXml } from '../../utils/xml-escape.js';\nimport { sanitizeAndValidateUrl } from './url-builder.js';\n\nexport function buildVideoXml(videos: SitemapEntry['videos']): string {\n if (!videos?.length) return '';\n\n let xml = '';\n for (const vid of 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 // ✨ Validation et Sérialisation de la durée (0 - 28800s)\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 // ✨ Validation et Sérialisation du nombre de vues (>= 0)\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 if (vid.requires_subscription !== undefined) {\n let subValue: 'yes' | 'no';\n\n if (typeof vid.requires_subscription === 'boolean') {\n subValue = vid.requires_subscription ? 'yes' : 'no';\n } else if (vid.requires_subscription === 'yes' || vid.requires_subscription === 'no') {\n subValue = vid.requires_subscription;\n } else {\n throw new Error(\n `[next-advanced-sitemap] Invalid value for requires_subscription: \"${vid.requires_subscription}\". Expected boolean or strict string 'yes' | 'no'.`\n );\n }\n\n xml += ` <video:requires_subscription>${subValue}</video:requires_subscription>\\n`;\n }\n\n // ✨ Validation et Sérialisation des Prix et Achats (v1.1.6)\n if (vid.price) {\n const { value, currency, type } = vid.price;\n\n if (value === undefined || value < 0) {\n throw new Error(\n `[next-advanced-sitemap] Invalid video price value: \"${value}\". Value must be a positive number.`\n );\n }\n\n const cleanCurrency = currency ? currency.trim().toUpperCase() : '';\n if (cleanCurrency.length !== 3) {\n throw new Error(\n `[next-advanced-sitemap] Invalid ISO 4217 currency code: \"${currency}\". Currency must be exactly a 3-letter code.`\n );\n }\n\n let priceXml = ` <video:price currency=\"${cleanCurrency}\"`;\n if (type) {\n if (type !== 'rent' && type !== 'own') {\n throw new Error(\n `[next-advanced-sitemap] Invalid price type: \"${type}\". Allowed values are 'rent' or 'own'.`\n );\n }\n priceXml += ` type=\"${type}\"`;\n }\n priceXml += `>${value.toFixed(2)}</video:price>\\n`;\n \n xml += priceXml;\n }\n\n xml += ` </video:video>\\n`;\n }\n \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 } from '../../types/sitemap.js';\nimport { escapeXml } from '../../utils/xml-escape.js';\n\nexport function buildNewsXml(news: SitemapEntry['news']): string {\n if (!news) return '';\n\n const nDate = news.publication_date instanceof Date ? news.publication_date.toISOString() : news.publication_date;\n \n let xml = '';\n xml += ` <news:news>\\n`;\n xml += ` <news:publication>\\n`;\n xml += ` <news:name>${escapeXml(news.name)}</news:name>\\n`;\n xml += ` <news:language>${escapeXml(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(news.title)}</news:title>\\n`;\n xml += ` </news:news>\\n`;\n \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 { buildUrlBaseXml } from './builders/url-builder.js';\nimport { buildImageXml } from './builders/image-builder.js';\nimport { buildVideoXml } from './builders/video-builder.js';\nimport { buildNewsXml } from './builders/news-builder.js';\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 : Version découplée et hautement modulaire.\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 xml += ` <url>\\n`;\n \n // 1. Éléments de base et hreflang alternatifs\n xml += buildUrlBaseXml(entry, options, now);\n\n // 2. Extension Images Google\n xml += buildImageXml(entry.images);\n\n // 3. Extension Vidéos Google (Validations v1.1.3 & v1.1.4 intégrées)\n xml += buildVideoXml(entry.videos);\n\n // 4. Extension News Google\n xml += buildNewsXml(entry.news);\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;;;ACVO,SAAS,uBAAuB,QAAgB,SAAyB;AAC9E,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,GAAG;AACrB,UAAM,IAAI;AAAA,MACR,+DAA+D,OAAO,MAAM,GAAG;AAAA,IACjF;AAAA,EACF;AAEA,MAAI,UAAU;AACd,MAAI,OAAO,IAAI,aAAa,YAAY;AACtC,cAAU,IAAI,SAAS,GAAG;AAAA,EAC5B,OAAO;AACL,QAAI;AACF,UAAI,IAAI,GAAG;AACX,gBAAU;AAAA,IACZ,QAAQ;AACN,gBAAU;AAAA,IACZ;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;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;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.6",
|
|
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",
|