@power-seo/sitemap 1.0.0 → 1.0.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/README.md CHANGED
@@ -1,362 +1,378 @@
1
- # @power-seo/sitemap — XML Sitemap Generator for TypeScript — Streaming, Index Splitting & Image/Video/News Extensions
2
-
3
- [![npm version](https://img.shields.io/npm/v/@power-seo/sitemap)](https://www.npmjs.com/package/@power-seo/sitemap)
4
- [![npm downloads](https://img.shields.io/npm/dm/@power-seo/sitemap)](https://www.npmjs.com/package/@power-seo/sitemap)
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue)](https://www.typescriptlang.org/)
7
- [![tree-shakeable](https://img.shields.io/badge/tree--shakeable-yes-brightgreen)](https://bundlephobia.com/package/@power-seo/sitemap)
8
-
9
- ---
10
-
11
- ## Overview
12
-
13
- **@power-seo/sitemap** is a zero-dependency XML sitemap generator for TypeScript that helps you generate standards-compliant sitemaps with image, video, and news extensions — including streaming generation and automatic index splitting for large sites.
14
-
15
- **What it does**
16
- - ✅ **Generate XML sitemaps** — `generateSitemap()` produces spec-compliant `<urlset>` XML strings
17
- - ✅ **Stream large sitemaps** — `streamSitemap()` yields XML chunks with constant memory usage
18
- - ✅ **Split into multiple files** — `splitSitemap()` auto-chunks at the 50,000-URL limit
19
- - ✅ **Generate sitemap indexes** — `generateSitemapIndex()` creates `<sitemapindex>` files pointing to child sitemaps
20
- - ✅ **Validate URL entries** — `validateSitemapUrl()` checks against Google's sitemap spec requirements
21
-
22
- **What it is not**
23
- - ❌ **Not a sitemap crawler** — does not discover URLs by crawling your site
24
- - ❌ **Not a submission client** — use `@power-seo/search-console` to submit sitemaps to GSC
25
-
26
- **Recommended for**
27
- - **Next.js App Router sites**, **Remix apps**, **Express servers**, **static site generators**, and any Node.js/edge environment that generates sitemaps programmatically
28
-
29
- ---
30
-
31
- ## Why @power-seo/sitemap Matters
32
-
33
- **The problem**
34
- - **Sites with 50,000+ URLs** cannot fit in a single sitemap file — the spec mandates splitting
35
- - **Image and video sitemaps** require `<image:image>` and `<video:video>` namespace extensions that most generators don't support
36
- - **Memory spikes** during XML string concatenation cause crashes or timeouts on large e-commerce catalogs
37
-
38
- **Why developers care**
39
- - **SEO:** Well-structured sitemaps improve crawl coverage and ensure all pages are discovered
40
- - **Performance:** Streaming generation keeps memory usage constant for million-URL datasets
41
- - **Indexing:** Image sitemaps help Google discover and index product images for Google Images
42
-
43
- ---
44
-
45
- ## Key Features
46
-
47
- - **Full sitemap spec support** — `<loc>`, `<lastmod>`, `<changefreq>`, `<priority>`, and all optional elements
48
- - **Image sitemap extension** — `<image:image>` tags with `loc`, `caption`, `title`, `license`
49
- - **Video sitemap extension** — `<video:video>` tags with title, description, thumbnail, duration
50
- - **News sitemap extension** — `<news:news>` tags with publication name, language, date
51
- - **Streaming generation** — `streamSitemap()` returns `AsyncIterable<string>` — no memory spike on large lists
52
- - **Automatic index splitting** — `splitSitemap()` chunks at `MAX_URLS_PER_SITEMAP` (50,000)
53
- - **Sitemap index generation** — `generateSitemapIndex()` creates a `<sitemapindex>` pointing to child sitemaps
54
- - **URL validation** — `validateSitemapUrl()` returns `{ valid, errors, warnings }` without throwing
55
- - **Constants exported** — `MAX_URLS_PER_SITEMAP` (50,000) and `MAX_SITEMAP_SIZE_BYTES` (50MB)
56
- - **Framework-agnostic** — works in Next.js API routes, Remix loaders, Express, Fastify, and edge runtimes
57
- - **Full TypeScript support** — typed `SitemapURL`, `SitemapImage`, `SitemapVideo`, `SitemapNews`, `SitemapConfig`
58
- - **Zero runtime dependencies** — pure TypeScript, no external XML libraries
59
-
60
- ---
61
-
62
- ## Benefits of Using @power-seo/sitemap
63
-
64
- - **Improved crawl coverage**: Well-structured sitemaps with `lastmod` help Googlebot prioritize fresh pages
65
- - **Better image indexing**: `<image:image>` extensions surface product images in Google Images
66
- - **Safer implementation**: `validateSitemapUrl()` catches out-of-range `priority` values and invalid dates before serving
67
- - **Faster delivery**: Zero-dependency streaming generation works in any runtime without configuration
68
-
69
- ---
70
-
71
- ## Quick Start
72
-
73
- ```ts
74
- import { generateSitemap } from '@power-seo/sitemap';
75
-
76
- const xml = generateSitemap({
77
- urls: [
78
- { loc: 'https://example.com/', lastmod: '2026-01-01', changefreq: 'daily', priority: 1.0 },
79
- { loc: 'https://example.com/about', changefreq: 'monthly', priority: 0.8 },
80
- { loc: 'https://example.com/blog/post-1', lastmod: '2026-01-15', priority: 0.6 },
81
- ],
82
- });
83
-
84
- // Returns valid XML string:
85
- // <?xml version="1.0" encoding="UTF-8"?>
86
- // <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">...
87
- ```
88
-
89
- **What you should see**
90
- - A standards-compliant XML sitemap string ready to serve as `Content-Type: application/xml`
91
- - `<urlset>` containing `<url>` entries with the fields you provided
92
-
93
- ---
94
-
95
- ## Installation
96
-
97
- ```bash
98
- npm i @power-seo/sitemap
99
- # or
100
- yarn add @power-seo/sitemap
101
- # or
102
- pnpm add @power-seo/sitemap
103
- # or
104
- bun add @power-seo/sitemap
105
- ```
106
-
107
- ---
108
-
109
- ## Framework Compatibility
110
-
111
- **Supported**
112
- - ✅ Next.js App Router — use in `app/sitemap.xml/route.ts` API route
113
- - ✅ Next.js Pages Router — use in `pages/api/sitemap.xml.ts`
114
- - ✅ Remix — use in resource routes
115
- - Node.js 18+ — pure TypeScript, no native bindings
116
- - ✅ Edge runtimes — no `fs`, no `path`, no Node.js-specific APIs (except `streamSitemap` which uses `AsyncIterable`)
117
- - ✅ Fastify / Express — serve the XML string as response body
118
-
119
- **Environment notes**
120
- - **SSR/SSG:** Fully supportedgenerate at request time or at build time
121
- - **Edge runtime:** `generateSitemap()` and `generateSitemapIndex()` are edge-compatible; `streamSitemap()` requires Node.js streams if writing to disk
122
- - **Browser-only usage:** Not applicable sitemap generation is a server-side concern
123
-
124
- ---
125
-
126
- ## Use Cases
127
-
128
- - **Next.js SSG sites** — generate a full sitemap from your CMS at build time
129
- - **E-commerce catalogs** product image sitemaps with `<image:image>` for every listing
130
- - **News publishers**`<news:news>` extension for Google News sitemap submission
131
- - **Multi-locale sites** — separate sitemaps per locale with a unified sitemap index
132
- - **Programmatic SEO** — generate sitemaps for thousands of auto-generated pages
133
- - **Large sites** — automatic splitting at 50,000 URLs per file with index generation
134
- - **Video platforms** — `<video:video>` extension for YouTube-style video SEO
135
-
136
- ---
137
-
138
- ## Example (Before / After)
139
-
140
- ```text
141
- Before:
142
- - Hand-built XML strings: missing namespace declarations, wrong date formats
143
- - Single 80,000-URL sitemap: invalid per spec (max 50,000), Google truncates
144
- - No image sitemap: product images not discovered by Googlebot Images
145
-
146
- After (@power-seo/sitemap):
147
- - generateSitemap({ urls }) → spec-compliant XML with correct namespace
148
- - splitSitemap(allUrls) + generateSitemapIndex() → auto-split + index file
149
- - urls[i].images = [{ loc, caption }] → <image:image> tags for each product
150
- ```
151
-
152
- ---
153
-
154
- ## Implementation Best Practices
155
-
156
- - **Always include `lastmod`** Googlebot uses it to prioritize re-crawling updated pages
157
- - **Keep `priority` values realistic** setting everything to 1.0 signals ignored priority; reserve 1.0 for the homepage
158
- - **Use `changefreq: 'never'` for permanent content** — signals Googlebot to skip re-crawling
159
- - **Set `sitemap.xml` URL in `robots.txt`** — `Sitemap: https://example.com/sitemap.xml` is required for discovery
160
- - **Submit to Google Search Console** after generating — use `@power-seo/search-console` `submitSitemap()`
161
-
162
- ---
163
-
164
- ## Architecture Overview
165
-
166
- **Where it runs**
167
- - **Build-time**: Generate static `sitemap.xml` files during `next build` or Remix production builds
168
- - **Runtime**: Serve dynamically from an API route; regenerate on demand or on ISR revalidation
169
- - **CI/CD**: Validate sitemap URL entries as part of pull request checks
170
-
171
- **Data flow**
172
- 1. **Input**: Array of `SitemapURL` objects with `loc`, `lastmod`, optional images/videos/news
173
- 2. **Analysis**: Spec validation, namespace detection, XML serialization
174
- 3. **Output**: Valid XML string or `AsyncIterable<string>` stream
175
- 4. **Action**: Serve as `application/xml`, write to disk, or submit to GSC via `@power-seo/search-console`
176
-
177
- ---
178
-
179
- ## Features Comparison with Popular Packages
180
-
181
- | Capability | next-sitemap | sitemap (npm) | xmlbuilder2 | @power-seo/sitemap |
182
- |---|---:|---:|---:|---:|
183
- | Image sitemap extension | | ✅ | ❌ | ✅ |
184
- | Video sitemap extension | | ✅ | ❌ | ✅ |
185
- | News sitemap extension | | | | |
186
- | Streaming generation | ❌ | ❌ | ❌ | ✅ |
187
- | Auto index splitting | ✅ | ❌ | ❌ | ✅ |
188
- | URL validation | ❌ | ❌ | ❌ | ✅ |
189
- | Zero runtime dependencies | ❌ | ❌ | ❌ | ✅ |
190
- | Edge runtime compatible | ❌ | ❌ | ❌ | ✅ |
191
-
192
- ---
193
-
194
- ## @power-seo Ecosystem
195
-
196
- All 17 packages are independently installable — use only what you need.
197
-
198
- | Package | Install | Description |
199
- |---------|---------|-------------|
200
- | [`@power-seo/core`](https://www.npmjs.com/package/@power-seo/core) | `npm i @power-seo/core` | Framework-agnostic utilities, types, validators, and constants |
201
- | [`@power-seo/react`](https://www.npmjs.com/package/@power-seo/react) | `npm i @power-seo/react` | React SEO components — meta, Open Graph, Twitter Card, breadcrumbs |
202
- | [`@power-seo/meta`](https://www.npmjs.com/package/@power-seo/meta) | `npm i @power-seo/meta` | SSR meta helpers for Next.js App Router, Remix v2, and generic SSR |
203
- | [`@power-seo/schema`](https://www.npmjs.com/package/@power-seo/schema) | `npm i @power-seo/schema` | Type-safe JSON-LD structured data — 20 builders + 18 React components |
204
- | [`@power-seo/content-analysis`](https://www.npmjs.com/package/@power-seo/content-analysis) | `npm i @power-seo/content-analysis` | Yoast-style SEO content scoring engine with React components |
205
- | [`@power-seo/readability`](https://www.npmjs.com/package/@power-seo/readability) | `npm i @power-seo/readability` | Readability scoring — Flesch-Kincaid, Gunning Fog, Coleman-Liau, ARI |
206
- | [`@power-seo/preview`](https://www.npmjs.com/package/@power-seo/preview) | `npm i @power-seo/preview` | SERP, Open Graph, and Twitter/X Card preview generators |
207
- | [`@power-seo/sitemap`](https://www.npmjs.com/package/@power-seo/sitemap) | `npm i @power-seo/sitemap` | XML sitemap generation, streaming, index splitting, and validation |
208
- | [`@power-seo/redirects`](https://www.npmjs.com/package/@power-seo/redirects) | `npm i @power-seo/redirects` | Redirect engine with Next.js, Remix, and Express adapters |
209
- | [`@power-seo/links`](https://www.npmjs.com/package/@power-seo/links) | `npm i @power-seo/links` | Link graph analysis — orphan detection, suggestions, equity scoring |
210
- | [`@power-seo/audit`](https://www.npmjs.com/package/@power-seo/audit) | `npm i @power-seo/audit` | Full SEO audit engine — meta, content, structure, performance rules |
211
- | [`@power-seo/images`](https://www.npmjs.com/package/@power-seo/images) | `npm i @power-seo/images` | Image SEO — alt text, lazy loading, format analysis, image sitemaps |
212
- | [`@power-seo/ai`](https://www.npmjs.com/package/@power-seo/ai) | `npm i @power-seo/ai` | LLM-agnostic AI prompt templates and parsers for SEO tasks |
213
- | [`@power-seo/analytics`](https://www.npmjs.com/package/@power-seo/analytics) | `npm i @power-seo/analytics` | Merge GSC + audit data, trend analysis, ranking insights, dashboard |
214
- | [`@power-seo/search-console`](https://www.npmjs.com/package/@power-seo/search-console) | `npm i @power-seo/search-console` | Google Search Console API OAuth2, service account, URL inspection |
215
- | [`@power-seo/integrations`](https://www.npmjs.com/package/@power-seo/integrations) | `npm i @power-seo/integrations` | Semrush and Ahrefs API clients with rate limiting and pagination |
216
- | [`@power-seo/tracking`](https://www.npmjs.com/package/@power-seo/tracking) | `npm i @power-seo/tracking` | GA4, Clarity, PostHog, Plausible, Fathom scripts + consent management |
217
-
218
- ### Ecosystem vs alternatives
219
-
220
- | Need | Common approach | @power-seo approach |
221
- |---|---|---|
222
- | Sitemap generation | `next-sitemap` | `@power-seo/sitemap` streaming, image, video, news |
223
- | Sitemap submission | Manual GSC UI | `@power-seo/search-console` `submitSitemap()` |
224
- | Image SEO | Manual `<image:image>` | `@power-seo/sitemap` + `@power-seo/images` |
225
- | Structured data | Manual JSON-LD | `@power-seo/schema` typed builders |
226
-
227
- ---
228
-
229
- ## Enterprise Integration
230
-
231
- **Multi-tenant SaaS**
232
- - **Per-tenant sitemaps**: Generate separate sitemaps per client domain; serve from tenant-aware API routes
233
- - **Sitemap index**: Use `generateSitemapIndex()` to aggregate tenant sitemaps into a root index
234
- - **Scheduled regeneration**: Rebuild sitemaps nightly as new content is published
235
-
236
- **ERP / internal portals**
237
- - Generate sitemaps only for public-facing modules (knowledge base, product catalog)
238
- - Use `validateSitemapUrl()` to enforce URL format standards across generated entries
239
- - Pipe large catalogs through `streamSitemap()` to avoid memory limits in serverless environments
240
-
241
- **Recommended integration pattern**
242
- - Generate sitemaps in **CI** at build time for static content
243
- - Serve dynamically from **API routes** for frequently updated content
244
- - Submit new sitemaps to GSC via `@power-seo/search-console` after deployment
245
- - Monitor crawl coverage in Google Search Console
246
-
247
- ---
248
-
249
- ## Scope and Limitations
250
-
251
- **This package does**
252
- - ✅ Generate spec-compliant XML sitemaps from URL arrays
253
- - Support image, video, and news sitemap extensions
254
- - ✅ Stream large sitemaps to avoid memory spikes
255
- - Split sitemaps and generate sitemap index files
256
-
257
- **This package does not**
258
- - Crawl your site to discover URLs — you provide the URL list
259
- - ❌ Submit sitemaps to Google — use `@power-seo/search-console` for submission
260
- - ❌ Monitor sitemap status — use Google Search Console for crawl coverage reports
261
-
262
- ---
263
-
264
- ## API Reference
265
-
266
- ### `generateSitemap(config)`
267
-
268
- ```ts
269
- function generateSitemap(config: SitemapConfig): string
270
- ```
271
-
272
- | Prop | Type | Description |
273
- |------|------|-------------|
274
- | `urls` | `SitemapURL[]` | Array of URL entries |
275
-
276
- #### `SitemapURL`
277
-
278
- | Prop | Type | Default | Description |
279
- |------|------|---------|-------------|
280
- | `loc` | `string` | — | **Required.** Absolute URL |
281
- | `lastmod` | `string` | — | Last modified (ISO 8601 or `YYYY-MM-DD`) |
282
- | `changefreq` | `'always' \| 'hourly' \| 'daily' \| 'weekly' \| 'monthly' \| 'yearly' \| 'never'` | — | Change frequency |
283
- | `priority` | `number` | `0.5` | Priority 0.0–1.0 |
284
- | `images` | `SitemapImage[]` | — | Image extension entries |
285
- | `videos` | `SitemapVideo[]` | — | Video extension entries |
286
- | `news` | `SitemapNews` | — | News extension entry |
287
-
288
- ### `streamSitemap(config)`
289
-
290
- ```ts
291
- function streamSitemap(config: SitemapConfig): AsyncIterable<string>
292
- ```
293
-
294
- Returns an async iterable that yields XML chunks. Suitable for piping to a Node.js `Writable`.
295
-
296
- ### `splitSitemap(urls, maxPerFile?)`
297
-
298
- ```ts
299
- function splitSitemap(urls: SitemapURL[], maxPerFile?: number): SitemapURL[][]
300
- ```
301
-
302
- Splits `urls` into chunks of at most `maxPerFile` (default: `MAX_URLS_PER_SITEMAP` = 50,000).
303
-
304
- ### `generateSitemapIndex(config)`
305
-
306
- ```ts
307
- function generateSitemapIndex(config: SitemapIndexConfig): string
308
- ```
309
-
310
- | Prop | Type | Description |
311
- |------|------|-------------|
312
- | `sitemaps` | `SitemapIndexEntry[]` | Array of `{ loc: string; lastmod?: string }` |
313
-
314
- ### `validateSitemapUrl(url)`
315
-
316
- ```ts
317
- function validateSitemapUrl(url: SitemapURL): SitemapValidationResult
318
- ```
319
-
320
- Returns `{ valid: boolean; errors: string[]; warnings: string[] }`.
321
-
322
- ---
323
-
324
- ## Contributing
325
-
326
- - Issues: [github.com/cybercraftbd/power-seo/issues](https://github.com/cybercraftbd/power-seo/issues)
327
- - PRs: [github.com/cybercraftbd/power-seo/pulls](https://github.com/cybercraftbd/power-seo/pulls)
328
- - Development setup:
329
- 1. `pnpm i`
330
- 2. `pnpm build`
331
- 3. `pnpm test`
332
-
333
- **Release workflow**
334
- - `npm version patch|minor|major`
335
- - `npm publish --access public`
336
-
337
- ---
338
-
339
- ## About CyberCraft Bangladesh
340
-
341
- **CyberCraft Bangladesh** is a Bangladesh-based enterprise-grade software engineering company specializing in ERP system development, AI-powered SaaS and business applications, full-stack SEO services, custom website development, and scalable eCommerce platforms. We design and develop intelligent, automation-driven SaaS and enterprise solutions that help startups, SMEs, NGOs, educational institutes, and large organizations streamline operations, enhance digital visibility, and accelerate growth through modern cloud-native technologies.
342
-
343
- | | |
344
- |---|---|
345
- | **Website** | [ccbd.dev](https://ccbd.dev) |
346
- | **GitHub** | [github.com/cybercraftbd](https://github.com/cybercraftbd) |
347
- | **npm Organization** | [npmjs.com/org/power-seo](https://www.npmjs.com/org/power-seo) |
348
- | **Email** | [info@ccbd.dev](mailto:info@ccbd.dev) |
349
-
350
- ---
351
-
352
- ## License
353
-
354
- **MIT**
355
-
356
- ---
357
-
358
- ## Keywords
359
-
360
- ```text
361
- seo, sitemap, xml-sitemap, sitemap-generator, image-sitemap, video-sitemap, news-sitemap, sitemap-index, typescript, nextjs, remix, streaming, crawl-budget, google-indexing
362
- ```
1
+ # @power-seo/sitemap — XML Sitemap Generator for TypeScript — Streaming, Index Splitting & Image/Video/News Extensions
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@power-seo/sitemap)](https://www.npmjs.com/package/@power-seo/sitemap)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@power-seo/sitemap)](https://www.npmjs.com/package/@power-seo/sitemap)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue)](https://www.typescriptlang.org/)
7
+ [![tree-shakeable](https://img.shields.io/badge/tree--shakeable-yes-brightgreen)](https://bundlephobia.com/package/@power-seo/sitemap)
8
+
9
+ ---
10
+
11
+ ## Overview
12
+
13
+ **@power-seo/sitemap** is a zero-dependency XML sitemap generator for TypeScript that helps you generate standards-compliant sitemaps with image, video, and news extensions — including streaming generation and automatic index splitting for large sites.
14
+
15
+ **What it does**
16
+
17
+ - ✅ **Generate XML sitemaps** — `generateSitemap()` produces spec-compliant `<urlset>` XML strings
18
+ - ✅ **Stream large sitemaps** — `streamSitemap()` yields XML chunks with constant memory usage
19
+ - ✅ **Split into multiple files** — `splitSitemap()` auto-chunks at the 50,000-URL limit
20
+ - ✅ **Generate sitemap indexes** — `generateSitemapIndex()` creates `<sitemapindex>` files pointing to child sitemaps
21
+ - ✅ **Validate URL entries** — `validateSitemapUrl()` checks against Google's sitemap spec requirements
22
+
23
+ **What it is not**
24
+
25
+ - ❌ **Not a sitemap crawler** — does not discover URLs by crawling your site
26
+ - ❌ **Not a submission client** — use `@power-seo/search-console` to submit sitemaps to GSC
27
+
28
+ **Recommended for**
29
+
30
+ - **Next.js App Router sites**, **Remix apps**, **Express servers**, **static site generators**, and any Node.js/edge environment that generates sitemaps programmatically
31
+
32
+ ---
33
+
34
+ ## Why @power-seo/sitemap Matters
35
+
36
+ **The problem**
37
+
38
+ - **Sites with 50,000+ URLs** cannot fit in a single sitemap file — the spec mandates splitting
39
+ - **Image and video sitemaps** require `<image:image>` and `<video:video>` namespace extensions that most generators don't support
40
+ - **Memory spikes** during XML string concatenation cause crashes or timeouts on large e-commerce catalogs
41
+
42
+ **Why developers care**
43
+
44
+ - **SEO:** Well-structured sitemaps improve crawl coverage and ensure all pages are discovered
45
+ - **Performance:** Streaming generation keeps memory usage constant for million-URL datasets
46
+ - **Indexing:** Image sitemaps help Google discover and index product images for Google Images
47
+
48
+ ---
49
+
50
+ ## Key Features
51
+
52
+ - **Full sitemap spec support** — `<loc>`, `<lastmod>`, `<changefreq>`, `<priority>`, and all optional elements
53
+ - **Image sitemap extension** — `<image:image>` tags with `loc`, `caption`, `title`, `license`
54
+ - **Video sitemap extension** — `<video:video>` tags with title, description, thumbnail, duration
55
+ - **News sitemap extension** — `<news:news>` tags with publication name, language, date
56
+ - **Streaming generation** — `streamSitemap()` returns `AsyncIterable<string>` no memory spike on large lists
57
+ - **Automatic index splitting** — `splitSitemap()` chunks at `MAX_URLS_PER_SITEMAP` (50,000)
58
+ - **Sitemap index generation** — `generateSitemapIndex()` creates a `<sitemapindex>` pointing to child sitemaps
59
+ - **URL validation** — `validateSitemapUrl()` returns `{ valid, errors, warnings }` without throwing
60
+ - **Constants exported** — `MAX_URLS_PER_SITEMAP` (50,000) and `MAX_SITEMAP_SIZE_BYTES` (50MB)
61
+ - **Framework-agnostic** — works in Next.js API routes, Remix loaders, Express, Fastify, and edge runtimes
62
+ - **Full TypeScript support** — typed `SitemapURL`, `SitemapImage`, `SitemapVideo`, `SitemapNews`, `SitemapConfig`
63
+ - **Zero runtime dependencies** — pure TypeScript, no external XML libraries
64
+
65
+ ---
66
+
67
+ ## Benefits of Using @power-seo/sitemap
68
+
69
+ - **Improved crawl coverage**: Well-structured sitemaps with `lastmod` help Googlebot prioritize fresh pages
70
+ - **Better image indexing**: `<image:image>` extensions surface product images in Google Images
71
+ - **Safer implementation**: `validateSitemapUrl()` catches out-of-range `priority` values and invalid dates before serving
72
+ - **Faster delivery**: Zero-dependency streaming generation works in any runtime without configuration
73
+
74
+ ---
75
+
76
+ ## Quick Start
77
+
78
+ ```ts
79
+ import { generateSitemap } from '@power-seo/sitemap';
80
+
81
+ const xml = generateSitemap({
82
+ urls: [
83
+ { loc: 'https://example.com/', lastmod: '2026-01-01', changefreq: 'daily', priority: 1.0 },
84
+ { loc: 'https://example.com/about', changefreq: 'monthly', priority: 0.8 },
85
+ { loc: 'https://example.com/blog/post-1', lastmod: '2026-01-15', priority: 0.6 },
86
+ ],
87
+ });
88
+
89
+ // Returns valid XML string:
90
+ // <?xml version="1.0" encoding="UTF-8"?>
91
+ // <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">...
92
+ ```
93
+
94
+ **What you should see**
95
+
96
+ - A standards-compliant XML sitemap string ready to serve as `Content-Type: application/xml`
97
+ - `<urlset>` containing `<url>` entries with the fields you provided
98
+
99
+ ---
100
+
101
+ ## Installation
102
+
103
+ ```bash
104
+ npm i @power-seo/sitemap
105
+ # or
106
+ yarn add @power-seo/sitemap
107
+ # or
108
+ pnpm add @power-seo/sitemap
109
+ # or
110
+ bun add @power-seo/sitemap
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Framework Compatibility
116
+
117
+ **Supported**
118
+
119
+ - ✅ Next.js App Router — use in `app/sitemap.xml/route.ts` API route
120
+ - Next.js Pages Router use in `pages/api/sitemap.xml.ts`
121
+ - Remix use in resource routes
122
+ - Node.js 18+pure TypeScript, no native bindings
123
+ - ✅ Edge runtimes — no `fs`, no `path`, no Node.js-specific APIs (except `streamSitemap` which uses `AsyncIterable`)
124
+ - ✅ Fastify / Express — serve the XML string as response body
125
+
126
+ **Environment notes**
127
+
128
+ - **SSR/SSG:** Fully supported — generate at request time or at build time
129
+ - **Edge runtime:** `generateSitemap()` and `generateSitemapIndex()` are edge-compatible; `streamSitemap()` requires Node.js streams if writing to disk
130
+ - **Browser-only usage:** Not applicable sitemap generation is a server-side concern
131
+
132
+ ---
133
+
134
+ ## Use Cases
135
+
136
+ - **Next.js SSG sites** — generate a full sitemap from your CMS at build time
137
+ - **E-commerce catalogs** — product image sitemaps with `<image:image>` for every listing
138
+ - **News publishers** `<news:news>` extension for Google News sitemap submission
139
+ - **Multi-locale sites** — separate sitemaps per locale with a unified sitemap index
140
+ - **Programmatic SEO** — generate sitemaps for thousands of auto-generated pages
141
+ - **Large sites** — automatic splitting at 50,000 URLs per file with index generation
142
+ - **Video platforms** — `<video:video>` extension for YouTube-style video SEO
143
+
144
+ ---
145
+
146
+ ## Example (Before / After)
147
+
148
+ ```text
149
+ Before:
150
+ - Hand-built XML strings: missing namespace declarations, wrong date formats
151
+ - Single 80,000-URL sitemap: invalid per spec (max 50,000), Google truncates
152
+ - No image sitemap: product images not discovered by Googlebot Images
153
+
154
+ After (@power-seo/sitemap):
155
+ - generateSitemap({ urls }) → spec-compliant XML with correct namespace
156
+ - splitSitemap(allUrls) + generateSitemapIndex() auto-split + index file
157
+ - urls[i].images = [{ loc, caption }] <image:image> tags for each product
158
+ ```
159
+
160
+ ---
161
+
162
+ ## Implementation Best Practices
163
+
164
+ - **Always include `lastmod`** — Googlebot uses it to prioritize re-crawling updated pages
165
+ - **Keep `priority` values realistic** — setting everything to 1.0 signals ignored priority; reserve 1.0 for the homepage
166
+ - **Use `changefreq: 'never'` for permanent content** — signals Googlebot to skip re-crawling
167
+ - **Set `sitemap.xml` URL in `robots.txt`** `Sitemap: https://example.com/sitemap.xml` is required for discovery
168
+ - **Submit to Google Search Console** after generating use `@power-seo/search-console` `submitSitemap()`
169
+
170
+ ---
171
+
172
+ ## Architecture Overview
173
+
174
+ **Where it runs**
175
+
176
+ - **Build-time**: Generate static `sitemap.xml` files during `next build` or Remix production builds
177
+ - **Runtime**: Serve dynamically from an API route; regenerate on demand or on ISR revalidation
178
+ - **CI/CD**: Validate sitemap URL entries as part of pull request checks
179
+
180
+ **Data flow**
181
+
182
+ 1. **Input**: Array of `SitemapURL` objects with `loc`, `lastmod`, optional images/videos/news
183
+ 2. **Analysis**: Spec validation, namespace detection, XML serialization
184
+ 3. **Output**: Valid XML string or `AsyncIterable<string>` stream
185
+ 4. **Action**: Serve as `application/xml`, write to disk, or submit to GSC via `@power-seo/search-console`
186
+
187
+ ---
188
+
189
+ ## Features Comparison with Popular Packages
190
+
191
+ | Capability | next-sitemap | sitemap (npm) | xmlbuilder2 | @power-seo/sitemap |
192
+ | ------------------------- | -----------: | ------------: | ----------: | -----------------: |
193
+ | Image sitemap extension | ✅ | ✅ | ❌ | ✅ |
194
+ | Video sitemap extension | ❌ | ✅ | ❌ | ✅ |
195
+ | News sitemap extension | ❌ | ✅ | ❌ | ✅ |
196
+ | Streaming generation | ❌ | ❌ | ❌ | ✅ |
197
+ | Auto index splitting | ✅ | ❌ | ❌ | ✅ |
198
+ | URL validation | | ❌ | | ✅ |
199
+ | Zero runtime dependencies | ❌ | ❌ | ❌ | ✅ |
200
+ | Edge runtime compatible | | ❌ | ❌ | |
201
+
202
+ ---
203
+
204
+ ## @power-seo Ecosystem
205
+
206
+ All 17 packages are independently installable use only what you need.
207
+
208
+ | Package | Install | Description |
209
+ | ------------------------------------------------------------------------------------------ | ----------------------------------- | ----------------------------------------------------------------------- |
210
+ | [`@power-seo/core`](https://www.npmjs.com/package/@power-seo/core) | `npm i @power-seo/core` | Framework-agnostic utilities, types, validators, and constants |
211
+ | [`@power-seo/react`](https://www.npmjs.com/package/@power-seo/react) | `npm i @power-seo/react` | React SEO components meta, Open Graph, Twitter Card, breadcrumbs |
212
+ | [`@power-seo/meta`](https://www.npmjs.com/package/@power-seo/meta) | `npm i @power-seo/meta` | SSR meta helpers for Next.js App Router, Remix v2, and generic SSR |
213
+ | [`@power-seo/schema`](https://www.npmjs.com/package/@power-seo/schema) | `npm i @power-seo/schema` | Type-safe JSON-LD structured data 20 builders + 18 React components |
214
+ | [`@power-seo/content-analysis`](https://www.npmjs.com/package/@power-seo/content-analysis) | `npm i @power-seo/content-analysis` | Yoast-style SEO content scoring engine with React components |
215
+ | [`@power-seo/readability`](https://www.npmjs.com/package/@power-seo/readability) | `npm i @power-seo/readability` | Readability scoring Flesch-Kincaid, Gunning Fog, Coleman-Liau, ARI |
216
+ | [`@power-seo/preview`](https://www.npmjs.com/package/@power-seo/preview) | `npm i @power-seo/preview` | SERP, Open Graph, and Twitter/X Card preview generators |
217
+ | [`@power-seo/sitemap`](https://www.npmjs.com/package/@power-seo/sitemap) | `npm i @power-seo/sitemap` | XML sitemap generation, streaming, index splitting, and validation |
218
+ | [`@power-seo/redirects`](https://www.npmjs.com/package/@power-seo/redirects) | `npm i @power-seo/redirects` | Redirect engine with Next.js, Remix, and Express adapters |
219
+ | [`@power-seo/links`](https://www.npmjs.com/package/@power-seo/links) | `npm i @power-seo/links` | Link graph analysis — orphan detection, suggestions, equity scoring |
220
+ | [`@power-seo/audit`](https://www.npmjs.com/package/@power-seo/audit) | `npm i @power-seo/audit` | Full SEO audit engine — meta, content, structure, performance rules |
221
+ | [`@power-seo/images`](https://www.npmjs.com/package/@power-seo/images) | `npm i @power-seo/images` | Image SEO — alt text, lazy loading, format analysis, image sitemaps |
222
+ | [`@power-seo/ai`](https://www.npmjs.com/package/@power-seo/ai) | `npm i @power-seo/ai` | LLM-agnostic AI prompt templates and parsers for SEO tasks |
223
+ | [`@power-seo/analytics`](https://www.npmjs.com/package/@power-seo/analytics) | `npm i @power-seo/analytics` | Merge GSC + audit data, trend analysis, ranking insights, dashboard |
224
+ | [`@power-seo/search-console`](https://www.npmjs.com/package/@power-seo/search-console) | `npm i @power-seo/search-console` | Google Search Console API — OAuth2, service account, URL inspection |
225
+ | [`@power-seo/integrations`](https://www.npmjs.com/package/@power-seo/integrations) | `npm i @power-seo/integrations` | Semrush and Ahrefs API clients with rate limiting and pagination |
226
+ | [`@power-seo/tracking`](https://www.npmjs.com/package/@power-seo/tracking) | `npm i @power-seo/tracking` | GA4, Clarity, PostHog, Plausible, Fathom — scripts + consent management |
227
+
228
+ ### Ecosystem vs alternatives
229
+
230
+ | Need | Common approach | @power-seo approach |
231
+ | ------------------ | ---------------------- | ---------------------------------------------------- |
232
+ | Sitemap generation | `next-sitemap` | `@power-seo/sitemap` streaming, image, video, news |
233
+ | Sitemap submission | Manual GSC UI | `@power-seo/search-console` `submitSitemap()` |
234
+ | Image SEO | Manual `<image:image>` | `@power-seo/sitemap` + `@power-seo/images` |
235
+ | Structured data | Manual JSON-LD | `@power-seo/schema` — typed builders |
236
+
237
+ ---
238
+
239
+ ## Enterprise Integration
240
+
241
+ **Multi-tenant SaaS**
242
+
243
+ - **Per-tenant sitemaps**: Generate separate sitemaps per client domain; serve from tenant-aware API routes
244
+ - **Sitemap index**: Use `generateSitemapIndex()` to aggregate tenant sitemaps into a root index
245
+ - **Scheduled regeneration**: Rebuild sitemaps nightly as new content is published
246
+
247
+ **ERP / internal portals**
248
+
249
+ - Generate sitemaps only for public-facing modules (knowledge base, product catalog)
250
+ - Use `validateSitemapUrl()` to enforce URL format standards across generated entries
251
+ - Pipe large catalogs through `streamSitemap()` to avoid memory limits in serverless environments
252
+
253
+ **Recommended integration pattern**
254
+
255
+ - Generate sitemaps in **CI** at build time for static content
256
+ - Serve dynamically from **API routes** for frequently updated content
257
+ - Submit new sitemaps to GSC via `@power-seo/search-console` after deployment
258
+ - Monitor crawl coverage in Google Search Console
259
+
260
+ ---
261
+
262
+ ## Scope and Limitations
263
+
264
+ **This package does**
265
+
266
+ - ✅ Generate spec-compliant XML sitemaps from URL arrays
267
+ - ✅ Support image, video, and news sitemap extensions
268
+ - ✅ Stream large sitemaps to avoid memory spikes
269
+ - Split sitemaps and generate sitemap index files
270
+
271
+ **This package does not**
272
+
273
+ - ❌ Crawl your site to discover URLs — you provide the URL list
274
+ - Submit sitemaps to Google use `@power-seo/search-console` for submission
275
+ - ❌ Monitor sitemap status — use Google Search Console for crawl coverage reports
276
+
277
+ ---
278
+
279
+ ## API Reference
280
+
281
+ ### `generateSitemap(config)`
282
+
283
+ ```ts
284
+ function generateSitemap(config: SitemapConfig): string;
285
+ ```
286
+
287
+ | Prop | Type | Description |
288
+ | ------ | -------------- | -------------------- |
289
+ | `urls` | `SitemapURL[]` | Array of URL entries |
290
+
291
+ #### `SitemapURL`
292
+
293
+ | Prop | Type | Default | Description |
294
+ | ------------ | --------------------------------------------------------------------------------- | ------- | ---------------------------------------- |
295
+ | `loc` | `string` | — | **Required.** Absolute URL |
296
+ | `lastmod` | `string` | — | Last modified (ISO 8601 or `YYYY-MM-DD`) |
297
+ | `changefreq` | `'always' \| 'hourly' \| 'daily' \| 'weekly' \| 'monthly' \| 'yearly' \| 'never'` | — | Change frequency |
298
+ | `priority` | `number` | `0.5` | Priority 0.0–1.0 |
299
+ | `images` | `SitemapImage[]` | — | Image extension entries |
300
+ | `videos` | `SitemapVideo[]` | — | Video extension entries |
301
+ | `news` | `SitemapNews` | — | News extension entry |
302
+
303
+ ### `streamSitemap(config)`
304
+
305
+ ```ts
306
+ function streamSitemap(config: SitemapConfig): AsyncIterable<string>;
307
+ ```
308
+
309
+ Returns an async iterable that yields XML chunks. Suitable for piping to a Node.js `Writable`.
310
+
311
+ ### `splitSitemap(urls, maxPerFile?)`
312
+
313
+ ```ts
314
+ function splitSitemap(urls: SitemapURL[], maxPerFile?: number): SitemapURL[][];
315
+ ```
316
+
317
+ Splits `urls` into chunks of at most `maxPerFile` (default: `MAX_URLS_PER_SITEMAP` = 50,000).
318
+
319
+ ### `generateSitemapIndex(config)`
320
+
321
+ ```ts
322
+ function generateSitemapIndex(config: SitemapIndexConfig): string;
323
+ ```
324
+
325
+ | Prop | Type | Description |
326
+ | ---------- | --------------------- | -------------------------------------------- |
327
+ | `sitemaps` | `SitemapIndexEntry[]` | Array of `{ loc: string; lastmod?: string }` |
328
+
329
+ ### `validateSitemapUrl(url)`
330
+
331
+ ```ts
332
+ function validateSitemapUrl(url: SitemapURL): SitemapValidationResult;
333
+ ```
334
+
335
+ Returns `{ valid: boolean; errors: string[]; warnings: string[] }`.
336
+
337
+ ---
338
+
339
+ ## Contributing
340
+
341
+ - Issues: [github.com/cybercraftbd/power-seo/issues](https://github.com/cybercraftbd/power-seo/issues)
342
+ - PRs: [github.com/cybercraftbd/power-seo/pulls](https://github.com/cybercraftbd/power-seo/pulls)
343
+ - Development setup:
344
+ 1. `pnpm i`
345
+ 2. `pnpm build`
346
+ 3. `pnpm test`
347
+
348
+ **Release workflow**
349
+
350
+ - `npm version patch|minor|major`
351
+ - `npm publish --access public`
352
+
353
+ ---
354
+
355
+ ## About CyberCraft Bangladesh
356
+
357
+ **CyberCraft Bangladesh** is a Bangladesh-based enterprise-grade software engineering company specializing in ERP system development, AI-powered SaaS and business applications, full-stack SEO services, custom website development, and scalable eCommerce platforms. We design and develop intelligent, automation-driven SaaS and enterprise solutions that help startups, SMEs, NGOs, educational institutes, and large organizations streamline operations, enhance digital visibility, and accelerate growth through modern cloud-native technologies.
358
+
359
+ | | |
360
+ | -------------------- | -------------------------------------------------------------- |
361
+ | **Website** | [ccbd.dev](https://ccbd.dev) |
362
+ | **GitHub** | [github.com/cybercraftbd](https://github.com/cybercraftbd) |
363
+ | **npm Organization** | [npmjs.com/org/power-seo](https://www.npmjs.com/org/power-seo) |
364
+ | **Email** | [info@ccbd.dev](mailto:info@ccbd.dev) |
365
+
366
+ ---
367
+
368
+ ## License
369
+
370
+ **MIT**
371
+
372
+ ---
373
+
374
+ ## Keywords
375
+
376
+ ```text
377
+ seo, sitemap, xml-sitemap, sitemap-generator, image-sitemap, video-sitemap, news-sitemap, sitemap-index, typescript, nextjs, remix, streaming, crawl-budget, google-indexing
378
+ ```