Also check out other xwde
projects here.
The implementation of the Sitemap (or URL inclusion) protocol in the Rust
programming language with the support of txt
& xml
formats, and video
,
image
, news
extensions (according to the Google's spec).
extension
to enable all XML sitemap extensions. Enabled by default.tokio
to enable asynchronous parsers & builders.AutoParser
.```rust
enum CustomError { // .. #[error("sitemap error: {0}")] Sitemap(#[from] sitemapo::Error), //.. }
fn main() -> Result<(), CustomError> {
type SyncReader = std::io::BufReader
let sitemaps = Vec::default(); // Sitemaps listed in the robots.txt file.
let mut parser = sitemapo::AutoParser::new_sync(&sitemaps, fetch);
while let Some(_record) = parser.read_sync()? {
// ..
}
Ok(())
} ```
TxtParser
& XmlParser
.```rust use sitemapo::{ parse::{Parser, TxtParser}, Error, };
fn main() -> Result<(), Error> { let buf = "https://example.com/file1.html".as_bytes();
let mut parser = TxtParser::new(buf)?;
let _rec = parser.read()?;
let _buf = parser.close()?;
Ok(())
} ```
TxtBuilder
& XmlBuilder
.```rust use sitemapo::{ build::{Builder, XmlBuilder}, record::EntryRecord, Error, };
fn main() -> Result<(), Error> { let buf = Vec::new(); let rec = EntryRecord::new("https://example.com/".try_into()?);
let mut builder = XmlBuilder::new(buf)?;
builder.write(&rec)?;
let _buf = builder.close()?;
Ok(())
} ```
AutoParser
does not yet support txt sitemaps.