https://github.com/bartholomej/svelte-sitemap
Sitemap generator for SvelteKit. Small helper which scans your SvelteKit routes and generates static sitemap.xml
https://github.com/bartholomej/svelte-sitemap
cli generator javascript router sitemap-generator sitemap-xml static-adapter svelte svelte-library sveltejs sveltekit typescript typescript-library
Last synced: 3 months ago
JSON representation
Sitemap generator for SvelteKit. Small helper which scans your SvelteKit routes and generates static sitemap.xml
- Host: GitHub
- URL: https://github.com/bartholomej/svelte-sitemap
- Owner: bartholomej
- License: mit
- Created: 2021-06-09T13:47:06.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2026-04-07T17:55:46.000Z (4 months ago)
- Last Synced: 2026-04-07T19:27:09.840Z (4 months ago)
- Topics: cli, generator, javascript, router, sitemap-generator, sitemap-xml, static-adapter, svelte, svelte-library, sveltejs, sveltekit, typescript, typescript-library
- Language: TypeScript
- Homepage:
- Size: 4.92 MB
- Stars: 342
- Watchers: 3
- Forks: 10
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://badge.fury.io/js/svelte-sitemap)
[](https://www.npmjs.com/svelte-sitemap)
[](https://github.com/bartholomej/svelte-sitemap/actions)
# πΊοΈ Svelte `sitemap.xml` generator
**Generates `sitemap.xml` from your SvelteKit static routes β automatically, on every build.**
---
- β‘οΈ Designed for SvelteKit `adapter-static` with `prerender` option (SSG)
- π· TypeScript, JavaScript, CLI version
- π§ Useful [options](#%EF%B8%8F-options) for customizing your sitemap
- π‘ [Ping](#-ping-google-search-console) Google Search Console after deploy
- ποΈ Support for [sitemap index](https://developers.google.com/search/docs/crawling-indexing/sitemaps/large-sitemaps) for large sites (50K+ pages)
- β² π Works with [Vercel](#-vercel-adapter) and [Cloudflare](#-cloudflare-adapter) adapters and more...
## π¦ Install
```bash
npm install svelte-sitemap --save-dev
# yarn add svelte-sitemap --dev
# pnpm add -D svelte-sitemap
# bun add -d svelte-sitemap
```
## π Usage
> There are three ways to use this library. Pick the one that suits you best.
### β¨ Method 1: Config file (recommended)
Create a config file `svelte-sitemap.config.ts` in the root of your project:
```typescript
// svelte-sitemap.config.ts
import type { OptionsSvelteSitemap } from 'svelte-sitemap';
const config: OptionsSvelteSitemap = {
domain: 'https://www.example.com',
trailingSlashes: true
// ...more options below
};
export default config;
```
Then add `svelte-sitemap` as a `postbuild` script in `package.json`:
```json
{
"scripts": {
"postbuild": "npx svelte-sitemap"
}
}
```
That's it. After every `build`, the sitemap is automatically generated in your `build/` folder.
---
### β¨οΈ Method 2: CLI (legacy)
Pass options directly as CLI flags β no config file needed:
```json
{
"scripts": {
"postbuild": "npx svelte-sitemap --domain https://myawesomedomain.com"
}
}
```
See all available flags in the [Options](#%EF%B8%8F-options) table below.
---
### π§ Method 3: JavaScript / TypeScript API
Sometimes it's useful to call the script directly from code:
```typescript
// my-script.js
import { createSitemap } from 'svelte-sitemap';
createSitemap({ domain: 'https://example.com', debug: true });
```
Run your script:
```bash
node my-script.js
```
---
## βοΈ Options
Options are defined as **config file keys** (camelCase). Use it in your `svelte-sitemap.config.ts` file.
_The same options are also available as **CLI flags** for legacy use._
| Config key | CLI flag | Description | Default | Example |
| ----------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------- | ------------------------------------------- |
| `domain` | `--domain`, `-d` | Your domain **[required]** | - | `domain: 'https://mydomain.com'` |
| `outDir` | `--out-dir`, `-o` | Custom build folder | `build` | `outDir: 'dist'` |
| `additional` | `--additional`, `-a` | Additional pages outside of SvelteKit | - | `additional: ['my-page', 'my-second-page']` |
| `ignore` | `--ignore`, `-i` | Ignore files or folders (glob patterns) | `[]` | `ignore: ['**/admin/**', 'my-secret-page']` |
| `trailingSlashes` | `--trailing-slashes`, `-t` | Add trailing slashes | `false` | `trailingSlashes: true` |
| `resetTime` | `--reset-time`, `-r` | Set lastModified time to now | `false` | `resetTime: true` |
| `changeFreq` | `--change-freq`, `-c` | Set change frequency [options](https://github.com/bartholomej/svelte-sitemap/blob/master/src/dto/global.dto.ts#L23) | - | `changeFreq: 'daily'` |
| `debug` | `--debug` | Show some useful logs | - | `debug: true` |
| - | `--help`, `-h` | Display usage info | - | - |
| - | `--version`, `-v` | Show version | - | - |
## π FAQ
### π How to exclude a directory?
Use `ignore` with glob patterns. For example, to ignore all `admin` folders and one specific page:
```typescript
// svelte-sitemap.config.ts
import type { OptionsSvelteSitemap } from 'svelte-sitemap';
const config: OptionsSvelteSitemap = {
domain: 'https://www.example.com',
ignore: ['pages/my-secret-page', '**/admin/**']
};
```
---
### π‘ Ping Google Search Console
Every time you deploy a new version, you can inform Google that there's a new update.
See this [discussion](https://github.com/bartholomej/svelte-sitemap/issues/23) with very useful tips.
---
### β² Vercel adapter
If you're using `adapter-vercel`, the output directory is different from the default `build/`:
```typescript
// svelte-sitemap.config.ts
import type { OptionsSvelteSitemap } from 'svelte-sitemap';
const config: OptionsSvelteSitemap = {
domain: 'https://www.example.com',
outDir: '.vercel/output/static'
};
```
Or check out [other solutions](https://github.com/bartholomej/svelte-sitemap/issues/16#issuecomment-961414454) and join the discussion.
---
### π Cloudflare adapter
If you're using `@sveltejs/adapter-cloudflare`, you need to exclude `sitemap.xml` from Cloudflare's routing in `svelte.config.js`:
```diff
-import adapter from '@sveltejs/adapter-auto';
+import adapter from '@sveltejs/adapter-cloudflare';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
- adapter: adapter()
+ adapter: adapter({ routes: { include: ['/*'], exclude: ['', '/sitemap.xml'] }})
}
};
export default config;
```
---
## π Common issues
### β Error: Missing folder
```
Γ Folder 'build/' doesn't exist. Make sure you are using this library as 'postbuild'
so 'build/' folder was successfully created before running this script.
```
Make sure the output folder exists. If your build outputs to a different folder than `build/`, use the `outDir` option in your config file.
---
### β Error: Missing html files
```
Γ There is no static html file in your 'build/' folder.
Are you sure you are using Svelte adapter-static with prerender option?
```
This library is intended for `adapter-static` with the `prerender` option (SSG). If there are no static HTML files in your build folder, this library won't work for you :'(
---
## βοΈ Show your support
Give a βοΈ if this project helped you!
Or if you are brave enough consider [making a donation](https://github.com/sponsors/bartholomej) for some πΊ or π΅ ;)
## π΅οΈ Privacy Policy
I DO NOT STORE ANY DATA. PERIOD.
I physically can't. I have nowhere to store it. I don't even have a server database to store it. So even if Justin Bieber asked nicely to see your data, I wouldn't have anything to show him.
That's why, with this library, what happens on your device stays on your device till disappear.
## π€ Contributing
I welcome you to customize this according to your needs ;)
Pull requests for any improvements would be great!
Feel free to check [issues page](https://github.com/bartholomej/svelte-sitemap/issues).
### π οΈ Developing and debugging this library
```bash
git clone git@github.com:bartholomej/svelte-sitemap.git
cd svelte-sitemap
yarn
yarn start
```
#### Run demo locally
You can find and modify it in [`./demo.ts`](./demo.ts) file
```bash
yarn demo
```
## π Credits
- svelte-sitemap is a workaround for [this official SvelteKit issue](https://github.com/sveltejs/kit/issues/1142)
- Brand new version is inspired by [Richard's article](https://r-bt.com/learning/sveltekit-sitemap/)
- Thanks to [@auderer](https://github.com/auderer) because [his issue](https://github.com/bartholomej/svelte-sitemap/issues/1) changed the direction of this library
## π License
Copyright Β© 2026 [Lukas Bartak](http://bartweb.cz)
Proudly powered by nature π», wind π¨, tea π΅ and beer πΊ ;)
All contents are licensed under the [MIT license].
[mit license]: LICENSE