| Crates.io | sitemap-writer |
| lib.rs | sitemap-writer |
| version | 1.0.1 |
| created_at | 2022-06-09 13:22:22.824243+00 |
| updated_at | 2026-01-06 15:25:48.245665+00 |
| description | A simple and lightweight Rust library for generating XML sitemaps |
| homepage | https://github.com/uiuifree/rust-sitemap-writer |
| repository | https://github.com/uiuifree/rust-sitemap-writer |
| max_upload_size | |
| id | 602607 |
| size | 29,594 |
A simple and lightweight Rust library for generating XML sitemaps.
loc, lastmod, changefreq, priority)Add this to your Cargo.toml:
[dependencies]
sitemap-writer = "1.0"
use sitemap_writer::{SitemapWriter, SitemapUrl, SitemapChangeFreq};
fn main() {
let result = SitemapWriter::make("sitemap.xml", vec![
SitemapUrl {
loc: "https://example.com/".to_string(),
lastmod: Some("2024-01-01".to_string()),
changefreq: Some(SitemapChangeFreq::DAILY),
priority: Some(1.0),
},
SitemapUrl::new("https://example.com/about/"),
]);
assert!(result.is_ok());
}
SitemapWriter::make(path, urls) - Write to Fileuse sitemap_writer::{SitemapWriter, SitemapUrl, SitemapChangeFreq};
let result = SitemapWriter::make("sitemap.xml", vec![
SitemapUrl {
loc: "https://example.com/".to_string(),
lastmod: Some("2024-01-01".to_string()),
changefreq: Some(SitemapChangeFreq::DAILY),
priority: Some(1.0),
},
SitemapUrl::new("https://example.com/contact/"),
]);
SitemapWriter::build(urls) - Build as Stringuse sitemap_writer::{SitemapWriter, SitemapUrl};
let xml = SitemapWriter::build(vec![
SitemapUrl::new("https://example.com/"),
SitemapUrl::new("https://example.com/about/"),
]);
| Field | Type | Description |
|---|---|---|
loc |
String |
Required. The URL of the page. |
lastmod |
Option<String> |
The date of last modification (YYYY-MM-DD). |
changefreq |
Option<SitemapChangeFreq> |
How frequently the page changes. |
priority |
Option<f32> |
Priority relative to other URLs (0.0 to 1.0). |
| Value | Description |
|---|---|
ALWAYS |
Changes every access |
HOURLY |
Changes hourly |
DAILY |
Changes daily |
WEEKLY |
Changes weekly |
MONTHLY |
Changes monthly |
YEARLY |
Changes yearly |
NEVER |
Archived content |
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/</loc>
<lastmod>2024-01-01</lastmod>
<changefreq>daily</changefreq>
<priority>1</priority>
</url>
<url>
<loc>https://example.com/about/</loc>
</url>
</urlset>
For large sites with more than 50,000 URLs, use Sitemap Index:
SitemapIndexWriter::make(path, sitemaps) - Write to Fileuse sitemap_writer::{SitemapIndexWriter, SitemapIndex};
let result = SitemapIndexWriter::make("sitemap_index.xml", vec![
SitemapIndex {
loc: "https://example.com/sitemap1.xml".to_string(),
lastmod: Some("2024-01-01".to_string()),
},
SitemapIndex::new("https://example.com/sitemap2.xml"),
]);
SitemapIndexWriter::build(sitemaps) - Build as Stringuse sitemap_writer::{SitemapIndexWriter, SitemapIndex};
let xml = SitemapIndexWriter::build(vec![
SitemapIndex::new("https://example.com/sitemap1.xml"),
SitemapIndex::new("https://example.com/sitemap2.xml"),
]);
| Field | Type | Description |
|---|---|---|
loc |
String |
Required. The URL of the sitemap file. |
lastmod |
Option<String> |
The date of last modification (YYYY-MM-DD). |
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://example.com/sitemap1.xml</loc>
<lastmod>2024-01-01</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/sitemap2.xml</loc>
</sitemap>
</sitemapindex>
MIT License