2020-11-22 14:43:41 +00:00
|
|
|
# Sitewriter
|
2021-02-01 09:48:24 +00:00
|
|
|
[![Rust](https://github.com/edg-l/sitewriter/workflows/Rust/badge.svg)](https://github.com/edg-l/sitewriter/actions)
|
2020-11-22 15:42:16 +00:00
|
|
|
[![crates.io](http://meritbadge.herokuapp.com/sitewriter)](https://crates.io/crates/sitewriter)
|
2021-02-01 09:48:24 +00:00
|
|
|
[![License](https://img.shields.io/github/license/edg-l/sitewriter)](https://github.com/edg-l/sitewriter/blob/master/LICENSE)
|
2020-11-27 13:32:25 +00:00
|
|
|
[![codecov](https://codecov.io/gh/edg-l/sitewriter/branch/master/graph/badge.svg?token=JKOQCRSCZU)](https://codecov.io/gh/edg-l/sitewriter)
|
2020-11-22 15:42:16 +00:00
|
|
|
|
2020-11-22 14:43:41 +00:00
|
|
|
A rust library to generate sitemaps.
|
|
|
|
|
|
|
|
It uses the [quick-xml](https://github.com/tafia/quick-xml) so it should be fast.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
2020-11-22 14:47:10 +00:00
|
|
|
To run the examples use `cargo run --example gen_sitemap`
|
|
|
|
|
2020-11-22 14:43:41 +00:00
|
|
|
```rust
|
2021-04-20 14:47:43 +00:00
|
|
|
use chrono::prelude::*;
|
|
|
|
use sitewriter::*;
|
2020-11-22 14:43:41 +00:00
|
|
|
|
2021-04-20 14:47:43 +00:00
|
|
|
let urls = vec![
|
|
|
|
UrlEntryBuilder::default()
|
|
|
|
.loc("https://edgarluque.com/projects".parse().unwrap())
|
|
|
|
.build()
|
|
|
|
.unwrap(),
|
|
|
|
UrlEntry {
|
|
|
|
loc: "https://edgarluque.com/".parse().unwrap(),
|
2020-11-22 14:43:41 +00:00
|
|
|
changefreq: Some(ChangeFreq::Daily),
|
|
|
|
priority: Some(1.0),
|
|
|
|
lastmod: Some(Utc::now()),
|
2021-04-20 14:47:43 +00:00
|
|
|
},
|
|
|
|
UrlEntry {
|
|
|
|
loc: "https://edgarluque.com/blog".parse().unwrap(),
|
2020-11-22 14:43:41 +00:00
|
|
|
changefreq: Some(ChangeFreq::Weekly),
|
|
|
|
priority: Some(0.8),
|
|
|
|
lastmod: Some(Utc::now()),
|
2021-04-20 14:47:43 +00:00
|
|
|
},
|
|
|
|
UrlEntry {
|
|
|
|
loc: "https://edgarluque.com/blog/sitewriter".parse().unwrap(),
|
2020-11-22 14:43:41 +00:00
|
|
|
changefreq: Some(ChangeFreq::Never),
|
|
|
|
priority: Some(0.5),
|
|
|
|
lastmod: Some(Utc.ymd(2020, 11, 22).and_hms(15, 10, 15)),
|
2021-04-20 14:47:43 +00:00
|
|
|
},
|
|
|
|
UrlEntry {
|
|
|
|
loc: "https://edgarluque.com/blog/some-future-post"
|
|
|
|
.parse()
|
|
|
|
.unwrap(),
|
2020-11-22 14:43:41 +00:00
|
|
|
changefreq: Some(ChangeFreq::Never),
|
|
|
|
priority: Some(0.5),
|
2021-04-20 14:47:43 +00:00
|
|
|
lastmod: Some(
|
|
|
|
Utc.from_utc_datetime(&Local.ymd(2020, 12, 5).and_hms(12, 30, 0).naive_utc()),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
// Entity escaping
|
|
|
|
UrlEntry {
|
|
|
|
loc: "https://edgarluque.com/blog/test&id='<test>'"
|
|
|
|
.parse()
|
|
|
|
.unwrap(),
|
|
|
|
changefreq: Some(ChangeFreq::Never),
|
|
|
|
priority: Some(0.5),
|
|
|
|
lastmod: Some(
|
|
|
|
Utc.from_utc_datetime(&Local.ymd(2020, 12, 5).and_hms(12, 30, 0).naive_utc()),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
];
|
2020-11-22 14:43:41 +00:00
|
|
|
|
2021-04-20 14:47:43 +00:00
|
|
|
let result = Sitemap::into_str(&urls).unwrap();
|
|
|
|
println!("{}", result);
|
2020-11-22 14:43:41 +00:00
|
|
|
```
|
2020-11-22 14:47:10 +00:00
|
|
|
|