https://github.com/bouzuya/sitemap-xml-writer
A Rust library for writing sitemap.xml
https://github.com/bouzuya/sitemap-xml-writer
rust sitemap xml
Last synced: 10 months ago
JSON representation
A Rust library for writing sitemap.xml
- Host: GitHub
- URL: https://github.com/bouzuya/sitemap-xml-writer
- Owner: bouzuya
- License: other
- Created: 2023-03-02T21:46:40.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-13T22:01:19.000Z (over 3 years ago)
- Last Synced: 2025-08-20T11:53:18.318Z (10 months ago)
- Topics: rust, sitemap, xml
- Language: Rust
- Homepage: https://crates.io/crates/sitemap-xml-writer
- Size: 35.2 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# sitemap-xml-writer
A Rust library for writing [`sitemap.xml`](https://www.sitemaps.org/).
[](https://github.com/bouzuya/sitemap-xml-writer/actions)
[](https://crates.io/crates/sitemap-xml-writer)
[](https://docs.rs/crate/sitemap-xml-writer)
[](#license)
## 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);
```
## License
Licensed under either of
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.