initial commit
This commit is contained in:
@@ -1,2 +1,67 @@
|
||||
# vite-sitemap-plugin
|
||||
# @unom/vite-sitemap-plugin
|
||||
|
||||
Vite plugin that writes `sitemap.xml` and `robots.txt` into your output directory at build start. Supports optional i18n routing with `hreflang` alternates.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
bun add -D @unom/vite-sitemap-plugin
|
||||
# or: npm i -D @unom/vite-sitemap-plugin
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
// vite.config.ts
|
||||
import { defineConfig } from "vite";
|
||||
import { sitemapPlugin } from "@unom/vite-sitemap-plugin";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
sitemapPlugin({
|
||||
siteUrl: "https://example.com",
|
||||
routes: ["", "/about", { path: "/blog", changefreq: "weekly", priority: 0.8 }],
|
||||
robots: {
|
||||
disallow: ["/admin/"],
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
### With locales (hreflang)
|
||||
|
||||
```ts
|
||||
sitemapPlugin({
|
||||
siteUrl: "https://example.com",
|
||||
locales: ["en", "de", "es"],
|
||||
defaultLocale: "en",
|
||||
routes: ["", "/legal/imprint", "/legal/privacy"],
|
||||
});
|
||||
```
|
||||
|
||||
This emits one `<url>` per `(locale, path)` pair with `<xhtml:link rel="alternate" hreflang="…">` entries and an `x-default` pointing to `defaultLocale`.
|
||||
|
||||
## Options
|
||||
|
||||
| Option | Type | Default |
|
||||
| --- | --- | --- |
|
||||
| `siteUrl` | `string` (required) | — |
|
||||
| `routes` | `Array<string \| SitemapEntry>` (required) | — |
|
||||
| `locales` | `string[]` | unset |
|
||||
| `defaultLocale` | `string` | first locale |
|
||||
| `formatUrl` | `(locale, path) => string` | `${siteUrl}/${locale}${path}` |
|
||||
| `lastmod` | `string \| Date` | build time |
|
||||
| `outDir` | `string` | `"public"` |
|
||||
| `sitemapFilename` | `string` | `"sitemap.xml"` |
|
||||
| `robotsFilename` | `string` | `"robots.txt"` |
|
||||
| `robots` | `RobotsOptions \| false` | `{}` |
|
||||
| `name` | `string` | `"vite-sitemap-plugin"` |
|
||||
|
||||
`SitemapEntry` accepts `path`, `lastmod`, `changefreq`, `priority`.
|
||||
|
||||
`RobotsOptions` accepts `disallow`, `allow`, `extraLines`, `userAgent`.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
Reference in New Issue
Block a user