@onruntime/next-sitemap 0.7.0 → 0.8.0

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 CHANGED
@@ -9,6 +9,14 @@ Dynamic sitemap generation for Next.js with automatic route discovery.
9
9
  - [Next.js Pages Router](https://github.com/onRuntime/onruntime/tree/master/examples/next-sitemap/pages)
10
10
  - [Next.js Pages Router with i18n](https://github.com/onRuntime/onruntime/tree/master/examples/next-sitemap/pages-with-locales)
11
11
 
12
+ ## Used by
13
+
14
+ - [onruntime.com](https://onruntime.com/sitemap.xml) - Creative development studio
15
+ - [trendstack.news](https://trendstack.news/sitemap.xml) - News site
16
+ - [tonightpass.com](https://tonightpass.com/sitemap.xml) - Nightlife platform
17
+
18
+ Want to be listed here? Open a PR! Just make sure `poweredBy` is enabled (default).
19
+
12
20
  ## Features
13
21
 
14
22
  - **App Router** and **Pages Router** support
@@ -185,6 +193,7 @@ export default createSitemapIndexApiHandler({
185
193
  | `changeFreq` | `ChangeFrequency` or `function` | `"weekly"` | Change frequency for entries |
186
194
  | `additionalSitemaps` | `string[]` | `[]` | Additional sitemaps to include in index |
187
195
  | `debug` | `boolean` | `false` | Enable debug logging to diagnose route discovery issues |
196
+ | `poweredBy` | `boolean` | `true` | Include "Powered by @onruntime/next-sitemap" comment in XML |
188
197
 
189
198
  #### Exclude Routes
190
199
 
@@ -303,6 +312,7 @@ export async function GET() {
303
312
  **Sitemap Index** (`/sitemap.xml`):
304
313
  ```xml
305
314
  <?xml version="1.0" encoding="UTF-8"?>
315
+ <!-- Powered by @onruntime/next-sitemap -->
306
316
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
307
317
  <sitemap>
308
318
  <loc>https://example.com/sitemap-0.xml</loc>
@@ -314,6 +324,7 @@ export async function GET() {
314
324
  **Individual Sitemap** (`/sitemap-0.xml`):
315
325
  ```xml
316
326
  <?xml version="1.0" encoding="UTF-8"?>
327
+ <!-- Powered by @onruntime/next-sitemap -->
317
328
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
318
329
  <url>
319
330
  <loc>https://example.com/</loc>
@@ -345,6 +356,7 @@ export default createRobotsApiHandler({
345
356
  disallow: ["/admin", "/private"],
346
357
  },
347
358
  sitemap: "https://example.com/sitemap.xml",
359
+ // poweredBy: false, // Disable "Powered by" comment
348
360
  });
349
361
  ```
350
362
 
@@ -234,7 +234,8 @@ function buildUrl(baseUrl, pathname, locale, defaultLocale) {
234
234
  }
235
235
  return `${baseUrl}/${locale}${normalizedPath}`;
236
236
  }
237
- function generateSitemapXml(entries) {
237
+ function generateSitemapXml(entries, options) {
238
+ const { poweredBy = true } = options || {};
238
239
  const hasAlternates = entries.some((e) => e.alternates?.languages);
239
240
  const xmlns = hasAlternates ? 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"' : 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
240
241
  const urlEntries = entries.map((entry) => {
@@ -258,13 +259,14 @@ function generateSitemapXml(entries) {
258
259
  ${parts.join("\n")}
259
260
  </url>`;
260
261
  }).join("\n");
261
- return `<?xml version="1.0" encoding="UTF-8"?>
262
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
263
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
262
264
  <urlset ${xmlns}>
263
265
  ${urlEntries}
264
266
  </urlset>`;
265
267
  }
266
268
  function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
267
- const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [] } = options || {};
269
+ const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [], poweredBy = true } = options || {};
268
270
  const now = (/* @__PURE__ */ new Date()).toISOString();
269
271
  const paginatedEntries = Array.from({ length: sitemapCount }, (_, i) => {
270
272
  const loc = `${baseUrl}${sitemapPattern.replace("{id}", String(i))}`;
@@ -281,7 +283,8 @@ function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
281
283
  </sitemap>`;
282
284
  });
283
285
  const allEntries = [...paginatedEntries, ...additionalEntries].join("\n");
284
- return `<?xml version="1.0" encoding="UTF-8"?>
286
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
287
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
285
288
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
286
289
  ${allEntries}
287
290
  </sitemapindex>`;
@@ -347,7 +350,7 @@ function createSitemapIndexHandler(options) {
347
350
  const filteredPaths = allPaths.filter((p) => !shouldExclude(p, exclude));
348
351
  const sitemapCount = Math.max(1, Math.ceil(filteredPaths.length / urlsPerSitemap));
349
352
  return new Response(
350
- generateSitemapIndexXml(options.baseUrl, sitemapCount, { additionalSitemaps }),
353
+ generateSitemapIndexXml(options.baseUrl, sitemapCount, { additionalSitemaps, poweredBy: options.poweredBy }),
351
354
  { headers: { "Content-Type": "application/xml" } }
352
355
  );
353
356
  }
@@ -375,7 +378,7 @@ function createSitemapHandler(options) {
375
378
  const filteredPaths = await getFilteredPaths();
376
379
  const paths = filteredPaths.slice(sitemapId * urlsPerSitemap, (sitemapId + 1) * urlsPerSitemap);
377
380
  const entries = pathsToEntries(paths, { ...options, exclude: void 0 });
378
- return new Response(generateSitemapXml(entries), {
381
+ return new Response(generateSitemapXml(entries, { poweredBy: options.poweredBy }), {
379
382
  headers: { "Content-Type": "application/xml" }
380
383
  });
381
384
  }
@@ -57,6 +57,11 @@ interface SitemapConfig {
57
57
  * @default false
58
58
  */
59
59
  debug?: boolean;
60
+ /**
61
+ * Include "Powered by @onruntime/next-sitemap" comment in generated XML
62
+ * @default true
63
+ */
64
+ poweredBy?: boolean;
60
65
  }
61
66
  interface SitemapEntry {
62
67
  url: string;
@@ -57,6 +57,11 @@ interface SitemapConfig {
57
57
  * @default false
58
58
  */
59
59
  debug?: boolean;
60
+ /**
61
+ * Include "Powered by @onruntime/next-sitemap" comment in generated XML
62
+ * @default true
63
+ */
64
+ poweredBy?: boolean;
60
65
  }
61
66
  interface SitemapEntry {
62
67
  url: string;
package/dist/app/index.js CHANGED
@@ -211,7 +211,8 @@ function buildUrl(baseUrl, pathname, locale, defaultLocale) {
211
211
  }
212
212
  return `${baseUrl}/${locale}${normalizedPath}`;
213
213
  }
214
- function generateSitemapXml(entries) {
214
+ function generateSitemapXml(entries, options) {
215
+ const { poweredBy = true } = options || {};
215
216
  const hasAlternates = entries.some((e) => e.alternates?.languages);
216
217
  const xmlns = hasAlternates ? 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"' : 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
217
218
  const urlEntries = entries.map((entry) => {
@@ -235,13 +236,14 @@ function generateSitemapXml(entries) {
235
236
  ${parts.join("\n")}
236
237
  </url>`;
237
238
  }).join("\n");
238
- return `<?xml version="1.0" encoding="UTF-8"?>
239
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
240
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
239
241
  <urlset ${xmlns}>
240
242
  ${urlEntries}
241
243
  </urlset>`;
242
244
  }
243
245
  function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
244
- const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [] } = options || {};
246
+ const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [], poweredBy = true } = options || {};
245
247
  const now = (/* @__PURE__ */ new Date()).toISOString();
246
248
  const paginatedEntries = Array.from({ length: sitemapCount }, (_, i) => {
247
249
  const loc = `${baseUrl}${sitemapPattern.replace("{id}", String(i))}`;
@@ -258,7 +260,8 @@ function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
258
260
  </sitemap>`;
259
261
  });
260
262
  const allEntries = [...paginatedEntries, ...additionalEntries].join("\n");
261
- return `<?xml version="1.0" encoding="UTF-8"?>
263
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
264
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
262
265
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
263
266
  ${allEntries}
264
267
  </sitemapindex>`;
@@ -324,7 +327,7 @@ function createSitemapIndexHandler(options) {
324
327
  const filteredPaths = allPaths.filter((p) => !shouldExclude(p, exclude));
325
328
  const sitemapCount = Math.max(1, Math.ceil(filteredPaths.length / urlsPerSitemap));
326
329
  return new Response(
327
- generateSitemapIndexXml(options.baseUrl, sitemapCount, { additionalSitemaps }),
330
+ generateSitemapIndexXml(options.baseUrl, sitemapCount, { additionalSitemaps, poweredBy: options.poweredBy }),
328
331
  { headers: { "Content-Type": "application/xml" } }
329
332
  );
330
333
  }
@@ -352,7 +355,7 @@ function createSitemapHandler(options) {
352
355
  const filteredPaths = await getFilteredPaths();
353
356
  const paths = filteredPaths.slice(sitemapId * urlsPerSitemap, (sitemapId + 1) * urlsPerSitemap);
354
357
  const entries = pathsToEntries(paths, { ...options, exclude: void 0 });
355
- return new Response(generateSitemapXml(entries), {
358
+ return new Response(generateSitemapXml(entries, { poweredBy: options.poweredBy }), {
356
359
  headers: { "Content-Type": "application/xml" }
357
360
  });
358
361
  }
package/dist/index.cjs CHANGED
@@ -246,7 +246,8 @@ function buildUrl(baseUrl, pathname, locale, defaultLocale) {
246
246
  }
247
247
  return `${baseUrl}/${locale}${normalizedPath}`;
248
248
  }
249
- function generateSitemapXml(entries) {
249
+ function generateSitemapXml(entries, options) {
250
+ const { poweredBy = true } = options || {};
250
251
  const hasAlternates = entries.some((e) => e.alternates?.languages);
251
252
  const xmlns = hasAlternates ? 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"' : 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
252
253
  const urlEntries = entries.map((entry) => {
@@ -270,13 +271,14 @@ function generateSitemapXml(entries) {
270
271
  ${parts.join("\n")}
271
272
  </url>`;
272
273
  }).join("\n");
273
- return `<?xml version="1.0" encoding="UTF-8"?>
274
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
275
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
274
276
  <urlset ${xmlns}>
275
277
  ${urlEntries}
276
278
  </urlset>`;
277
279
  }
278
280
  function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
279
- const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [] } = options || {};
281
+ const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [], poweredBy = true } = options || {};
280
282
  const now = (/* @__PURE__ */ new Date()).toISOString();
281
283
  const paginatedEntries = Array.from({ length: sitemapCount }, (_, i) => {
282
284
  const loc = `${baseUrl}${sitemapPattern.replace("{id}", String(i))}`;
@@ -293,7 +295,8 @@ function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
293
295
  </sitemap>`;
294
296
  });
295
297
  const allEntries = [...paginatedEntries, ...additionalEntries].join("\n");
296
- return `<?xml version="1.0" encoding="UTF-8"?>
298
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
299
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
297
300
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
298
301
  ${allEntries}
299
302
  </sitemapindex>`;
package/dist/index.d.cts CHANGED
@@ -106,6 +106,11 @@ interface SitemapConfig {
106
106
  * @default false
107
107
  */
108
108
  debug?: boolean;
109
+ /**
110
+ * Include "Powered by @onruntime/next-sitemap" comment in generated XML
111
+ * @default true
112
+ */
113
+ poweredBy?: boolean;
109
114
  }
110
115
  interface SitemapEntry {
111
116
  url: string;
@@ -153,13 +158,16 @@ declare function buildUrl(baseUrl: string, pathname: string, locale?: string, de
153
158
  /**
154
159
  * Generate sitemap XML from entries
155
160
  */
156
- declare function generateSitemapXml(entries: SitemapEntry[]): string;
161
+ declare function generateSitemapXml(entries: SitemapEntry[], options?: {
162
+ poweredBy?: boolean;
163
+ }): string;
157
164
  /**
158
165
  * Generate sitemap index XML
159
166
  */
160
167
  declare function generateSitemapIndexXml(baseUrl: string, sitemapCount: number, options?: {
161
168
  sitemapPattern?: string;
162
169
  additionalSitemaps?: string[];
170
+ poweredBy?: boolean;
163
171
  }): string;
164
172
 
165
173
  export { type ChangeFrequency, JS_EXTENSIONS, NO_STATIC_PARAMS, type PageModule, type RouteInfo, type SitemapConfig, type SitemapEntry, type WorkerFailure, type WorkerOutput, type WorkerSuccess, buildUrl, calculateDepthPriority, executeWorker, generateAllPaths, generateSitemapIndexXml, generateSitemapXml, getChangeFreq, getPriority, getRouteParams, isDev, normalizePath, paramsCache, pathsToEntries, shouldExclude };
package/dist/index.d.ts CHANGED
@@ -106,6 +106,11 @@ interface SitemapConfig {
106
106
  * @default false
107
107
  */
108
108
  debug?: boolean;
109
+ /**
110
+ * Include "Powered by @onruntime/next-sitemap" comment in generated XML
111
+ * @default true
112
+ */
113
+ poweredBy?: boolean;
109
114
  }
110
115
  interface SitemapEntry {
111
116
  url: string;
@@ -153,13 +158,16 @@ declare function buildUrl(baseUrl: string, pathname: string, locale?: string, de
153
158
  /**
154
159
  * Generate sitemap XML from entries
155
160
  */
156
- declare function generateSitemapXml(entries: SitemapEntry[]): string;
161
+ declare function generateSitemapXml(entries: SitemapEntry[], options?: {
162
+ poweredBy?: boolean;
163
+ }): string;
157
164
  /**
158
165
  * Generate sitemap index XML
159
166
  */
160
167
  declare function generateSitemapIndexXml(baseUrl: string, sitemapCount: number, options?: {
161
168
  sitemapPattern?: string;
162
169
  additionalSitemaps?: string[];
170
+ poweredBy?: boolean;
163
171
  }): string;
164
172
 
165
173
  export { type ChangeFrequency, JS_EXTENSIONS, NO_STATIC_PARAMS, type PageModule, type RouteInfo, type SitemapConfig, type SitemapEntry, type WorkerFailure, type WorkerOutput, type WorkerSuccess, buildUrl, calculateDepthPriority, executeWorker, generateAllPaths, generateSitemapIndexXml, generateSitemapXml, getChangeFreq, getPriority, getRouteParams, isDev, normalizePath, paramsCache, pathsToEntries, shouldExclude };
package/dist/index.js CHANGED
@@ -223,7 +223,8 @@ function buildUrl(baseUrl, pathname, locale, defaultLocale) {
223
223
  }
224
224
  return `${baseUrl}/${locale}${normalizedPath}`;
225
225
  }
226
- function generateSitemapXml(entries) {
226
+ function generateSitemapXml(entries, options) {
227
+ const { poweredBy = true } = options || {};
227
228
  const hasAlternates = entries.some((e) => e.alternates?.languages);
228
229
  const xmlns = hasAlternates ? 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"' : 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
229
230
  const urlEntries = entries.map((entry) => {
@@ -247,13 +248,14 @@ function generateSitemapXml(entries) {
247
248
  ${parts.join("\n")}
248
249
  </url>`;
249
250
  }).join("\n");
250
- return `<?xml version="1.0" encoding="UTF-8"?>
251
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
252
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
251
253
  <urlset ${xmlns}>
252
254
  ${urlEntries}
253
255
  </urlset>`;
254
256
  }
255
257
  function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
256
- const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [] } = options || {};
258
+ const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [], poweredBy = true } = options || {};
257
259
  const now = (/* @__PURE__ */ new Date()).toISOString();
258
260
  const paginatedEntries = Array.from({ length: sitemapCount }, (_, i) => {
259
261
  const loc = `${baseUrl}${sitemapPattern.replace("{id}", String(i))}`;
@@ -270,7 +272,8 @@ function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
270
272
  </sitemap>`;
271
273
  });
272
274
  const allEntries = [...paginatedEntries, ...additionalEntries].join("\n");
273
- return `<?xml version="1.0" encoding="UTF-8"?>
275
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
276
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
274
277
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
275
278
  ${allEntries}
276
279
  </sitemapindex>`;
@@ -234,7 +234,8 @@ function buildUrl(baseUrl, pathname, locale, defaultLocale) {
234
234
  }
235
235
  return `${baseUrl}/${locale}${normalizedPath}`;
236
236
  }
237
- function generateSitemapXml(entries) {
237
+ function generateSitemapXml(entries, options) {
238
+ const { poweredBy = true } = options || {};
238
239
  const hasAlternates = entries.some((e) => e.alternates?.languages);
239
240
  const xmlns = hasAlternates ? 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"' : 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
240
241
  const urlEntries = entries.map((entry) => {
@@ -258,13 +259,14 @@ function generateSitemapXml(entries) {
258
259
  ${parts.join("\n")}
259
260
  </url>`;
260
261
  }).join("\n");
261
- return `<?xml version="1.0" encoding="UTF-8"?>
262
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
263
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
262
264
  <urlset ${xmlns}>
263
265
  ${urlEntries}
264
266
  </urlset>`;
265
267
  }
266
268
  function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
267
- const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [] } = options || {};
269
+ const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [], poweredBy = true } = options || {};
268
270
  const now = (/* @__PURE__ */ new Date()).toISOString();
269
271
  const paginatedEntries = Array.from({ length: sitemapCount }, (_, i) => {
270
272
  const loc = `${baseUrl}${sitemapPattern.replace("{id}", String(i))}`;
@@ -281,7 +283,8 @@ function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
281
283
  </sitemap>`;
282
284
  });
283
285
  const allEntries = [...paginatedEntries, ...additionalEntries].join("\n");
284
- return `<?xml version="1.0" encoding="UTF-8"?>
286
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
287
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
285
288
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
286
289
  ${allEntries}
287
290
  </sitemapindex>`;
@@ -289,7 +292,12 @@ ${allEntries}
289
292
 
290
293
  // src/pages/robots.ts
291
294
  function generateRobotsTxt(config) {
295
+ const { poweredBy = true } = config;
292
296
  const lines = [];
297
+ if (poweredBy) {
298
+ lines.push("# Powered by @onruntime/next-sitemap");
299
+ lines.push("");
300
+ }
293
301
  const rules = Array.isArray(config.rules) ? config.rules : [config.rules];
294
302
  for (const rule of rules) {
295
303
  const userAgents = Array.isArray(rule.userAgent) ? rule.userAgent : [rule.userAgent];
@@ -387,7 +395,7 @@ function createSitemapIndexApiHandler(options) {
387
395
  const sitemapCount = Math.max(1, Math.ceil(filteredPaths.length / urlsPerSitemap));
388
396
  res.setHeader("Content-Type", "application/xml");
389
397
  res.status(200).send(
390
- generateSitemapIndexXml(options.baseUrl, sitemapCount, { additionalSitemaps })
398
+ generateSitemapIndexXml(options.baseUrl, sitemapCount, { additionalSitemaps, poweredBy: options.poweredBy })
391
399
  );
392
400
  };
393
401
  }
@@ -408,7 +416,7 @@ function createSitemapApiHandler(options) {
408
416
  const paths = filteredPaths.slice(sitemapId * urlsPerSitemap, (sitemapId + 1) * urlsPerSitemap);
409
417
  const entries = pathsToEntries(paths, { ...options, exclude: void 0 });
410
418
  res.setHeader("Content-Type", "application/xml");
411
- res.status(200).send(generateSitemapXml(entries));
419
+ res.status(200).send(generateSitemapXml(entries, { poweredBy: options.poweredBy }));
412
420
  };
413
421
  }
414
422
  async function getSitemapStaticPaths(options) {
@@ -60,6 +60,11 @@ interface SitemapConfig {
60
60
  * @default false
61
61
  */
62
62
  debug?: boolean;
63
+ /**
64
+ * Include "Powered by @onruntime/next-sitemap" comment in generated XML
65
+ * @default true
66
+ */
67
+ poweredBy?: boolean;
63
68
  }
64
69
  interface SitemapEntry {
65
70
  url: string;
@@ -71,11 +76,18 @@ interface SitemapEntry {
71
76
  };
72
77
  }
73
78
 
79
+ interface RobotsConfig extends MetadataRoute.Robots {
80
+ /**
81
+ * Include "Powered by @onruntime/next-sitemap" comment
82
+ * @default true
83
+ */
84
+ poweredBy?: boolean;
85
+ }
74
86
  /**
75
87
  * Generate robots.txt content from configuration
76
88
  * Compatible with Next.js MetadataRoute.Robots
77
89
  */
78
- declare function generateRobotsTxt(config: MetadataRoute.Robots): string;
90
+ declare function generateRobotsTxt(config: RobotsConfig): string;
79
91
 
80
92
  interface CreateSitemapApiHandlerOptions extends SitemapConfig {
81
93
  /**
@@ -111,6 +123,6 @@ declare function getSitemapStaticPaths(options: CreateSitemapApiHandlerOptions):
111
123
  * Create API handler for robots.txt
112
124
  * Use in: pages/api/robots.txt.ts
113
125
  */
114
- declare function createRobotsApiHandler(config: MetadataRoute.Robots): (_req: NextApiRequest, res: NextApiResponse) => void;
126
+ declare function createRobotsApiHandler(config: RobotsConfig): (_req: NextApiRequest, res: NextApiResponse) => void;
115
127
 
116
- export { type ChangeFrequency, type CreateSitemapApiHandlerOptions, type SitemapConfig, type SitemapEntry, createRobotsApiHandler, createSitemapApiHandler, createSitemapIndexApiHandler, generateRobotsTxt, getSitemapStaticPaths };
128
+ export { type ChangeFrequency, type CreateSitemapApiHandlerOptions, type RobotsConfig, type SitemapConfig, type SitemapEntry, createRobotsApiHandler, createSitemapApiHandler, createSitemapIndexApiHandler, generateRobotsTxt, getSitemapStaticPaths };
@@ -60,6 +60,11 @@ interface SitemapConfig {
60
60
  * @default false
61
61
  */
62
62
  debug?: boolean;
63
+ /**
64
+ * Include "Powered by @onruntime/next-sitemap" comment in generated XML
65
+ * @default true
66
+ */
67
+ poweredBy?: boolean;
63
68
  }
64
69
  interface SitemapEntry {
65
70
  url: string;
@@ -71,11 +76,18 @@ interface SitemapEntry {
71
76
  };
72
77
  }
73
78
 
79
+ interface RobotsConfig extends MetadataRoute.Robots {
80
+ /**
81
+ * Include "Powered by @onruntime/next-sitemap" comment
82
+ * @default true
83
+ */
84
+ poweredBy?: boolean;
85
+ }
74
86
  /**
75
87
  * Generate robots.txt content from configuration
76
88
  * Compatible with Next.js MetadataRoute.Robots
77
89
  */
78
- declare function generateRobotsTxt(config: MetadataRoute.Robots): string;
90
+ declare function generateRobotsTxt(config: RobotsConfig): string;
79
91
 
80
92
  interface CreateSitemapApiHandlerOptions extends SitemapConfig {
81
93
  /**
@@ -111,6 +123,6 @@ declare function getSitemapStaticPaths(options: CreateSitemapApiHandlerOptions):
111
123
  * Create API handler for robots.txt
112
124
  * Use in: pages/api/robots.txt.ts
113
125
  */
114
- declare function createRobotsApiHandler(config: MetadataRoute.Robots): (_req: NextApiRequest, res: NextApiResponse) => void;
126
+ declare function createRobotsApiHandler(config: RobotsConfig): (_req: NextApiRequest, res: NextApiResponse) => void;
115
127
 
116
- export { type ChangeFrequency, type CreateSitemapApiHandlerOptions, type SitemapConfig, type SitemapEntry, createRobotsApiHandler, createSitemapApiHandler, createSitemapIndexApiHandler, generateRobotsTxt, getSitemapStaticPaths };
128
+ export { type ChangeFrequency, type CreateSitemapApiHandlerOptions, type RobotsConfig, type SitemapConfig, type SitemapEntry, createRobotsApiHandler, createSitemapApiHandler, createSitemapIndexApiHandler, generateRobotsTxt, getSitemapStaticPaths };
@@ -211,7 +211,8 @@ function buildUrl(baseUrl, pathname, locale, defaultLocale) {
211
211
  }
212
212
  return `${baseUrl}/${locale}${normalizedPath}`;
213
213
  }
214
- function generateSitemapXml(entries) {
214
+ function generateSitemapXml(entries, options) {
215
+ const { poweredBy = true } = options || {};
215
216
  const hasAlternates = entries.some((e) => e.alternates?.languages);
216
217
  const xmlns = hasAlternates ? 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"' : 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
217
218
  const urlEntries = entries.map((entry) => {
@@ -235,13 +236,14 @@ function generateSitemapXml(entries) {
235
236
  ${parts.join("\n")}
236
237
  </url>`;
237
238
  }).join("\n");
238
- return `<?xml version="1.0" encoding="UTF-8"?>
239
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
240
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
239
241
  <urlset ${xmlns}>
240
242
  ${urlEntries}
241
243
  </urlset>`;
242
244
  }
243
245
  function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
244
- const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [] } = options || {};
246
+ const { sitemapPattern = "/sitemap-{id}.xml", additionalSitemaps = [], poweredBy = true } = options || {};
245
247
  const now = (/* @__PURE__ */ new Date()).toISOString();
246
248
  const paginatedEntries = Array.from({ length: sitemapCount }, (_, i) => {
247
249
  const loc = `${baseUrl}${sitemapPattern.replace("{id}", String(i))}`;
@@ -258,7 +260,8 @@ function generateSitemapIndexXml(baseUrl, sitemapCount, options) {
258
260
  </sitemap>`;
259
261
  });
260
262
  const allEntries = [...paginatedEntries, ...additionalEntries].join("\n");
261
- return `<?xml version="1.0" encoding="UTF-8"?>
263
+ const comment = poweredBy ? "\n<!-- Powered by @onruntime/next-sitemap -->" : "";
264
+ return `<?xml version="1.0" encoding="UTF-8"?>${comment}
262
265
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
263
266
  ${allEntries}
264
267
  </sitemapindex>`;
@@ -266,7 +269,12 @@ ${allEntries}
266
269
 
267
270
  // src/pages/robots.ts
268
271
  function generateRobotsTxt(config) {
272
+ const { poweredBy = true } = config;
269
273
  const lines = [];
274
+ if (poweredBy) {
275
+ lines.push("# Powered by @onruntime/next-sitemap");
276
+ lines.push("");
277
+ }
270
278
  const rules = Array.isArray(config.rules) ? config.rules : [config.rules];
271
279
  for (const rule of rules) {
272
280
  const userAgents = Array.isArray(rule.userAgent) ? rule.userAgent : [rule.userAgent];
@@ -364,7 +372,7 @@ function createSitemapIndexApiHandler(options) {
364
372
  const sitemapCount = Math.max(1, Math.ceil(filteredPaths.length / urlsPerSitemap));
365
373
  res.setHeader("Content-Type", "application/xml");
366
374
  res.status(200).send(
367
- generateSitemapIndexXml(options.baseUrl, sitemapCount, { additionalSitemaps })
375
+ generateSitemapIndexXml(options.baseUrl, sitemapCount, { additionalSitemaps, poweredBy: options.poweredBy })
368
376
  );
369
377
  };
370
378
  }
@@ -385,7 +393,7 @@ function createSitemapApiHandler(options) {
385
393
  const paths = filteredPaths.slice(sitemapId * urlsPerSitemap, (sitemapId + 1) * urlsPerSitemap);
386
394
  const entries = pathsToEntries(paths, { ...options, exclude: void 0 });
387
395
  res.setHeader("Content-Type", "application/xml");
388
- res.status(200).send(generateSitemapXml(entries));
396
+ res.status(200).send(generateSitemapXml(entries, { poweredBy: options.poweredBy }));
389
397
  };
390
398
  }
391
399
  async function getSitemapStaticPaths(options) {
package/dist/worker.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
  var fs = require('fs');
4
4
  var module$1 = require('module');
5
5
  var path = require('path');
6
+ var os = require('os');
6
7
  var jiti = require('jiti');
7
8
  require('child_process');
8
9
  var url = require('url');
@@ -116,8 +117,52 @@ process.env.NODE_ENV === "development";
116
117
 
117
118
  // src/worker.ts
118
119
  var joinPath = (...segments) => path.join(...segments);
120
+ var mockedModules = /* @__PURE__ */ new Set();
121
+ var mockTempDir = null;
122
+ function getMockTempDir() {
123
+ if (!mockTempDir) {
124
+ mockTempDir = fs.mkdtempSync(joinPath(os.tmpdir(), "next-sitemap-"));
125
+ }
126
+ return mockTempDir;
127
+ }
128
+ function createMockFile(name) {
129
+ const mockPath = joinPath(getMockTempDir(), `${name.replace(/[^a-zA-Z0-9]/g, "_")}-mock.js`);
130
+ const mockContent = `
131
+ // Auto-generated mock for ${name}
132
+ const handler = {
133
+ get(_, prop) {
134
+ if (prop === Symbol.toPrimitive) return () => "";
135
+ if (prop === "then") return undefined;
136
+ return new Proxy(() => {}, handler);
137
+ },
138
+ apply() { return new Proxy(() => {}, handler); }
139
+ };
140
+ const mock = new Proxy(() => {}, handler);
141
+ module.exports = mock;
142
+ module.exports.default = mock;
143
+ // Common named exports
144
+ module.exports.env = mock;
145
+ module.exports.createEnv = () => mock;
146
+ `;
147
+ fs.writeFileSync(mockPath, mockContent);
148
+ return mockPath;
149
+ }
119
150
  installMockLoader();
120
151
  main();
152
+ function createGenericMock() {
153
+ const handler = {
154
+ get(_, prop) {
155
+ if (prop === Symbol.toPrimitive) return () => "";
156
+ if (prop === "then") return void 0;
157
+ return new Proxy(() => createGenericMock(), handler);
158
+ },
159
+ apply() {
160
+ return createGenericMock();
161
+ }
162
+ };
163
+ return new Proxy(() => {
164
+ }, handler);
165
+ }
121
166
  function installMockLoader() {
122
167
  const ModuleInternal = module$1.Module;
123
168
  const originalLoad = ModuleInternal._load;
@@ -126,13 +171,19 @@ function installMockLoader() {
126
171
  try {
127
172
  resolvedPath = ModuleInternal._resolveFilename(request, parent, isMain);
128
173
  } catch {
129
- return originalLoad(request, parent, isMain);
174
+ mockedModules.add(request);
175
+ return createGenericMock();
130
176
  }
131
177
  const ext = path.extname(resolvedPath).toLowerCase();
132
178
  if (ext && !JS_EXTENSIONS.has(ext)) {
133
179
  return {};
134
180
  }
135
- return originalLoad(request, parent, isMain);
181
+ try {
182
+ return originalLoad(request, parent, isMain);
183
+ } catch {
184
+ mockedModules.add(request);
185
+ return createGenericMock();
186
+ }
136
187
  };
137
188
  }
138
189
  function parseTsconfigAliases(projectRoot) {
@@ -151,7 +202,16 @@ function parseTsconfigAliases(projectRoot) {
151
202
  if (fs.existsSync(srcPath)) {
152
203
  aliases["src/"] = `${srcPath}/`;
153
204
  }
205
+ for (const ext of JS_EXTENSIONS) {
206
+ const envFile = joinPath(projectRoot, `env${ext}`);
207
+ if (fs.existsSync(envFile)) {
208
+ aliases["env"] = createMockFile("env");
209
+ break;
210
+ }
211
+ }
154
212
  }
213
+ aliases["server-only"] = createMockFile("server-only");
214
+ aliases["client-only"] = createMockFile("client-only");
155
215
  for (const [pattern, targets] of Object.entries(paths)) {
156
216
  const target = targets[0];
157
217
  if (!target) continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onruntime/next-sitemap",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Dynamic sitemap generation for Next.js with automatic route discovery",
5
5
  "author": "onRuntime Studio <contact@onruntime.com>",
6
6
  "repository": {