@djangocfg/nextjs 2.1.413 → 2.1.416

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -14,7 +14,7 @@ var require_package = __commonJS({
14
14
  "package.json"(exports, module) {
15
15
  module.exports = {
16
16
  name: "@djangocfg/nextjs",
17
- version: "2.1.413",
17
+ version: "2.1.416",
18
18
  description: "Next.js server utilities: sitemap, health, OG images, contact forms, navigation, config",
19
19
  keywords: [
20
20
  "nextjs",
@@ -204,6 +204,11 @@ var require_package = __commonJS({
204
204
  }
205
205
  });
206
206
 
207
+ // src/sitemap/constants.ts
208
+ var STATIC_ID = "static";
209
+ var DEFAULT_INDEX_REVALIDATE = 600;
210
+ var DEFAULT_FEED_REVALIDATE = 3600;
211
+
207
212
  // src/sitemap/fetch.ts
208
213
  var EMPTY_INDEX = {
209
214
  sources: [],
@@ -264,9 +269,6 @@ function decodeChunkId(id) {
264
269
  }
265
270
 
266
271
  // src/sitemap/sitemap.ts
267
- var STATIC_ID = "static";
268
- var DEFAULT_INDEX_REVALIDATE = 600;
269
- var DEFAULT_FEED_REVALIDATE = 3600;
270
272
  function createDjangoSitemap(opts) {
271
273
  const {
272
274
  host,
@@ -310,6 +312,56 @@ function renderStatic(host, routes) {
310
312
  }));
311
313
  }
312
314
 
315
+ // src/sitemap/index-route.ts
316
+ function createSitemapIndex(opts) {
317
+ const {
318
+ host,
319
+ apiUrl,
320
+ indexRevalidate = DEFAULT_INDEX_REVALIDATE,
321
+ includeStatic = true
322
+ } = opts;
323
+ return {
324
+ async GET() {
325
+ const ids = includeStatic ? [STATIC_ID] : [];
326
+ if (apiUrl) {
327
+ const index = await fetchSitemapIndex(apiUrl, indexRevalidate);
328
+ for (const s of index.sources) {
329
+ for (const c of s.chunks) {
330
+ ids.push(encodeChunkId(s.name, c.cursor_to));
331
+ }
332
+ }
333
+ }
334
+ const lastmod = (/* @__PURE__ */ new Date()).toISOString();
335
+ const body = renderIndex(host, ids, lastmod);
336
+ return new Response(body, {
337
+ status: 200,
338
+ headers: {
339
+ "content-type": "application/xml; charset=utf-8",
340
+ // Mirror the per-chunk revalidate so a cached CDN edge expires
341
+ // at the same cadence as the index it points at.
342
+ "cache-control": `public, s-maxage=${indexRevalidate}, stale-while-revalidate=${indexRevalidate}`
343
+ }
344
+ });
345
+ }
346
+ };
347
+ }
348
+ function renderIndex(host, ids, lastmod) {
349
+ const lines = [];
350
+ lines.push('<?xml version="1.0" encoding="UTF-8"?>');
351
+ lines.push('<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
352
+ for (const id of ids) {
353
+ lines.push(" <sitemap>");
354
+ lines.push(` <loc>${escapeXml(`${host}/sitemap/${id}.xml`)}</loc>`);
355
+ lines.push(` <lastmod>${lastmod}</lastmod>`);
356
+ lines.push(" </sitemap>");
357
+ }
358
+ lines.push("</sitemapindex>");
359
+ return lines.join("\n");
360
+ }
361
+ function escapeXml(s) {
362
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
363
+ }
364
+
313
365
  // src/sitemap/robots.ts
314
366
  var DEFAULT_DISALLOW = ["/account/", "/auth", "/api/"];
315
367
  function createRobots(opts) {
@@ -1873,6 +1925,7 @@ export {
1873
1925
  createDjangoSitemap,
1874
1926
  createHealthHandler,
1875
1927
  createRobots,
1928
+ createSitemapIndex,
1876
1929
  decodeChunkId,
1877
1930
  deepMerge,
1878
1931
  defineRoute,