next-advanced-sitemap 1.1.0 → 1.1.2

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/LICENSE CHANGED
@@ -1,24 +1,24 @@
1
- FomaDev Public License (FPL)
2
-
3
- Copyright (c) 2026 FomaDev. All rights reserved.
4
-
5
- This license protects next-advanced-sitemap innovation while encouraging community collaboration.
6
-
7
- 1. Personal and Educational Use
8
- The use of the next-advanced-sitemap library is entirely free for developers and companies, including within commercial projects, as long as it is used as a dependency. You may integrate and use this tool in your websites or applications without any payment to FomaDev.
9
-
10
- 2. Contributions (Fork & Pull Request)
11
- Forks are authorized ONLY for contributing to the official FomaDev project. Any improvements, bug fixes, or new features must be submitted via a Pull Request to the original repository. By contributing, you agree that your code will be integrated under this same license.
12
-
13
- 3. Commercial Use and Competition (PAID)
14
- A paid commercial license is MANDATORY for the following cases:
15
- - Selling, redistributing, or sub-licensing the source code of this library.
16
- - Creating a derivative sitemap generation tool or library based on this source code.
17
- - Integrating this source code directly into another commercial library or framework intended for sale.
18
- - Building a paid "Sitemap as a Service" platform based on this specific engine.
19
-
20
- 4. Prohibition of Independent Forks
21
- Maintaining a separate version (permanent Fork) of this project to bypass FomaDev's authority or to create a competing package on registries (such as npm) is strictly prohibited.
22
-
23
- 5. Licensing Contact
1
+ FomaDev Public License (FPL)
2
+
3
+ Copyright (c) 2026 FomaDev. All rights reserved.
4
+
5
+ This license protects next-advanced-sitemap innovation while encouraging community collaboration.
6
+
7
+ 1. Personal and Educational Use
8
+ The use of the next-advanced-sitemap library is entirely free for developers and companies, including within commercial projects, as long as it is used as a dependency. You may integrate and use this tool in your websites or applications without any payment to FomaDev.
9
+
10
+ 2. Contributions (Fork & Pull Request)
11
+ Forks are authorized ONLY for contributing to the official FomaDev project. Any improvements, bug fixes, or new features must be submitted via a Pull Request to the original repository. By contributing, you agree that your code will be integrated under this same license.
12
+
13
+ 3. Commercial Use and Competition (PAID)
14
+ A paid commercial license is MANDATORY for the following cases:
15
+ - Selling, redistributing, or sub-licensing the source code of this library.
16
+ - Creating a derivative sitemap generation tool or library based on this source code.
17
+ - Integrating this source code directly into another commercial library or framework intended for sale.
18
+ - Building a paid "Sitemap as a Service" platform based on this specific engine.
19
+
20
+ 4. Prohibition of Independent Forks
21
+ Maintaining a separate version (permanent Fork) of this project to bypass FomaDev's authority or to create a competing package on registries (such as npm) is strictly prohibited.
22
+
23
+ 5. Licensing Contact
24
24
  To obtain commercial authorization, negotiate an exploitation license, or for any questions regarding professional use, contact Fordi (FomaDev) directly.
package/README.md CHANGED
@@ -1,212 +1,228 @@
1
- # next-advanced-sitemap
2
-
3
- A robust and type-safe sitemap generator for Next.js (App Router). This library extends standard sitemap capabilities by providing native support for Google-specific metadata including Images, Videos, News, and Internationalization (Hreflang).
4
-
5
- ## Overview
6
-
7
- While Next.js provides a built-in `MetadataRoute.Sitemap` utility, it currently lacks support for advanced SEO attributes required by high-performance web applications. `next-advanced-sitemap` bridges this gap, allowing developers to programmatically generate complex XML sitemaps that comply with Google's extended schemas.
8
-
9
- ## Features
10
-
11
- - **Google Images Support**: Index visual assets such as dashboard charts, infographics, and banners.
12
- - **Google Video Support**: Improve search visibility for video content with thumbnail and description metadata.
13
- - **Google News Support**: Comply with Google News requirements including publication names and dates.
14
- - **Internationalization**: Seamless integration of `xhtml:link` tags for Hreflang and multi-regional SEO.
15
- - **Priority Auto-Sorting (v1.0.8)**: Optional deterministic descending sort (`1.0` to `0.0`) based on entry weights to present your most strategic pages to crawlers first.
16
- - **Auto-Trimming Sanitization (v1.0.7)**: Automatic `.trim()` execution on all URL fields to silently correct leading/trailing whitespace errors from CMS or databases.
17
- - **Native Date Polymorphism (v1.0.6)**: Full support for native JavaScript `Date` objects inside Google News and Video extensions—no manual conversion required.
18
- - **Strict SEO Enum Typing (v1.0.5)**: Compile-time validation and IDE autocompletion for `changefreq` and `priority` values to prevent typos.
19
- - **Strict Structural Validation (v1.0.4)**: Advanced URL parsing using the platform-native engine to intercept syntax errors and unencoded whitespaces before deployment.
20
- - **Auto-lastmod (v1.0.3)**: Optional automatic injection of the current system date for entries missing a `lastmod` value.
21
- - **Advanced XML Escaping (v1.0.2)**: Enhanced processor to handle complex special characters (`&`, `"`, `'`, `<`, `>`) in SEO metadata, ensuring XML integrity.
22
- - **Developer Experience**: Fully typed with TypeScript, zero external dependencies, and optimized for Next.js Route Handlers.
23
- - **Custom TTL Cache-Control (v1.0.9)**: Direct control over sitemap caching persistence using a clean `maxAge` configuration option to lower crawl footprints on backend nodes.
24
- - **Local SEO & Image Licensing (v1.1.0)**: Enhanced Google Images schema integration with full support for `geo_location` and programmatic `license` badges to protect visual assets and boost image search CTR.
25
-
26
- ## Installation
27
-
28
- ```bash
29
- npm install next-advanced-sitemap
30
- ```
31
-
32
- ## Usage
33
-
34
- To implement an advanced sitemap in the Next.js App Router, create a Route Handler at `app/sitemap.xml/route.ts`.
35
-
36
- ```typescript
37
- import { getServerSitemapResponse, SitemapEntry } from 'next-advanced-sitemap';
38
-
39
- export async function GET() {
40
- const entries: SitemapEntry[] = [
41
- {
42
- url: ' https://fomadev.com ', // Auto-trimmed seamlessly in v1.0.7
43
- lastmod: new Date(),
44
- changefreq: 'daily', // Strictly typed
45
- priority: 1.0, // Auto-completed and strictly typed
46
- alternates: [
47
- { hreflang: 'fr', href: 'https://fomadev.com/fr' },
48
- { hreflang: 'en', href: 'https://fomadev.com/en' }
49
- ]
50
- },
51
- {
52
- url: 'https://fomadev.com/dashboard',
53
- priority: 0.8,
54
- images: [
55
- {
56
- loc: 'https://fomadev.com/charts/analytics.png',
57
- title: 'Growth Analytics Chart',
58
- caption: 'Visual representation of monthly user growth.'
59
- }
60
- ]
61
- },
62
- {
63
- url: 'https://fomadev.com/video-tutorial',
64
- priority: 0.6,
65
- videos: [
66
- {
67
- thumbnail_loc: 'https://fomadev.com/thumbs/tutorial.jpg',
68
- title: 'Next.js Advanced SEO Tutorial',
69
- description: 'Learn how to implement advanced sitemaps in Next.js & React.',
70
- publication_date: new Date('2026-05-25') // Accepts raw Date objects smoothly
71
- }
72
- ]
73
- }
74
- ];
75
-
76
- // Enable autoLastmod and sortByPriority (v1.0.8) to optimize crawl efficiency
77
- return getServerSitemapResponse(entries, {
78
- autoLastmod: true,
79
- sortByPriority: true
80
- });
81
- }
82
- ```
83
-
84
- ## API Reference
85
-
86
- ### getServerSitemapResponse(entries: SitemapEntry[], options?: SitemapOptions)
87
-
88
- Generates a standard Next.js `Response` object with the correct `application/xml` content-type and optimized cache headers.
89
-
90
- ### Options:
91
-
92
- * `autoLastmod` (boolean): If `true`, injects the current ISO date for any entry missing the `lastmod` property.
93
-
94
- * `sortByPriority` (boolean): If `true`, sorts the sitemap records in a descending sequence based on their priority level (`1.0` down to `0.0`) before writing the XML stream. Items without an explicit priority fall back safely to `0.5`.
95
-
96
- * `maxAge` (number): (Optional) Maximum lifespan duration expressed in seconds. Transforms the HTTP communication layer payload to use a rigid `public, max-age=X, must-revalidate` schema.
97
-
98
- ### SitemapEntry Object
99
-
100
- <table>
101
- <thead>
102
- <tr>
103
- <th>Property</th>
104
- <th>Type</th>
105
- <th>Description</th>
106
- </tr>
107
- </thead>
108
- <tbody>
109
- <tr>
110
- <td><code>url</code></td>
111
- <td class="type-label">string</td>
112
- <td>The absolute URL of the page (must start with <strong>http/https</strong>).</td>
113
- </tr>
114
- <tr>
115
- <td><code>lastmod</code></td>
116
- <td class="type-label">Date | string</td>
117
- <td>(Optional) Last modification date.</td>
118
- </tr>
119
- <tr>
120
- <td><code>changefreq</code></td>
121
- <td class="type-label">SitemapChangeFreq</td>
122
- <td>(Optional) Bounded search engine hint ('always', 'daily', etc.).</td>
123
- </tr>
124
- <tr>
125
- <td><code>priority</code></td>
126
- <td class="type-label">SitemapPriority</td>
127
- <td>(Optional) Bounded priority float value (0.0 to 1.0).</td>
128
- </tr>
129
- <tr>
130
- <td><code>images</code></td>
131
- <td class="type-label">SitemapImage[]</td>
132
- <td>(Optional) Array of image metadata for Google Images.</td>
133
- </tr>
134
- <tr>
135
- <td><code>videos</code></td>
136
- <td class="type-label">SitemapVideo[]</td>
137
- <td>(Optional) Array of video metadata for Google Videos.</td>
138
- </tr>
139
- <tr>
140
- <td><code>news</code></td>
141
- <td class="type-label">SitemapNews</td>
142
- <td>(Optional) Metadata for Google News indexing.</td>
143
- </tr>
144
- <tr>
145
- <td><code>alternates</code></td>
146
- <td class="type-label">SitemapAlternate[]</td>
147
- <td>(Optional) Regional alternate URLs (Hreflang).</td>
148
- </tr>
149
- <tr>
150
- <td><code>geo_location</code></td>
151
- <td class="type-label">string</td>
152
- <td>(Optional) Geographic location string of the image (e.g., "Kinshasa, DRC").</td>
153
- </tr>
154
- <tr>
155
- <td><code>license</code></td>
156
- <td class="type-label">string</td>
157
- <td>(Optional) Valid HTTP/HTTPS URL addressing the licensing rights or usage terms of the image asset.</td>
158
- </tr>
159
- </tbody>
160
- </table>
161
-
162
- ## Technical Implementation
163
-
164
- ### Priority Auto-Sorting
165
- Search engine crawlers allocate a finite scanning resource quota (crawl budget) when inspecting domain properties. By default, raw database queries or collection iterations generate un-ordered XML lists, causing indexers to process trivial nodes ahead of strategic content. When `sortByPriority` is enabled, the generation engine executes an immutable descending sorting operation. Unlabeled entries smoothly receive an RFC-compliant fallback baseline score of `0.5`, allowing top-tier entries to line up at the absolute top of the index file.
166
-
167
- ### Auto-Trimming & Ingestion Sanitization
168
-
169
- Distributed content pipelines frequently face issues with accidental leading spaces, trailing newlines, or indentation remnants introduced via headless CMS panels or Markdown document updates. To protect against application deployment errors caused by these invisible characters, the pipeline incorporates an automatic `.trim()` sanitization step. This layer cleans all input strings—including primary entries, alternative nodes, image endpoints, and video references—and passes the cleaned string directly down to the structural validation layer and the output XML stream.
170
-
171
- ### Native Date Polymorphism
172
-
173
- To simplify integrations with database mappers and modern ORMs (like Prisma, Supabase, or Mongoose) that output raw timestamps, the compiler implements native date polymorphism. Media structures (`SitemapNews` and `SitemapVideo`) accept both standard string layouts and full JavaScript `Date` instances. The internal pipeline evaluates instances using the `instanceof Date` boundary condition and automatically fires the `.toISOString()` handler when a native object is discovered, removing boilerplate conversion overhead.
174
-
175
- ### Compile-Time Parameter Guarding
176
-
177
- To avoid syntax typos breaking standard crawler schemas (e.g. accidentally writing `"dayly"` instead of `"daily"`), the library replaces generic primitive types with rigid evaluation layers:
178
-
179
- * **SitemapChangeFreq**: A literal string union restricting data ingestion exclusively to authorized keywords (`'always'` | `'hourly'` | `'daily'` | `'weekly'` | `'monthly'` | `'yearly'` | `'never'`).
180
-
181
- * **SitemapPriority**: A custom intersection schema offering direct autocomplete properties across decimal steps from `0.0` to `1.0` within modern code editors while retaining flexibility for precise custom float variables.
182
-
183
- ### Validation & Safety
184
-
185
- The library executes deterministic validation layers on all URL inputs:
186
-
187
- 1. **Protocol Match**: Enforces that all strings begin strictly with an absolute `http://` or `https://` prefix.
188
-
189
- 2. **Whitespace Interception**: Instantly isolates and rejects strings containing unencoded internal spaces.
190
-
191
- 3. **Structural Compliance**: Leverages the native `URL.canParse`() API (with a clean fallback mechanism to the `new URL()` constructor) to validate layout health.
192
-
193
-
194
- ### Advanced XML Security
195
-
196
- The engine includes an enhanced encoding processor. It automatically detects and escapes special characters within titles, descriptions, and captions to prevent XML layout corruption (e.g., `&` becomes `&amp;`, `<` becomes `&lt;`).
197
-
198
- ### Performance
199
-
200
- This library relies on an optimized string-building pattern to ensure minimal execution memory footprints, even when parsing deep multi-resource structures with thousands of entries.
201
-
202
- ## License
203
-
204
- This project is licensed under the [FomaDev Public License (FPL)](LICENSE).
205
-
206
- * **Free Use**: Authorized for personal and commercial projects as a dependency.
207
-
208
- * **[Contributions](CONTRIBUTING.md)**: Authorized via Pull Requests to the official repository only.
209
-
210
- * **Restrictions**: Independent forks, redistribution of source code, or building competing products based on this engine require a paid commercial license.
211
-
1
+ # next-advanced-sitemap
2
+
3
+ [![License: FPL](https://img.shields.io/badge/License-FPL-orange.svg)](LICENSE)
4
+ ![CI Status](https://github.com/fomadev/next-advanced-sitemap/actions/workflows/tests.yml/badge.svg)
5
+
6
+ A robust and type-safe sitemap generator for Next.js (App Router). This library extends standard sitemap capabilities by providing native support for Google-specific metadata including Images, Videos, News, and Internationalization (Hreflang).
7
+
8
+ ## Overview
9
+
10
+ While Next.js provides a built-in `MetadataRoute.Sitemap` utility, it currently lacks support for advanced SEO attributes required by high-performance web applications. `next-advanced-sitemap` bridges this gap, allowing developers to programmatically generate complex XML sitemaps that comply with Google's extended schemas.
11
+
12
+ ## Features
13
+
14
+ - **Google Images Support**: Index visual assets such as dashboard charts, infographics, and banners.
15
+ - **Image Accessibility & E-commerce Protection (v1.1.2)**: Advanced protection against empty text strings or white spaces (`.trim()`) in `title` and `caption` fields to prevent malformed XML tags, combined with robust escaping.
16
+ - **Google Video Support**: Improve search visibility for video content with thumbnail, description, and statistical metadata.
17
+ - **Video Engagement Metrics (v1.1.3 Preview)**: Secure structural injection of `<video:duration>` and `<video:view_count>` with automatic decimal truncation (`Math.floor`) to match Google requirements.
18
+ - **Google Video Live Streaming (v1.1.1)**: Native injection of the `<video:live>` parameter to flag real-time broadcasts and instantly trigger red **LIVE** badges on Google SERP matrices.
19
+ - **Google News Support**: Comply with Google News requirements including publication names and dates.
20
+ - **Internationalization**: Seamless integration of `xhtml:link` tags for Hreflang and multi-regional SEO.
21
+ - **Priority Auto-Sorting (v1.0.8)**: Optional deterministic descending sort (`1.0` to `0.0`) based on entry weights to present your most strategic pages to crawlers first.
22
+ - **Auto-Trimming Sanitization (v1.0.7)**: Automatic `.trim()` execution on all URL fields to silently correct leading/trailing whitespace errors from CMS or databases.
23
+ - **Native Date Polymorphism (v1.0.6)**: Full support for native JavaScript `Date` objects inside Google News and Video extensions—no manual conversion required.
24
+ - **Strict SEO Enum Typing (v1.0.5)**: Compile-time validation and IDE autocompletion for `changefreq` and `priority` values to prevent typos.
25
+ - **Strict Structural Validation (v1.0.4)**: Advanced URL parsing using the platform-native engine to intercept syntax errors and unencoded whitespaces before deployment.
26
+ - **Auto-lastmod (v1.0.3)**: Optional automatic injection of the current system date for entries missing a `lastmod` value.
27
+ - **Advanced XML Escaping (v1.0.2)**: Enhanced processor to handle complex special characters (`&`, `"`, `'`, `<`, `>`) in SEO metadata, ensuring XML integrity.
28
+ - **Developer Experience**: Fully typed with TypeScript, zero external dependencies, and optimized for Next.js Route Handlers.
29
+ - **Custom TTL Cache-Control (v1.0.9)**: Direct control over sitemap caching persistence using a clean `maxAge` configuration option to lower crawl footprints on backend nodes.
30
+ - **Local SEO & Image Licensing (v1.1.0)**: Enhanced Google Images schema integration with full support for `geo_location` and programmatic `license` badges to protect visual assets and boost image search CTR.
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ npm install next-advanced-sitemap
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ To implement an advanced sitemap in the Next.js App Router, create a Route Handler at `app/sitemap.xml/route.ts`.
41
+
42
+ ```typescript
43
+ import { getServerSitemapResponse, SitemapEntry } from 'next-advanced-sitemap';
44
+
45
+ export async function GET() {
46
+ const entries: SitemapEntry[] = [
47
+ {
48
+ url: ' https://fomadev.com ', // Auto-trimmed seamlessly in v1.0.7
49
+ lastmod: new Date(),
50
+ changefreq: 'daily', // Strictly typed
51
+ priority: 1.0, // Auto-completed and strictly typed
52
+ alternates: [
53
+ { hreflang: 'fr', href: 'https://fomadev.com/fr' },
54
+ { hreflang: 'en', href: 'https://fomadev.com/en' }
55
+ ]
56
+ },
57
+ {
58
+ url: 'https://fomadev.com/live-stream',
59
+ priority: 0.9,
60
+ videos: [
61
+ {
62
+ thumbnail_loc: 'https://fomadev.com/thumbs/live.jpg',
63
+ title: 'FomaDev Live Tech Session',
64
+ description: 'Building production-grade packages with Next.js.',
65
+ publication_date: new Date(),
66
+ live: 'yes' // v1.1.1: Triggers the official Google LIVE badge on SERP
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ url: 'https://fomadev.com/products/tech-item',
72
+ priority: 0.8,
73
+ images: [
74
+ {
75
+ loc: 'https://fomadev.com/images/product.png',
76
+ title: ' Premium Wireless Keyboard ', // v1.1.2: Auto-trimmed preventively
77
+ caption: 'Close-up shot of our custom mechanical keyboard layout with XML characters like & or <', // v1.1.2: Deep XML Escaping
78
+ geo_location: 'Kinshasa, Democratic Republic of the Congo', // v1.1.0 Local SEO
79
+ license: 'https://fomadev.com/terms/licensing' // v1.1.0 Badging
80
+ }
81
+ ]
82
+ }
83
+ ];
84
+
85
+ // Enable autoLastmod and sortByPriority (v1.0.8) to optimize crawl efficiency
86
+ return getServerSitemapResponse(entries, {
87
+ autoLastmod: true,
88
+ sortByPriority: true
89
+ });
90
+ }
91
+ ```
92
+
93
+ ## API Reference
94
+
95
+ ### getServerSitemapResponse(entries: SitemapEntry[], options?: SitemapOptions)
96
+
97
+ Generates a standard Next.js `Response` object with the correct `application/xml` content-type and optimized cache headers.
98
+
99
+ ### Options:
100
+
101
+ * `autoLastmod` (boolean): If `true`, injects the current ISO date for any entry missing the `lastmod` property.
102
+
103
+ * `sortByPriority` (boolean): If `true`, sorts the sitemap records in a descending sequence based on their priority level (`1.0` down to `0.0`) before writing the XML stream. Items without an explicit priority fall back safely to `0.5`.
104
+
105
+ * `maxAge` (number): (Optional) Maximum lifespan duration expressed in seconds. Transforms the HTTP communication layer payload to use a rigid `public, max-age=X, must-revalidate` schema.
106
+
107
+ ### SitemapEntry Object
108
+
109
+ <table>
110
+ <thead>
111
+ <tr>
112
+ <th>Property</th>
113
+ <th>Type</th>
114
+ <th>Description</th>
115
+ </tr>
116
+ </thead>
117
+ <tbody>
118
+ <tr>
119
+ <td><code>url</code></td>
120
+ <td class="type-label">string</td>
121
+ <td>The absolute URL of the page (must start with <strong>http/https</strong>).</td>
122
+ </tr>
123
+ <tr>
124
+ <td><code>lastmod</code></td>
125
+ <td class="type-label">Date | string</td>
126
+ <td>(Optional) Last modification date.</td>
127
+ </tr>
128
+ <tr>
129
+ <td><code>changefreq</code></td>
130
+ <td class="type-label">SitemapChangeFreq</td>
131
+ <td>(Optional) Bounded search engine hint ('always', 'daily', etc.).</td>
132
+ </tr>
133
+ <tr>
134
+ <td><code>priority</code></td>
135
+ <td class="type-label">SitemapPriority</td>
136
+ <td>(Optional) Bounded priority float value (0.0 to 1.0).</td>
137
+ </tr>
138
+ <tr>
139
+ <td><code>images</code></td>
140
+ <td class="type-label">SitemapImage[]</td>
141
+ <td>(Optional) Array of image metadata for Google Images.</td>
142
+ </tr>
143
+ <tr>
144
+ <td><code>videos</code></td>
145
+ <td class="type-label">SitemapVideo[]</td>
146
+ <td>(Optional) Array of video metadata for Google Videos.</td>
147
+ </tr>
148
+ <tr>
149
+ <td><code>news</code></td>
150
+ <td class="type-label">SitemapNews</td>
151
+ <td>(Optional) Metadata for Google News indexing.</td>
152
+ </tr>
153
+ <tr>
154
+ <td><code>alternates</code></td>
155
+ <td class="type-label">SitemapAlternate[]</td>
156
+ <td>(Optional) Regional alternate URLs (Hreflang).</td>
157
+ </tr>
158
+ <tr>
159
+ <td><code>geo_location</code></td>
160
+ <td class="type-label">string</td>
161
+ <td>(Optional) Geographic location string of the image (e.g., "Kinshasa, DRC").</td>
162
+ </tr>
163
+ <tr>
164
+ <td><code>license</code></td>
165
+ <td class="type-label">string</td>
166
+ <td>(Optional) Valid HTTP/HTTPS URL addressing the licensing rights or usage terms of the image asset.</td>
167
+ </tr>
168
+ </tbody>
169
+ </table>
170
+
171
+ ## Technical Implementation
172
+
173
+ ### Image Accessibility & E-commerce Protection
174
+ Large e-commerce platform backends or multi-vendor platforms frequently inject messy string data from user-generated fields—such as alternative text filled with raw spaces (`" "`) or unescaped description metadata containing special HTML entities (`&`, `<`, `>`). To achieve strict alignment with Googlebot accessibility schemas without risking layout parsing crashes, the engine implements a two-tier architectural protective filter in **v1.1.2**:
175
+
176
+ 1. **White Space Drop**: Every title, caption, and geographical entry is preventively processed using white-space reduction pipelines. Empty strings or lines composed only of white spaces are automatically stripped to avoid rendering dead, invalid `<image:title></image:title>` tokens.
177
+
178
+ 2. **Deep Meta-Escaping**: Extends the core encoding matrix down to visual metadata blocks. This ensures massive production payloads safely render special symbols without altering the global XML stream layout tree.
179
+
180
+ ### Priority Auto-Sorting
181
+ Search engine crawlers allocate a finite scanning resource quota (crawl budget) when inspecting domain properties. By default, raw database queries or collection iterations generate un-ordered XML lists, causing indexers to process trivial nodes ahead of strategic content. When `sortByPriority` is enabled, the generation engine executes an immutable descending sorting operation. Unlabeled entries smoothly receive an RFC-compliant fallback baseline score of `0.5`, allowing top-tier entries to line up at the absolute top of the index file.
182
+
183
+ ### Auto-Trimming & Ingestion Sanitization
184
+
185
+ Distributed content pipelines frequently face issues with accidental leading spaces, trailing newlines, or indentation remnants introduced via headless CMS panels or Markdown document updates. To protect against application deployment errors caused by these invisible characters, the pipeline incorporates an automatic `.trim()` sanitization step. This layer cleans all input strings—including primary entries, alternative nodes, image endpoints, and video references—and passes the cleaned string directly down to the structural validation layer and the output XML stream.
186
+
187
+ ### Native Date Polymorphism
188
+
189
+ To simplify integrations with database mappers and modern ORMs (like Prisma, Supabase, or Mongoose) that output raw timestamps, the compiler implements native date polymorphism. Media structures (`SitemapNews` and `SitemapVideo`) accept both standard string layouts and full JavaScript `Date` instances. The internal pipeline evaluates instances using the `instanceof Date` boundary condition and automatically fires the `.toISOString()` handler when a native object is discovered, removing boilerplate conversion overhead.
190
+
191
+ ### Compile-Time Parameter Guarding
192
+
193
+ To avoid syntax typos breaking standard crawler schemas (e.g. accidentally writing `"dayly"` instead of `"daily"`), the library replaces generic primitive types with rigid evaluation layers:
194
+
195
+ * **SitemapChangeFreq**: A literal string union restricting data ingestion exclusively to authorized keywords (`'always'` | `'hourly'` | `'daily'` | `'weekly'` | `'monthly'` | `'yearly'` | `'never'`).
196
+
197
+ * **SitemapPriority**: A custom intersection schema offering direct autocomplete properties across decimal steps from `0.0` to `1.0` within modern code editors while retaining flexibility for precise custom float variables.
198
+
199
+ ### Validation & Safety
200
+
201
+ The library executes deterministic validation layers on all URL inputs:
202
+
203
+ 1. **Protocol Match**: Enforces that all strings begin strictly with an absolute `http://` or `https://` prefix.
204
+
205
+ 2. **Whitespace Interception**: Instantly isolates and rejects strings containing unencoded internal spaces.
206
+
207
+ 3. **Structural Compliance**: Leverages the native `URL.canParse`() API (with a clean fallback mechanism to the `new URL()` constructor) to validate layout health.
208
+
209
+
210
+ ### Advanced XML Security
211
+
212
+ The engine includes an enhanced encoding processor. It automatically detects and escapes special characters within titles, descriptions, and captions to prevent XML layout corruption (e.g., `&` becomes `&amp;`, `<` becomes `&lt;`).
213
+
214
+ ### Performance
215
+
216
+ This library relies on an optimized string-building pattern to ensure minimal execution memory footprints, even when parsing deep multi-resource structures with thousands of entries.
217
+
218
+ ## License
219
+
220
+ This project is licensed under the [FomaDev Public License (FPL)](LICENSE).
221
+
222
+ * **Free Use**: Authorized for personal and commercial projects as a dependency.
223
+
224
+ * **[Contributions](CONTRIBUTING.md)**: Authorized via Pull Requests to the official repository only.
225
+
226
+ * **Restrictions**: Independent forks, redistribution of source code, or building competing products based on this engine require a paid commercial license.
227
+
212
228
  See the [LICENSE](LICENSE) file for the full legal text.
package/dist/index.cjs CHANGED
@@ -135,12 +135,16 @@ function generateXml(entries, options = {}) {
135
135
  `;
136
136
  xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>
137
137
  `;
138
- if (img.title) xml += ` <image:title>${escapeXml(img.title)}</image:title>
138
+ if (img.title && img.title.trim() !== "") {
139
+ xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>
139
140
  `;
140
- if (img.caption) xml += ` <image:caption>${escapeXml(img.caption)}</image:caption>
141
+ }
142
+ if (img.caption && img.caption.trim() !== "") {
143
+ xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>
141
144
  `;
142
- if (img.geo_location) {
143
- xml += ` <image:geo_location>${escapeXml(img.geo_location)}</image:geo_location>
145
+ }
146
+ if (img.geo_location && img.geo_location.trim() !== "") {
147
+ xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>
144
148
  `;
145
149
  }
146
150
  if (img.license) {
@@ -172,6 +176,18 @@ function generateXml(entries, options = {}) {
172
176
  if (vid.publication_date) {
173
177
  const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;
174
178
  xml += ` <video:publication_date>${vDate}</video:publication_date>
179
+ `;
180
+ }
181
+ if (vid.duration !== void 0) {
182
+ xml += ` <video:duration>${Math.floor(vid.duration)}</video:duration>
183
+ `;
184
+ }
185
+ if (vid.view_count !== void 0) {
186
+ xml += ` <video:view_count>${Math.floor(vid.view_count)}</video:view_count>
187
+ `;
188
+ }
189
+ if (vid.live) {
190
+ xml += ` <video:live>${vid.live}</video:live>
175
191
  `;
176
192
  }
177
193
  xml += ` </video:video>
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/utils/xml-escape.ts","../src/core/generator.ts"],"sourcesContent":["/* * Copyright (c) 2026 Fordi / FomaDev. \r\n * Licensed under FomaDev Public License.\r\n * See LICENSE file in the project root for full license information.\r\n */\r\n\r\nimport { SitemapEntry, SitemapOptions } from './types/sitemap.js';\r\nimport { generateXml } from './core/generator.js';\r\n\r\nexport * from './types/sitemap.js';\r\n\r\n/**\r\n * Génère une réponse HTTP compatible Next.js (App Router) avec options de configuration.\r\n * v1.0.9 : Injection dynamique et personnalisable de l'en-tête Cache-Control via l'option maxAge\r\n * * @param entries - Liste des entrées du sitemap\r\n * @param options - Options de génération et de mise en cache (ex: autoLastmod, maxAge)\r\n * @returns Une instance de Response contenant le flux XML configuré\r\n */\r\nexport function getServerSitemapResponse(\r\n entries: SitemapEntry[], \r\n options: SitemapOptions = {}\r\n): Response {\r\n const xml = generateXml(entries, options);\r\n\r\n // Détermination de la stratégie de mise en cache (v1.0.9)\r\n const cacheControlHeader = options.maxAge !== undefined\r\n ? `public, max-age=${options.maxAge}, must-revalidate`\r\n : 'public, s-maxage=86400, stale-while-revalidate';\r\n\r\n return new Response(xml, {\r\n headers: {\r\n 'Content-Type': 'application/xml',\r\n 'Cache-Control': cacheControlHeader,\r\n },\r\n });\r\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \r\n * Licensed under FomaDev Public License.\r\n * See LICENSE file in the project root for full license information.\r\n */\r\n\r\n/**\r\n * Convertit les caractères spéciaux en entités XML pour éviter la corruption du fichier.\r\n * Gère : <, >, &, \", '\r\n */\r\nexport function escapeXml(unsafe: string | undefined | null): string {\r\n if (!unsafe) return '';\r\n \r\n return unsafe.replace(/[<>&\"']/g, (c) => {\r\n switch (c) {\r\n case '<': return '&lt;';\r\n case '>': return '&gt;';\r\n case '&': return '&amp;';\r\n case '\"': return '&quot;';\r\n case \"'\": return '&apos;';\r\n default: return c;\r\n }\r\n });\r\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \r\n * Licensed under FomaDev Public License.\r\n * See LICENSE file in the project root for full license information.\r\n */\r\n\r\nimport { SitemapEntry, SitemapOptions } from '../types/sitemap.js';\r\nimport { escapeXml } from '../utils/xml-escape.js';\r\n\r\n/**\r\n * Nettoie et valide de manière stricte le format et la structure d'une URL.\r\n * v1.0.7 : Intégration de l'Auto-Trimming (nettoyage des espaces de début et de fin)\r\n */\r\nfunction sanitizeAndValidateUrl(rawUrl: string, context: string): string {\r\n const url = rawUrl ? rawUrl.trim() : '';\r\n\r\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\r\n throw new Error(\r\n `[next-advanced-sitemap] Invalid URL in ${context}: \"${url}\". URLs must start with http:// or https://`\r\n );\r\n }\r\n\r\n if (url.includes(' ')) {\r\n throw new Error(\r\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\r\n );\r\n }\r\n\r\n let isValid = false;\r\n if (typeof URL.canParse === 'function') {\r\n isValid = URL.canParse(url);\r\n } else {\r\n try {\r\n new URL(url);\r\n isValid = true;\r\n } catch {\r\n isValid = false;\r\n }\r\n }\r\n\r\n if (!isValid) {\r\n throw new Error(\r\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\r\n );\r\n }\r\n\r\n return url;\r\n}\r\n\r\n/**\r\n * Génère le flux XML complet du sitemap incluant les extensions Images, Vidéos, News et Hreflang.\r\n * v1.1.0 : Prise en charge des attributs étendus <image:geo_location> et <image:license>\r\n */\r\nexport function generateXml(entries: SitemapEntry[], options: SitemapOptions = {}): string {\r\n const now = new Date().toISOString();\r\n let finalEntries = [...entries];\r\n\r\n if (options.sortByPriority) {\r\n finalEntries.sort((a, b) => {\r\n const priorityA = a.priority !== undefined ? (a.priority as number) : 0.5;\r\n const priorityB = b.priority !== undefined ? (b.priority as number) : 0.5;\r\n return priorityB - priorityA;\r\n });\r\n }\r\n \r\n let xml = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n`;\r\n xml += `<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\\n`;\r\n xml += ` xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"\\n`;\r\n xml += ` xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\"\\n`;\r\n xml += ` xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\"\\n`;\r\n xml += ` xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\\n`;\r\n\r\n for (const entry of finalEntries) {\r\n const cleanMainUrl = sanitizeAndValidateUrl(entry.url, 'main entry');\r\n\r\n xml += ` <url>\\n`;\r\n xml += ` <loc>${escapeXml(cleanMainUrl)}</loc>\\n`;\r\n\r\n if (entry.alternates?.length) {\r\n for (const alt of entry.alternates) {\r\n const cleanAltUrl = sanitizeAndValidateUrl(alt.href, 'alternate link');\r\n xml += ` <xhtml:link rel=\"alternate\" hreflang=\"${escapeXml(alt.hreflang)}\" href=\"${escapeXml(cleanAltUrl)}\" />\\n`;\r\n }\r\n }\r\n\r\n let lastmodValue = entry.lastmod;\r\n if (options.autoLastmod && !lastmodValue) {\r\n lastmodValue = now;\r\n }\r\n\r\n if (lastmodValue) {\r\n const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;\r\n xml += ` <lastmod>${date}</lastmod>\\n`;\r\n }\r\n\r\n if (entry.changefreq) {\r\n xml += ` <changefreq>${entry.changefreq}</changefreq>\\n`;\r\n }\r\n\r\n if (entry.priority !== undefined) {\r\n xml += ` <priority>${(entry.priority as number).toFixed(1)}</priority>\\n`;\r\n }\r\n\r\n // Extension Images - enrichie en v1.1.0\r\n if (entry.images?.length) {\r\n for (const img of entry.images) {\r\n const cleanImgUrl = sanitizeAndValidateUrl(img.loc, 'image location');\r\n \r\n xml += ` <image:image>\\n`;\r\n xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>\\n`;\r\n if (img.title) xml += ` <image:title>${escapeXml(img.title)}</image:title>\\n`;\r\n if (img.caption) xml += ` <image:caption>${escapeXml(img.caption)}</image:caption>\\n`;\r\n \r\n // SEO Local v1.1.0\r\n if (img.geo_location) {\r\n xml += ` <image:geo_location>${escapeXml(img.geo_location)}</image:geo_location>\\n`;\r\n }\r\n \r\n // Gestion des Licences Google Images v1.1.0\r\n if (img.license) {\r\n const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, 'image license URL');\r\n xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>\\n`;\r\n }\r\n \r\n xml += ` </image:image>\\n`;\r\n }\r\n }\r\n\r\n // Extension Vidéos\r\n if (entry.videos?.length) {\r\n for (const vid of entry.videos) {\r\n const cleanThumbLoc = sanitizeAndValidateUrl(vid.thumbnail_loc, 'video thumbnail');\r\n const cleanContentLoc = vid.content_loc ? sanitizeAndValidateUrl(vid.content_loc, 'video content location') : undefined;\r\n const cleanPlayerLoc = vid.player_loc ? sanitizeAndValidateUrl(vid.player_loc, 'video player location') : undefined;\r\n\r\n xml += ` <video:video>\\n`;\r\n xml += ` <video:thumbnail_loc>${escapeXml(cleanThumbLoc)}</video:thumbnail_loc>\\n`;\r\n xml += ` <video:title>${escapeXml(vid.title)}</video:title>\\n`;\r\n xml += ` <video:description>${escapeXml(vid.description)}</video:description>\\n`;\r\n \r\n if (cleanContentLoc) xml += ` <video:content_loc>${escapeXml(cleanContentLoc)}</video:content_loc>\\n`;\r\n if (cleanPlayerLoc) xml += ` <video:player_loc>${escapeXml(cleanPlayerLoc)}</video:player_loc>\\n`;\r\n \r\n if (vid.publication_date) {\r\n const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;\r\n xml += ` <video:publication_date>${vDate}</video:publication_date>\\n`;\r\n }\r\n xml += ` </video:video>\\n`;\r\n }\r\n }\r\n\r\n // Extension News\r\n if (entry.news) {\r\n const nDate = entry.news.publication_date instanceof Date ? entry.news.publication_date.toISOString() : entry.news.publication_date;\r\n xml += ` <news:news>\\n`;\r\n xml += ` <news:publication>\\n`;\r\n xml += ` <news:name>${escapeXml(entry.news.name)}</news:name>\\n`;\r\n xml += ` <news:language>${escapeXml(entry.news.language)}</news:language>\\n`;\r\n xml += ` </news:publication>\\n`;\r\n xml += ` <news:publication_date>${nDate}</news:publication_date>\\n`;\r\n xml += ` <news:title>${escapeXml(entry.news.title)}</news:title>\\n`;\r\n xml += ` </news:news>\\n`;\r\n }\r\n\r\n xml += ` </url>\\n`;\r\n }\r\n\r\n xml += `</urlset>`;\r\n return xml;\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,SAAS,UAAU,QAA2C;AACnE,MAAI,CAAC,OAAQ,QAAO;AAEpB,SAAO,OAAO,QAAQ,YAAY,CAAC,MAAM;AACvC,YAAQ,GAAG;AAAA,MACT,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB;AAAS,eAAO;AAAA,IAClB;AAAA,EACF,CAAC;AACH;;;ACVA,SAAS,uBAAuB,QAAgB,SAAyB;AACvE,QAAM,MAAM,SAAS,OAAO,KAAK,IAAI;AAErC,MAAI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AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/utils/xml-escape.ts","../src/core/generator.ts"],"sourcesContent":["/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from './types/sitemap.js';\nimport { generateXml } from './core/generator.js';\n\nexport * from './types/sitemap.js';\n\n/**\n * Génère une réponse HTTP compatible Next.js (App Router) avec options de configuration.\n * v1.0.9 : Injection dynamique et personnalisable de l'en-tête Cache-Control via l'option maxAge\n * * @param entries - Liste des entrées du sitemap\n * @param options - Options de génération et de mise en cache (ex: autoLastmod, maxAge)\n * @returns Une instance de Response contenant le flux XML configuré\n */\nexport function getServerSitemapResponse(\n entries: SitemapEntry[], \n options: SitemapOptions = {}\n): Response {\n const xml = generateXml(entries, options);\n\n // Détermination de la stratégie de mise en cache (v1.0.9)\n const cacheControlHeader = options.maxAge !== undefined\n ? `public, max-age=${options.maxAge}, must-revalidate`\n : 'public, s-maxage=86400, stale-while-revalidate';\n\n return new Response(xml, {\n headers: {\n 'Content-Type': 'application/xml',\n 'Cache-Control': cacheControlHeader,\n },\n });\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\n/**\n * Convertit les caractères spéciaux en entités XML pour éviter la corruption du fichier.\n * Gère : <, >, &, \", '\n */\nexport function escapeXml(unsafe: string | undefined | null): string {\n if (!unsafe) return '';\n \n return unsafe.replace(/[<>&\"']/g, (c) => {\n switch (c) {\n case '<': return '&lt;';\n case '>': return '&gt;';\n case '&': return '&amp;';\n case '\"': return '&quot;';\n case \"'\": return '&apos;';\n default: return c;\n }\n });\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from '../types/sitemap.js';\nimport { escapeXml } from '../utils/xml-escape.js';\n\n/**\n * Nettoie et valide de manière stricte le format et la structure d'une URL.\n * v1.0.7 : Intégration de l'Auto-Trimming (nettoyage des espaces de début et de fin)\n */\nfunction sanitizeAndValidateUrl(rawUrl: string, context: string): string {\n const url = rawUrl ? rawUrl.trim() : '';\n\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\n throw new Error(\n `[next-advanced-sitemap] Invalid URL in ${context}: \"${url}\". URLs must start with http:// or https://`\n );\n }\n\n if (url.includes(' ')) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n let isValid = false;\n if (typeof URL.canParse === 'function') {\n isValid = URL.canParse(url);\n } else {\n try {\n new URL(url);\n isValid = true;\n } catch {\n isValid = false;\n }\n }\n\n if (!isValid) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n return url;\n}\n\n/**\n * Génère le flux XML complet du sitemap incluant les extensions Images, Vidéos, News et Hreflang.\n * v1.1.2 : Métadonnées d'Accessibilité Images (caption & title optionnels, renforcés et nettoyés)\n * + Support sécurisé des statistiques vidéo (duration & view_count)\n */\nexport function generateXml(entries: SitemapEntry[], options: SitemapOptions = {}): string {\n const now = new Date().toISOString();\n let finalEntries = [...entries];\n\n if (options.sortByPriority) {\n finalEntries.sort((a, b) => {\n const priorityA = a.priority !== undefined ? (a.priority as number) : 0.5;\n const priorityB = b.priority !== undefined ? (b.priority as number) : 0.5;\n return priorityB - priorityA;\n });\n }\n \n let xml = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n`;\n xml += `<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\\n`;\n xml += ` xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"\\n`;\n xml += ` xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\"\\n`;\n xml += ` xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\"\\n`;\n xml += ` xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\\n`;\n\n for (const entry of finalEntries) {\n const cleanMainUrl = sanitizeAndValidateUrl(entry.url, 'main entry');\n\n xml += ` <url>\\n`;\n xml += ` <loc>${escapeXml(cleanMainUrl)}</loc>\\n`;\n\n if (entry.alternates?.length) {\n for (const alt of entry.alternates) {\n const cleanAltUrl = sanitizeAndValidateUrl(alt.href, 'alternate link');\n xml += ` <xhtml:link rel=\"alternate\" hreflang=\"${escapeXml(alt.hreflang)}\" href=\"${escapeXml(cleanAltUrl)}\" />\\n`;\n }\n }\n\n let lastmodValue = entry.lastmod;\n if (options.autoLastmod && !lastmodValue) {\n lastmodValue = now;\n }\n\n if (lastmodValue) {\n const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;\n xml += ` <lastmod>${date}</lastmod>\\n`;\n }\n\n if (entry.changefreq) {\n xml += ` <changefreq>${entry.changefreq}</changefreq>\\n`;\n }\n\n if (entry.priority !== undefined) {\n xml += ` <priority>${(entry.priority as number).toFixed(1)}</priority>\\n`;\n }\n\n // Extension Images - v1.1.2 renforcée\n if (entry.images?.length) {\n for (const img of entry.images) {\n const cleanImgUrl = sanitizeAndValidateUrl(img.loc, 'image location');\n \n xml += ` <image:image>\\n`;\n xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>\\n`;\n \n // ✨ v1.1.2 : .trim() préventif pour s'assurer qu'un texte blanc ne crée pas de balise invalide\n if (img.title && img.title.trim() !== '') {\n xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>\\n`;\n }\n if (img.caption && img.caption.trim() !== '') {\n xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>\\n`;\n }\n \n // SEO Local\n if (img.geo_location && img.geo_location.trim() !== '') {\n xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>\\n`;\n }\n \n // Gestion des Licences Google Images\n if (img.license) {\n const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, 'image license URL');\n xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>\\n`;\n }\n \n xml += ` </image:image>\\n`;\n }\n }\n\n // Extension Vidéos\n if (entry.videos?.length) {\n for (const vid of entry.videos) {\n const cleanThumbLoc = sanitizeAndValidateUrl(vid.thumbnail_loc, 'video thumbnail');\n const cleanContentLoc = vid.content_loc ? sanitizeAndValidateUrl(vid.content_loc, 'video content location') : undefined;\n const cleanPlayerLoc = vid.player_loc ? sanitizeAndValidateUrl(vid.player_loc, 'video player location') : undefined;\n\n xml += ` <video:video>\\n`;\n xml += ` <video:thumbnail_loc>${escapeXml(cleanThumbLoc)}</video:thumbnail_loc>\\n`;\n xml += ` <video:title>${escapeXml(vid.title)}</video:title>\\n`;\n xml += ` <video:description>${escapeXml(vid.description)}</video:description>\\n`;\n \n if (cleanContentLoc) xml += ` <video:content_loc>${escapeXml(cleanContentLoc)}</video:content_loc>\\n`;\n if (cleanPlayerLoc) xml += ` <video:player_loc>${escapeXml(cleanPlayerLoc)}</video:player_loc>\\n`;\n \n if (vid.publication_date) {\n const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;\n xml += ` <video:publication_date>${vDate}</video:publication_date>\\n`;\n }\n\n // Métadonnées de statistiques (v1.1.3 - Préparé et sécurisé)\n if (vid.duration !== undefined) {\n xml += ` <video:duration>${Math.floor(vid.duration)}</video:duration>\\n`;\n }\n if (vid.view_count !== undefined) {\n xml += ` <video:view_count>${Math.floor(vid.view_count)}</video:view_count>\\n`;\n }\n\n // Support du Live Streaming v1.1.1\n if (vid.live) {\n xml += ` <video:live>${vid.live}</video:live>\\n`;\n }\n\n xml += ` </video:video>\\n`;\n }\n }\n\n // Extension News\n if (entry.news) {\n const nDate = entry.news.publication_date instanceof Date ? entry.news.publication_date.toISOString() : entry.news.publication_date;\n xml += ` <news:news>\\n`;\n xml += ` <news:publication>\\n`;\n xml += ` <news:name>${escapeXml(entry.news.name)}</news:name>\\n`;\n xml += ` <news:language>${escapeXml(entry.news.language)}</news:language>\\n`;\n xml += ` </news:publication>\\n`;\n xml += ` <news:publication_date>${nDate}</news:publication_date>\\n`;\n xml += ` <news:title>${escapeXml(entry.news.title)}</news:title>\\n`;\n xml += ` </news:news>\\n`;\n }\n\n xml += ` </url>\\n`;\n }\n\n xml += `</urlset>`;\n return xml;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,SAAS,UAAU,QAA2C;AACnE,MAAI,CAAC,OAAQ,QAAO;AAEpB,SAAO,OAAO,QAAQ,YAAY,CAAC,MAAM;AACvC,YAAQ,GAAG;AAAA,MACT,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB;AAAS,eAAO;AAAA,IAClB;AAAA,EACF,CAAC;AACH;;;ACVA,SAAS,uBAAuB,QAAgB,SAAyB;AACvE,QAAM,MAAM,SAAS,OAAO,KAAK,IAAI;AAErC,MAAI,CAAC,IAAI,WAAW,SAAS,KAAK,CAAC,IAAI,WAAW,UAAU,GAAG;AAC7D,UAAM,IAAI;AAAA,MACR,0CAA0C,OAAO,MAAM,GAAG;AAAA,IAC5D;AAAA,EACF;AAEA,MAAI,IAAI,SAAS,GAAG,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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B,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
package/dist/index.d.cts CHANGED
@@ -43,6 +43,8 @@ interface SitemapVideo {
43
43
  view_count?: number;
44
44
  publication_date?: Date | string;
45
45
  family_friendly?: 'yes' | 'no';
46
+ /** (Optional) v1.1.1: Indique si la vidéo est une diffusion en direct ('yes' ou 'no'). */
47
+ live?: 'yes' | 'no';
46
48
  }
47
49
  /**
48
50
  * Interface pour Google News
package/dist/index.d.ts CHANGED
@@ -43,6 +43,8 @@ interface SitemapVideo {
43
43
  view_count?: number;
44
44
  publication_date?: Date | string;
45
45
  family_friendly?: 'yes' | 'no';
46
+ /** (Optional) v1.1.1: Indique si la vidéo est une diffusion en direct ('yes' ou 'no'). */
47
+ live?: 'yes' | 'no';
46
48
  }
47
49
  /**
48
50
  * Interface pour Google News
package/dist/index.js CHANGED
@@ -109,12 +109,16 @@ function generateXml(entries, options = {}) {
109
109
  `;
110
110
  xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>
111
111
  `;
112
- if (img.title) xml += ` <image:title>${escapeXml(img.title)}</image:title>
112
+ if (img.title && img.title.trim() !== "") {
113
+ xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>
113
114
  `;
114
- if (img.caption) xml += ` <image:caption>${escapeXml(img.caption)}</image:caption>
115
+ }
116
+ if (img.caption && img.caption.trim() !== "") {
117
+ xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>
115
118
  `;
116
- if (img.geo_location) {
117
- xml += ` <image:geo_location>${escapeXml(img.geo_location)}</image:geo_location>
119
+ }
120
+ if (img.geo_location && img.geo_location.trim() !== "") {
121
+ xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>
118
122
  `;
119
123
  }
120
124
  if (img.license) {
@@ -146,6 +150,18 @@ function generateXml(entries, options = {}) {
146
150
  if (vid.publication_date) {
147
151
  const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;
148
152
  xml += ` <video:publication_date>${vDate}</video:publication_date>
153
+ `;
154
+ }
155
+ if (vid.duration !== void 0) {
156
+ xml += ` <video:duration>${Math.floor(vid.duration)}</video:duration>
157
+ `;
158
+ }
159
+ if (vid.view_count !== void 0) {
160
+ xml += ` <video:view_count>${Math.floor(vid.view_count)}</video:view_count>
161
+ `;
162
+ }
163
+ if (vid.live) {
164
+ xml += ` <video:live>${vid.live}</video:live>
149
165
  `;
150
166
  }
151
167
  xml += ` </video:video>
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/xml-escape.ts","../src/core/generator.ts","../src/index.ts"],"sourcesContent":["/* * Copyright (c) 2026 Fordi / FomaDev. \r\n * Licensed under FomaDev Public License.\r\n * See LICENSE file in the project root for full license information.\r\n */\r\n\r\n/**\r\n * Convertit les caractères spéciaux en entités XML pour éviter la corruption du fichier.\r\n * Gère : <, >, &, \", '\r\n */\r\nexport function escapeXml(unsafe: string | undefined | null): string {\r\n if (!unsafe) return '';\r\n \r\n return unsafe.replace(/[<>&\"']/g, (c) => {\r\n switch (c) {\r\n case '<': return '&lt;';\r\n case '>': return '&gt;';\r\n case '&': return '&amp;';\r\n case '\"': return '&quot;';\r\n case \"'\": return '&apos;';\r\n default: return c;\r\n }\r\n });\r\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \r\n * Licensed under FomaDev Public License.\r\n * See LICENSE file in the project root for full license information.\r\n */\r\n\r\nimport { SitemapEntry, SitemapOptions } from '../types/sitemap.js';\r\nimport { escapeXml } from '../utils/xml-escape.js';\r\n\r\n/**\r\n * Nettoie et valide de manière stricte le format et la structure d'une URL.\r\n * v1.0.7 : Intégration de l'Auto-Trimming (nettoyage des espaces de début et de fin)\r\n */\r\nfunction sanitizeAndValidateUrl(rawUrl: string, context: string): string {\r\n const url = rawUrl ? rawUrl.trim() : '';\r\n\r\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\r\n throw new Error(\r\n `[next-advanced-sitemap] Invalid URL in ${context}: \"${url}\". URLs must start with http:// or https://`\r\n );\r\n }\r\n\r\n if (url.includes(' ')) {\r\n throw new Error(\r\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\r\n );\r\n }\r\n\r\n let isValid = false;\r\n if (typeof URL.canParse === 'function') {\r\n isValid = URL.canParse(url);\r\n } else {\r\n try {\r\n new URL(url);\r\n isValid = true;\r\n } catch {\r\n isValid = false;\r\n }\r\n }\r\n\r\n if (!isValid) {\r\n throw new Error(\r\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\r\n );\r\n }\r\n\r\n return url;\r\n}\r\n\r\n/**\r\n * Génère le flux XML complet du sitemap incluant les extensions Images, Vidéos, News et Hreflang.\r\n * v1.1.0 : Prise en charge des attributs étendus <image:geo_location> et <image:license>\r\n */\r\nexport function generateXml(entries: SitemapEntry[], options: SitemapOptions = {}): string {\r\n const now = new Date().toISOString();\r\n let finalEntries = [...entries];\r\n\r\n if (options.sortByPriority) {\r\n finalEntries.sort((a, b) => {\r\n const priorityA = a.priority !== undefined ? (a.priority as number) : 0.5;\r\n const priorityB = b.priority !== undefined ? (b.priority as number) : 0.5;\r\n return priorityB - priorityA;\r\n });\r\n }\r\n \r\n let xml = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n`;\r\n xml += `<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\\n`;\r\n xml += ` xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"\\n`;\r\n xml += ` xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\"\\n`;\r\n xml += ` xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\"\\n`;\r\n xml += ` xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\\n`;\r\n\r\n for (const entry of finalEntries) {\r\n const cleanMainUrl = sanitizeAndValidateUrl(entry.url, 'main entry');\r\n\r\n xml += ` <url>\\n`;\r\n xml += ` <loc>${escapeXml(cleanMainUrl)}</loc>\\n`;\r\n\r\n if (entry.alternates?.length) {\r\n for (const alt of entry.alternates) {\r\n const cleanAltUrl = sanitizeAndValidateUrl(alt.href, 'alternate link');\r\n xml += ` <xhtml:link rel=\"alternate\" hreflang=\"${escapeXml(alt.hreflang)}\" href=\"${escapeXml(cleanAltUrl)}\" />\\n`;\r\n }\r\n }\r\n\r\n let lastmodValue = entry.lastmod;\r\n if (options.autoLastmod && !lastmodValue) {\r\n lastmodValue = now;\r\n }\r\n\r\n if (lastmodValue) {\r\n const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;\r\n xml += ` <lastmod>${date}</lastmod>\\n`;\r\n }\r\n\r\n if (entry.changefreq) {\r\n xml += ` <changefreq>${entry.changefreq}</changefreq>\\n`;\r\n }\r\n\r\n if (entry.priority !== undefined) {\r\n xml += ` <priority>${(entry.priority as number).toFixed(1)}</priority>\\n`;\r\n }\r\n\r\n // Extension Images - enrichie en v1.1.0\r\n if (entry.images?.length) {\r\n for (const img of entry.images) {\r\n const cleanImgUrl = sanitizeAndValidateUrl(img.loc, 'image location');\r\n \r\n xml += ` <image:image>\\n`;\r\n xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>\\n`;\r\n if (img.title) xml += ` <image:title>${escapeXml(img.title)}</image:title>\\n`;\r\n if (img.caption) xml += ` <image:caption>${escapeXml(img.caption)}</image:caption>\\n`;\r\n \r\n // SEO Local v1.1.0\r\n if (img.geo_location) {\r\n xml += ` <image:geo_location>${escapeXml(img.geo_location)}</image:geo_location>\\n`;\r\n }\r\n \r\n // Gestion des Licences Google Images v1.1.0\r\n if (img.license) {\r\n const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, 'image license URL');\r\n xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>\\n`;\r\n }\r\n \r\n xml += ` </image:image>\\n`;\r\n }\r\n }\r\n\r\n // Extension Vidéos\r\n if (entry.videos?.length) {\r\n for (const vid of entry.videos) {\r\n const cleanThumbLoc = sanitizeAndValidateUrl(vid.thumbnail_loc, 'video thumbnail');\r\n const cleanContentLoc = vid.content_loc ? sanitizeAndValidateUrl(vid.content_loc, 'video content location') : undefined;\r\n const cleanPlayerLoc = vid.player_loc ? sanitizeAndValidateUrl(vid.player_loc, 'video player location') : undefined;\r\n\r\n xml += ` <video:video>\\n`;\r\n xml += ` <video:thumbnail_loc>${escapeXml(cleanThumbLoc)}</video:thumbnail_loc>\\n`;\r\n xml += ` <video:title>${escapeXml(vid.title)}</video:title>\\n`;\r\n xml += ` <video:description>${escapeXml(vid.description)}</video:description>\\n`;\r\n \r\n if (cleanContentLoc) xml += ` <video:content_loc>${escapeXml(cleanContentLoc)}</video:content_loc>\\n`;\r\n if (cleanPlayerLoc) xml += ` <video:player_loc>${escapeXml(cleanPlayerLoc)}</video:player_loc>\\n`;\r\n \r\n if (vid.publication_date) {\r\n const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;\r\n xml += ` <video:publication_date>${vDate}</video:publication_date>\\n`;\r\n }\r\n xml += ` </video:video>\\n`;\r\n }\r\n }\r\n\r\n // Extension News\r\n if (entry.news) {\r\n const nDate = entry.news.publication_date instanceof Date ? entry.news.publication_date.toISOString() : entry.news.publication_date;\r\n xml += ` <news:news>\\n`;\r\n xml += ` <news:publication>\\n`;\r\n xml += ` <news:name>${escapeXml(entry.news.name)}</news:name>\\n`;\r\n xml += ` <news:language>${escapeXml(entry.news.language)}</news:language>\\n`;\r\n xml += ` </news:publication>\\n`;\r\n xml += ` <news:publication_date>${nDate}</news:publication_date>\\n`;\r\n xml += ` <news:title>${escapeXml(entry.news.title)}</news:title>\\n`;\r\n xml += ` </news:news>\\n`;\r\n }\r\n\r\n xml += ` </url>\\n`;\r\n }\r\n\r\n xml += `</urlset>`;\r\n return xml;\r\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \r\n * Licensed under FomaDev Public License.\r\n * See LICENSE file in the project root for full license information.\r\n */\r\n\r\nimport { SitemapEntry, SitemapOptions } from './types/sitemap.js';\r\nimport { generateXml } from './core/generator.js';\r\n\r\nexport * from './types/sitemap.js';\r\n\r\n/**\r\n * Génère une réponse HTTP compatible Next.js (App Router) avec options de configuration.\r\n * v1.0.9 : Injection dynamique et personnalisable de l'en-tête Cache-Control via l'option maxAge\r\n * * @param entries - Liste des entrées du sitemap\r\n * @param options - Options de génération et de mise en cache (ex: autoLastmod, maxAge)\r\n * @returns Une instance de Response contenant le flux XML configuré\r\n */\r\nexport function getServerSitemapResponse(\r\n entries: SitemapEntry[], \r\n options: SitemapOptions = {}\r\n): Response {\r\n const xml = generateXml(entries, options);\r\n\r\n // Détermination de la stratégie de mise en cache (v1.0.9)\r\n const cacheControlHeader = options.maxAge !== undefined\r\n ? `public, max-age=${options.maxAge}, must-revalidate`\r\n : 'public, s-maxage=86400, stale-while-revalidate';\r\n\r\n return new Response(xml, {\r\n headers: {\r\n 'Content-Type': 'application/xml',\r\n 'Cache-Control': cacheControlHeader,\r\n },\r\n });\r\n}"],"mappings":";AASO,SAAS,UAAU,QAA2C;AACnE,MAAI,CAAC,OAAQ,QAAO;AAEpB,SAAO,OAAO,QAAQ,YAAY,CAAC,MAAM;AACvC,YAAQ,GAAG;AAAA,MACT,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB;AAAS,eAAO;AAAA,IAClB;AAAA,EACF,CAAC;AACH;;;ACVA,SAAS,uBAAuB,QAAgB,SAAyB;AACvE,QAAM,MAAM,SAAS,OAAO,KAAK,IAAI;AAErC,MAAI,CAAC,IAAI,WAAW,SAAS,KAAK,CAAC,IAAI,WAAW,UAAU,GAAG;AAC7D,UAAM,IAAI;AAAA,MACR,0CAA0C,OAAO,MAAM,GAAG;AAAA,IAC5D;AAAA,EACF;AAEA,MAAI,IAAI,SAAS,GAAG,GAAG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AAO,sBAAsB,UAAU,IAAI,KAAK,CAAC;AAAA;AACjD,eAAO,4BAA4B,UAAU,IAAI,WAAW,CAAC;AAAA;AAE7D,YAAI,gBAAiB,QAAO,4BAA4B,UAAU,eAAe,CAAC;AAAA;AAClF,YAAI,eAAgB,QAAO,2BAA2B,UAAU,cAAc,CAAC;AAAA;AAE/E,YAAI,IAAI,kBAAkB;AACxB,gBAAM,QAAQ,IAAI,4BAA4B,OAAO,IAAI,iBAAiB,YAAY,IAAI,IAAI;AAC9F,iBAAO,iCAAiC,KAAK;AAAA;AAAA,QAC/C;AACA,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;;;ACvJO,SAAS,yBACd,SACA,UAA0B,CAAC,GACjB;AACV,QAAM,MAAM,YAAY,SAAS,OAAO;AAGxC,QAAM,qBAAqB,QAAQ,WAAW,SAC1C,mBAAmB,QAAQ,MAAM,sBACjC;AAEJ,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/utils/xml-escape.ts","../src/core/generator.ts","../src/index.ts"],"sourcesContent":["/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\n/**\n * Convertit les caractères spéciaux en entités XML pour éviter la corruption du fichier.\n * Gère : <, >, &, \", '\n */\nexport function escapeXml(unsafe: string | undefined | null): string {\n if (!unsafe) return '';\n \n return unsafe.replace(/[<>&\"']/g, (c) => {\n switch (c) {\n case '<': return '&lt;';\n case '>': return '&gt;';\n case '&': return '&amp;';\n case '\"': return '&quot;';\n case \"'\": return '&apos;';\n default: return c;\n }\n });\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from '../types/sitemap.js';\nimport { escapeXml } from '../utils/xml-escape.js';\n\n/**\n * Nettoie et valide de manière stricte le format et la structure d'une URL.\n * v1.0.7 : Intégration de l'Auto-Trimming (nettoyage des espaces de début et de fin)\n */\nfunction sanitizeAndValidateUrl(rawUrl: string, context: string): string {\n const url = rawUrl ? rawUrl.trim() : '';\n\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\n throw new Error(\n `[next-advanced-sitemap] Invalid URL in ${context}: \"${url}\". URLs must start with http:// or https://`\n );\n }\n\n if (url.includes(' ')) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n let isValid = false;\n if (typeof URL.canParse === 'function') {\n isValid = URL.canParse(url);\n } else {\n try {\n new URL(url);\n isValid = true;\n } catch {\n isValid = false;\n }\n }\n\n if (!isValid) {\n throw new Error(\n `[next-advanced-sitemap] Malformed URL structure detected in ${context}: \"${url}\". Please verify spaces or special characters.`\n );\n }\n\n return url;\n}\n\n/**\n * Génère le flux XML complet du sitemap incluant les extensions Images, Vidéos, News et Hreflang.\n * v1.1.2 : Métadonnées d'Accessibilité Images (caption & title optionnels, renforcés et nettoyés)\n * + Support sécurisé des statistiques vidéo (duration & view_count)\n */\nexport function generateXml(entries: SitemapEntry[], options: SitemapOptions = {}): string {\n const now = new Date().toISOString();\n let finalEntries = [...entries];\n\n if (options.sortByPriority) {\n finalEntries.sort((a, b) => {\n const priorityA = a.priority !== undefined ? (a.priority as number) : 0.5;\n const priorityB = b.priority !== undefined ? (b.priority as number) : 0.5;\n return priorityB - priorityA;\n });\n }\n \n let xml = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n`;\n xml += `<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\\n`;\n xml += ` xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"\\n`;\n xml += ` xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\"\\n`;\n xml += ` xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\"\\n`;\n xml += ` xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\\n`;\n\n for (const entry of finalEntries) {\n const cleanMainUrl = sanitizeAndValidateUrl(entry.url, 'main entry');\n\n xml += ` <url>\\n`;\n xml += ` <loc>${escapeXml(cleanMainUrl)}</loc>\\n`;\n\n if (entry.alternates?.length) {\n for (const alt of entry.alternates) {\n const cleanAltUrl = sanitizeAndValidateUrl(alt.href, 'alternate link');\n xml += ` <xhtml:link rel=\"alternate\" hreflang=\"${escapeXml(alt.hreflang)}\" href=\"${escapeXml(cleanAltUrl)}\" />\\n`;\n }\n }\n\n let lastmodValue = entry.lastmod;\n if (options.autoLastmod && !lastmodValue) {\n lastmodValue = now;\n }\n\n if (lastmodValue) {\n const date = lastmodValue instanceof Date ? lastmodValue.toISOString() : lastmodValue;\n xml += ` <lastmod>${date}</lastmod>\\n`;\n }\n\n if (entry.changefreq) {\n xml += ` <changefreq>${entry.changefreq}</changefreq>\\n`;\n }\n\n if (entry.priority !== undefined) {\n xml += ` <priority>${(entry.priority as number).toFixed(1)}</priority>\\n`;\n }\n\n // Extension Images - v1.1.2 renforcée\n if (entry.images?.length) {\n for (const img of entry.images) {\n const cleanImgUrl = sanitizeAndValidateUrl(img.loc, 'image location');\n \n xml += ` <image:image>\\n`;\n xml += ` <image:loc>${escapeXml(cleanImgUrl)}</image:loc>\\n`;\n \n // ✨ v1.1.2 : .trim() préventif pour s'assurer qu'un texte blanc ne crée pas de balise invalide\n if (img.title && img.title.trim() !== '') {\n xml += ` <image:title>${escapeXml(img.title.trim())}</image:title>\\n`;\n }\n if (img.caption && img.caption.trim() !== '') {\n xml += ` <image:caption>${escapeXml(img.caption.trim())}</image:caption>\\n`;\n }\n \n // SEO Local\n if (img.geo_location && img.geo_location.trim() !== '') {\n xml += ` <image:geo_location>${escapeXml(img.geo_location.trim())}</image:geo_location>\\n`;\n }\n \n // Gestion des Licences Google Images\n if (img.license) {\n const cleanLicenseUrl = sanitizeAndValidateUrl(img.license, 'image license URL');\n xml += ` <image:license>${escapeXml(cleanLicenseUrl)}</image:license>\\n`;\n }\n \n xml += ` </image:image>\\n`;\n }\n }\n\n // Extension Vidéos\n if (entry.videos?.length) {\n for (const vid of entry.videos) {\n const cleanThumbLoc = sanitizeAndValidateUrl(vid.thumbnail_loc, 'video thumbnail');\n const cleanContentLoc = vid.content_loc ? sanitizeAndValidateUrl(vid.content_loc, 'video content location') : undefined;\n const cleanPlayerLoc = vid.player_loc ? sanitizeAndValidateUrl(vid.player_loc, 'video player location') : undefined;\n\n xml += ` <video:video>\\n`;\n xml += ` <video:thumbnail_loc>${escapeXml(cleanThumbLoc)}</video:thumbnail_loc>\\n`;\n xml += ` <video:title>${escapeXml(vid.title)}</video:title>\\n`;\n xml += ` <video:description>${escapeXml(vid.description)}</video:description>\\n`;\n \n if (cleanContentLoc) xml += ` <video:content_loc>${escapeXml(cleanContentLoc)}</video:content_loc>\\n`;\n if (cleanPlayerLoc) xml += ` <video:player_loc>${escapeXml(cleanPlayerLoc)}</video:player_loc>\\n`;\n \n if (vid.publication_date) {\n const vDate = vid.publication_date instanceof Date ? vid.publication_date.toISOString() : vid.publication_date;\n xml += ` <video:publication_date>${vDate}</video:publication_date>\\n`;\n }\n\n // Métadonnées de statistiques (v1.1.3 - Préparé et sécurisé)\n if (vid.duration !== undefined) {\n xml += ` <video:duration>${Math.floor(vid.duration)}</video:duration>\\n`;\n }\n if (vid.view_count !== undefined) {\n xml += ` <video:view_count>${Math.floor(vid.view_count)}</video:view_count>\\n`;\n }\n\n // Support du Live Streaming v1.1.1\n if (vid.live) {\n xml += ` <video:live>${vid.live}</video:live>\\n`;\n }\n\n xml += ` </video:video>\\n`;\n }\n }\n\n // Extension News\n if (entry.news) {\n const nDate = entry.news.publication_date instanceof Date ? entry.news.publication_date.toISOString() : entry.news.publication_date;\n xml += ` <news:news>\\n`;\n xml += ` <news:publication>\\n`;\n xml += ` <news:name>${escapeXml(entry.news.name)}</news:name>\\n`;\n xml += ` <news:language>${escapeXml(entry.news.language)}</news:language>\\n`;\n xml += ` </news:publication>\\n`;\n xml += ` <news:publication_date>${nDate}</news:publication_date>\\n`;\n xml += ` <news:title>${escapeXml(entry.news.title)}</news:title>\\n`;\n xml += ` </news:news>\\n`;\n }\n\n xml += ` </url>\\n`;\n }\n\n xml += `</urlset>`;\n return xml;\n}","/* * Copyright (c) 2026 Fordi / FomaDev. \n * Licensed under FomaDev Public License.\n * See LICENSE file in the project root for full license information.\n */\n\nimport { SitemapEntry, SitemapOptions } from './types/sitemap.js';\nimport { generateXml } from './core/generator.js';\n\nexport * from './types/sitemap.js';\n\n/**\n * Génère une réponse HTTP compatible Next.js (App Router) avec options de configuration.\n * v1.0.9 : Injection dynamique et personnalisable de l'en-tête Cache-Control via l'option maxAge\n * * @param entries - Liste des entrées du sitemap\n * @param options - Options de génération et de mise en cache (ex: autoLastmod, maxAge)\n * @returns Une instance de Response contenant le flux XML configuré\n */\nexport function getServerSitemapResponse(\n entries: SitemapEntry[], \n options: SitemapOptions = {}\n): Response {\n const xml = generateXml(entries, options);\n\n // Détermination de la stratégie de mise en cache (v1.0.9)\n const cacheControlHeader = options.maxAge !== undefined\n ? `public, max-age=${options.maxAge}, must-revalidate`\n : 'public, s-maxage=86400, stale-while-revalidate';\n\n return new Response(xml, {\n headers: {\n 'Content-Type': 'application/xml',\n 'Cache-Control': cacheControlHeader,\n },\n });\n}"],"mappings":";AASO,SAAS,UAAU,QAA2C;AACnE,MAAI,CAAC,OAAQ,QAAO;AAEpB,SAAO,OAAO,QAAQ,YAAY,CAAC,MAAM;AACvC,YAAQ,GAAG;AAAA,MACT,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB,KAAK;AAAK,eAAO;AAAA,MACjB;AAAS,eAAO;AAAA,IAClB;AAAA,EACF,CAAC;AACH;;;ACVA,SAAS,uBAAuB,QAAgB,SAAyB;AACvE,QAAM,MAAM,SAAS,OAAO,KAAK,IAAI;AAErC,MAAI,CAAC,IAAI,WAAW,SAAS,KAAK,CAAC,IAAI,WAAW,UAAU,GAAG;AAC7D,UAAM,IAAI;AAAA,MACR,0CAA0C,OAAO,MAAM,GAAG;AAAA,IAC5D;AAAA,EACF;AAEA,MAAI,IAAI,SAAS,GAAG,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;AAAA,MACR,+DAA+D,OAAO,MAAM,GAAG;AAAA,IACjF;AAAA,EACF;AAEA,SAAO;AACT;AAOO,SAAS,YAAY,SAAyB,UAA0B,CAAC,GAAW;AACzF,QAAM,OAAM,oBAAI,KAAK,GAAE,YAAY;AACnC,MAAI,eAAe,CAAC,GAAG,OAAO;AAE9B,MAAI,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,YAAI,IAAI,aAAa,QAAW;AAC9B,iBAAO,yBAAyB,KAAK,MAAM,IAAI,QAAQ,CAAC;AAAA;AAAA,QAC1D;AACA,YAAI,IAAI,eAAe,QAAW;AAChC,iBAAO,2BAA2B,KAAK,MAAM,IAAI,UAAU,CAAC;AAAA;AAAA,QAC9D;AAGA,YAAI,IAAI,MAAM;AACZ,iBAAO,qBAAqB,IAAI,IAAI;AAAA;AAAA,QACtC;AAEA,eAAO;AAAA;AAAA,MACT;AAAA,IACF;AAGA,QAAI,MAAM,MAAM;AACd,YAAM,QAAQ,MAAM,KAAK,4BAA4B,OAAO,MAAM,KAAK,iBAAiB,YAAY,IAAI,MAAM,KAAK;AACnH,aAAO;AAAA;AACP,aAAO;AAAA;AACP,aAAO,sBAAsB,UAAU,MAAM,KAAK,IAAI,CAAC;AAAA;AACvD,aAAO,0BAA0B,UAAU,MAAM,KAAK,QAAQ,CAAC;AAAA;AAC/D,aAAO;AAAA;AACP,aAAO,gCAAgC,KAAK;AAAA;AAC5C,aAAO,qBAAqB,UAAU,MAAM,KAAK,KAAK,CAAC;AAAA;AACvD,aAAO;AAAA;AAAA,IACT;AAEA,WAAO;AAAA;AAAA,EACT;AAEA,SAAO;AACP,SAAO;AACT;;;AC5KO,SAAS,yBACd,SACA,UAA0B,CAAC,GACjB;AACV,QAAM,MAAM,YAAY,SAAS,OAAO;AAGxC,QAAM,qBAAqB,QAAQ,WAAW,SAC1C,mBAAmB,QAAQ,MAAM,sBACjC;AAEJ,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,47 +1,56 @@
1
- {
2
- "name": "next-advanced-sitemap",
3
- "version": "1.1.0",
4
- "type": "module",
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
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
14
- }
15
- },
16
- "files": [
17
- "dist"
18
- ],
19
- "scripts": {
20
- "dev": "tsup src/index.ts --watch",
21
- "build": "tsup",
22
- "test": "vitest run",
23
- "prepublishOnly": "npm run test && npm run build"
24
- },
25
- "keywords": [
26
- "nextjs",
27
- "sitemap",
28
- "seo",
29
- "google-images",
30
- "google-video",
31
- "google-news",
32
- "hreflang",
33
- "multilingual",
34
- "typescript",
35
- "app-router"
36
- ],
37
- "author": "fomadev",
38
- "license": "FomaDev Public License",
39
- "repository": {
40
- "type": "git",
41
- "url": "git+https://github.com/fomadev/next-advanced-sitemap.git"
42
- },
43
- "bugs": {
44
- "url": "https://github.com/fomadev/next-advanced-sitemap/issues"
45
- },
46
- "homepage": "https://github.com/fomadev/next-advanced-sitemap#readme"
1
+ {
2
+ "name": "next-advanced-sitemap",
3
+ "version": "1.1.2",
4
+ "type": "module",
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
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "dev": "tsup src/index.ts --watch",
21
+ "build": "tsup",
22
+ "test": "vitest run",
23
+ "prepublishOnly": "npm run test && npm run build"
24
+ },
25
+ "keywords": [
26
+ "nextjs",
27
+ "sitemap",
28
+ "seo",
29
+ "google-images",
30
+ "google-video",
31
+ "google-news",
32
+ "hreflang",
33
+ "multilingual",
34
+ "typescript",
35
+ "app-router"
36
+ ],
37
+ "author": "fomadev",
38
+ "license": "FomaDev Public License",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/fomadev/next-advanced-sitemap.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/fomadev/next-advanced-sitemap/issues"
45
+ },
46
+ "homepage": "https://github.com/fomadev/next-advanced-sitemap#readme",
47
+ "devDependencies": {
48
+ "tsup": "^8.5.1",
49
+ "typescript": "^5.7.3",
50
+ "vitest": "^1.4.0"
51
+ },
52
+ "peerDependencies": {
53
+ "next": ">=13.0.0",
54
+ "react": ">=18.0.0"
55
+ }
47
56
  }