https://github.com/aminnairi/rollup-plugin-sitemap
Sitemap generator
https://github.com/aminnairi/rollup-plugin-sitemap
generator plugin rollup sitemap xml
Last synced: 2 months ago
JSON representation
Sitemap generator
- Host: GitHub
- URL: https://github.com/aminnairi/rollup-plugin-sitemap
- Owner: aminnairi
- License: gpl-3.0
- Created: 2022-09-09T09:43:55.000Z (almost 4 years ago)
- Default Branch: development
- Last Pushed: 2024-03-29T17:00:25.000Z (over 2 years ago)
- Last Synced: 2025-02-17T11:49:01.156Z (over 1 year ago)
- Topics: generator, plugin, rollup, sitemap, xml
- Language: TypeScript
- Homepage:
- Size: 46.9 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# @aminnairi/rollup-plugin-sitemap
[](https://www.npmjs.com/package/@aminnairi/rollup-plugin-sitemap)
[](https://www.typescriptlang.org/)
[](LICENSE)
[]()
Sitemap generator
## Installation
```bash
npm install rollup @aminnairi/rollup-plugin-sitemap
touch rollup.config.js
```
## Configuration
```javascript
import { defineConfig } from "rollup"
import { sitemap } from "@aminnairi/rollup-plugin-sitemap"
export default defineConfig({
input: "index.js",
plugins: [
sitemap({
baseUrl: "https://domain.com",
urls: [
{ location: "/" },
{ location: "/about" }
{ location: "/contact" }
]
})
],
output: {
file: "build/index.js",
format: "esm"
}
})
```
```xml
cat build/sitemap.xml
https://domain.com/
https://domain.com/about
https://domain.com/contact
```
## Configuration with last modification
```javascript
import { defineConfig } from "rollup"
import { sitemap } from "@aminnairi/rollup-plugin-sitemap"
export default defineConfig({
input: "index.js",
plugins: [
sitemap({
baseUrl: "https://domain.com",
urls: [
{
location: "/",
lastModified: new Date()
},
{
location: "/about",
lastModified: new Date()
}
{
location: "/contact",
lastModified: new Date()
}
]
})
],
output: {
file: "build/index.js",
format: "esm"
}
})
```
```xml
cat build/sitemap.xml
https://domain.com/
2022-09-09
https://domain.com/about
2022-09-09
https://domain.com/contact
2022-09-09
```
## Configuration with change frequency
```javascript
import { defineConfig } from "rollup"
import { sitemap } from "@aminnairi/rollup-plugin-sitemap"
export default defineConfig({
input: "index.js",
plugins: [
sitemap({
baseUrl: "https://domain.com",
urls: [
{
location: "/",
changeFrequency: "monthly"
},
{
location: "/about",
changeFrequency: "monthly"
}
{
location: "/contact",
changeFrequency: "monthly"
}
]
})
],
output: {
file: "build/index.js",
format: "esm"
}
})
```
```xml
cat build/sitemap.xml
https://domain.com/
monthly
https://domain.com/about
monthly
https://domain.com/contact
monthly
```
## Configuration with priority
```javascript
import { defineConfig } from "rollup"
import { sitemap } from "@aminnairi/rollup-plugin-sitemap"
export default defineConfig({
input: "index.js",
plugins: [
sitemap({
baseUrl: "https://domain.com",
urls: [
{
location: "/",
priority: 1
},
{
location: "/about",
priority: 1
}
{
location: "/contact",
priority: 1
}
]
})
],
output: {
file: "build/index.js",
format: "esm"
}
})
```
```xml
cat build/sitemap.xml
https://domain.com/
1
https://domain.com/about
1
https://domain.com/contact
1
```
## Configuration with custom path
By default, the sitemap is generated at `sitemap.xml`. You can customize this by using the `path` option:
```javascript
import { defineConfig } from "rollup";
import { sitemap } from "@aminnairi/rollup-plugin-sitemap";
export default defineConfig({
input: "index.js",
plugins: [
sitemap({
baseUrl: "https://domain.com",
path: "subcategory.sitemap.xml",
urls: [{ location: "/" }],
}),
],
output: {
file: "build/index.js",
format: "esm",
},
});
```
```xml
cat build/subcategory.sitemap.xml
https://domain.com/
```
## Configuration with robots.txt
You can also generate a `robots.txt` file alongside your sitemap using the `robots` option:
```javascript
import { defineConfig } from "rollup";
import { sitemap } from "@aminnairi/rollup-plugin-sitemap";
export default defineConfig({
input: "index.js",
plugins: [
sitemap({
baseUrl: "https://domain.com",
urls: [{ location: "/" }],
robots: {
sitemap: true,
},
}),
],
output: {
file: "build/index.js",
format: "esm",
},
});
```
```txt
cat build/robots.txt
Sitemap: https://domain.com/sitemap.xml
```
### Configuration with robots rules
You can add custom rules to the `robots.txt` file:
```javascript
import { defineConfig } from "rollup";
import { sitemap } from "@aminnairi/rollup-plugin-sitemap";
export default defineConfig({
input: "index.js",
plugins: [
sitemap({
baseUrl: "https://domain.com",
urls: [{ location: "/" }],
robots: {
sitemap: true,
rules: [
{
description: "Block GPT Bot from indexing",
userAgent: "GPTBot",
disallow: "/",
},
{
description: "Allow Google Bot to index everything",
userAgent: "Googlebot",
allow: "/",
},
],
},
}),
],
output: {
file: "build/index.js",
format: "esm",
},
});
```
```txt
cat build/robots.txt
Sitemap: https://domain.com/sitemap.xml
# Block GPT Bot from indexing
User-Agent: GPTBot
Disallow: /
# Allow Google Bot to index everything
User-Agent: Googlebot
Allow: /
```
## Types
This package exports TypeScript types for advanced configuration:
```typescript
import { defineConfig } from "rollup";
import {
sitemap,
type ChangeFrequency,
type Priority,
type Url,
type Robots,
type RobotsRule,
} from "@aminnairi/rollup-plugin-sitemap";
const changeFrequency: ChangeFrequency = "monthly";
const priority: Priority = 0.8;
const url: Url = {
location: "/",
lastModified: new Date(),
changeFrequency,
priority,
};
const robotsRule: RobotsRule = {
description: "Block GPT Bot",
userAgent: "GPTBot",
disallow: "/",
};
const robots: Robots = {
sitemap: true,
rules: [robotsRule],
};
export default defineConfig({
input: "index.js",
plugins: [
sitemap({
baseUrl: "https://domain.com",
urls: [url],
robots,
}),
],
output: {
file: "build/index.js",
format: "esm",
},
});
```
### ChangeFrequency
The `ChangeFrequency` type represents how often a page is likely to change. Possible values:
- `"always"` - For pages that change every time they are accessed
- `"hourly"` - For pages that change at least once an hour
- `"daily"` - For pages that change at least once a day
- `"weekly"` - For pages that change at least once a week
- `"monthly"` - For pages that change at least once a month
- `"yearly"` - For pages that change at least once a year
- `"never"` - For archived pages that will never change again
### Priority
The `Priority` type represents the importance of a page relative to other pages on your site. Possible values:
- `0`, `0.1`, `0.2`, `0.3`, `0.4`, `0.5`, `0.6`, `0.7`, `0.8`, `0.9`, `1`
## Contributing
See [`CONTRIBUTING.md`](./CONTRIBUTING.md).
## License
MIT License - see the [LICENSE](LICENSE) file for details.
## Changelog
### 1.0.1 (2026-03-13)
#### Features
- Added vitest testing framework with 100% code coverage
- Added GitHub Actions workflows:
- Development workflow (lint + build on `development` branch)
- Production workflow (lint + test + coverage + build on `production` branch)
- Added badges to README (npm, types, license, codecov)
#### Documentation
- Added testing commands to CONTRIBUTING.md
- Added `test`, `test:watch`, and `test --coverage` scripts
#### Fixes
- Made `userAgent` optional in `RobotsRule` interface
### 1.0.0 (2026-03-13)
#### Breaking changes
- Module format changed from CommonJS to ESM. If you were using CommonJS imports, update your imports to use ESM syntax.
- The sitemap URL in `robots.txt` now includes the sitemap filename (e.g., `Sitemap: https://domain.com/sitemap.xml` instead of `Sitemap: https://domain.com`).
#### Features
- Added `path` option to customize the sitemap filename (e.g., `subcategory.sitemap.xml`)
- Added full `robots.txt` generation support with custom rules including:
- `description` - Comment describing the rule
- `userAgent` - Which robot the rule applies to
- `allow` - URL paths allowed to be indexed
- `disallow` - URL paths disallowed from indexing
- Added TypeScript type exports (`ChangeFrequency`, `Priority`, `Url`, `Robots`, `RobotsRule`)
- Added `lint` script for TypeScript type checking
#### Fixes
- Fixed module export format to be ESM-compatible
#### Documentation
- Added comprehensive documentation for all new features
- Added TypeScript types documentation
- Updated contributing guidelines
#### License
- Changed from GPL-3.0 to MIT
### 0.1.0
- Initial release
- Basic sitemap generation with `location`, `lastModified`, `changeFrequency`, and `priority` options
- Basic `robots.txt` generation with sitemap URL