Generate sitemap.xml from directory structure
npm install simapA simple, fast CLI tool to generate sitemap.xml files from your directory structure.
``bash`
npm install -g simap
`bash`
simap
- dirpath - Path to the directory containing your website filesdomain
- - Your website's base URL (must include http:// or https://)
- --ignore, -i - Ignore routes starting with the specified path (can be used multiple times)--help, -h
- - Show help message
`bashGenerate sitemap for a local public directory
simap ./public https://example.com
Features
- 🚀 Fast and lightweight
- 📁 Recursively scans directories
- 🔍 Supports HTML files by default
- 📅 Includes last modification dates
- 🎯 SEO-friendly XML format
- ⚙️ Configurable via programmatic API
- 🚫 Automatically excludes common build/config folders
- 🎭 Ignore specific routes with
--ignore flagDefault Behavior
- File extensions:
.html, .htm
- Excluded folders: node_modules, .git, dist, .next, .nuxt
- Change frequency: weekly
- Priority: 0.5Output
The tool generates a
sitemap.xml file in the specified directory with properly formatted URLs, including:
- URL location
- Last modification date
- Change frequency
- Priority$3
`xml
https://example.com/
2024-01-20T10:30:00.000Z
weekly
0.5
https://example.com/about
2024-01-19T15:45:00.000Z
weekly
0.5
`Programmatic Usage
You can also use simap as a module in your Node.js projects:
`typescript
import { generateSitemap } from 'simap';await generateSitemap('./public', 'https://example.com', {
extensions: ['.html', '.htm', '.php'],
exclude: ['node_modules', 'temp'],
priority: 0.8,
changefreq: 'daily',
ignoreRoutes: ['/admin', '/private', '/test']
});
`$3
`typescript
interface SitemapOptions {
extensions?: string[]; // File extensions to include
exclude?: string[]; // Folders to exclude
priority?: number; // URL priority (0.0 to 1.0)
changefreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
ignoreRoutes?: string[]; // Routes to ignore (prefix matching)
}
``- Node.js >= 16.0.0
MIT
Issues and pull requests are welcome!