sitewriter/examples/gen_sitemap.rs

50 lines
1.7 KiB
Rust
Raw Normal View History

2020-11-22 14:43:41 +00:00
use chrono::prelude::*;
use sitewriter::{ChangeFreq, UrlEntry, UrlEntryBuilder};
2020-11-22 14:43:41 +00:00
fn main() {
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(),
changefreq: Some(ChangeFreq::Daily),
priority: Some(1.0),
lastmod: Some(Utc::now()),
},
UrlEntry {
loc: "https://edgarluque.com/blog".parse().unwrap(),
changefreq: Some(ChangeFreq::Weekly),
priority: Some(0.8),
lastmod: Some(Utc::now()),
},
UrlEntry {
loc: "https://edgarluque.com/blog/sitewriter".parse().unwrap(),
changefreq: Some(ChangeFreq::Never),
priority: Some(0.5),
2023-01-11 13:23:59 +00:00
lastmod: Some(Utc.with_ymd_and_hms(2020, 12, 5, 15, 30, 0).unwrap()),
2021-04-20 14:47:43 +00:00
},
UrlEntry {
loc: "https://edgarluque.com/blog/some-future-post"
.parse()
.unwrap(),
changefreq: Some(ChangeFreq::Never),
priority: Some(0.5),
2023-01-11 13:23:59 +00:00
lastmod: Some(Utc.with_ymd_and_hms(2020, 12, 5, 12, 30, 0).unwrap()),
2021-04-20 14:47:43 +00:00
},
// Entity escaping
UrlEntry {
loc: "https://edgarluque.com/blog/test&id='<test>'"
.parse()
.unwrap(),
changefreq: Some(ChangeFreq::Never),
priority: Some(0.5),
2023-01-11 13:23:59 +00:00
lastmod: Some(Utc.with_ymd_and_hms(2020, 12, 5, 12, 30, 0).unwrap()),
2021-04-20 14:47:43 +00:00
},
];
2020-11-22 14:43:41 +00:00
let result = sitewriter::generate_str(&urls);
2020-11-22 14:43:41 +00:00
println!("{}", result);
}