# sitemaps
The sitemap-xml-writer crate provides writers for [`sitemap.xml`](https://www.sitemaps.org/).
[![crates.io](https://img.shields.io/crates/v/sitemap-xml-writer)](https://docs.rs/crate/sitemap-xml-writer)
[![docs.rs](https://img.shields.io/docsrs/sitemap-xml-writer)](https://docs.rs/crate/sitemap-xml-writer)
## Feature flags
- `"chrono"` ... `chrono::NaiveDate` and `chrono::DateTime` support
- `"time"` ... `time::Date` and `time::OffsetDateTime` support
- `"url"` ... `url::Url` support
## Usage
### Writing sitemap file
```rust
use sitemap_xml_writer::{SitemapWriter, Url};
use std::io::Cursor;
let mut writer = SitemapWriter::start(Cursor::new(Vec::new()))?;
writer.write(
Url::loc("http://www.example.com/")?
.lastmod("2005-01-01")?
.changefreq("monthly")?
.priority("0.8")?,
)?;
writer.end()?;
let actual = String::from_utf8(writer.into_inner().into_inner())?;
let expected = concat!(
r#""#,
r#""#,
r#""#,
r#"http://www.example.com/"#,
r#"2005-01-01"#,
r#"monthly"#,
r#"0.8"#,
r#""#,
r#""#
);
assert_eq!(actual, expected);
```
### Writing sitemap index file
```rust
use sitemap_xml_writer::{SitemapIndexWriter};
use std::io::Cursor;
let mut writer = SitemapIndexWriter::start(Cursor::new(Vec::new()))?;
writer.write(
Sitemap::loc("http://www.example.com/sitemap1.xml.gz")?
.lastmod("2004-10-01T18:23:17+00:00")?,
)?;
writer.end()?;
let actual = String::from_utf8(writer.into_inner().into_inner())?;
let expected = concat!(
r#""#,
r#""#,
r#""#,
r#"http://www.example.com/sitemap1.xml.gz"#,
r#"2004-10-01T18:23:17+00:00"#,
r#""#,
r#""#
);
assert_eq!(actual, expected);
```