Repository navigation
Library quick start
The sitevet crate is the same engine the CLI runs. The CLI is a thin wrapper over it, so anything the CLI does, your code can do.
[dependencies]
sitevet = "0.6"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }Add features = ["browser"] to sitevet for the rendered checks, history for the run store. See Installation.
#[tokio::main]
async fn main() -> sitevet::Result<()> {
let report = sitevet::audit("https://example.com", sitevet::Options::default()).await?;
println!("{} pages, score {}", report.pages.len(), report.score);
for c in &report.categories {
println!("{:<22} {:>3} {} fail, {} warn", c.category, c.score, c.fail, c.warn);
}
Ok(())
}audit needs a tokio context. Dropping the future stops all network work. On another executor, use spawn (see Library events and spawn).
Options holds every setting the CLI has a flag for. It is #[non_exhaustive], so start from the default and set fields:
let mut options = sitevet::Options::default();
options.max_pages = 20;
options.only = vec!["security".into(), "links".into()];
options.delay_ms = 250;
options.validate()?; // optional: audit() validates tooThe fields and defaults are listed in CLI configuration; the TOML keys are the field names. To read a sitevet.toml:
let options = sitevet::Options::from_toml_str(&std::fs::read_to_string("sitevet.toml")?)?;A [cli] table in the file is ignored here, and unknown keys are errors.
let html: String = sitevet::audit_to_html(url, options.clone()).await?; // the self-contained report
let md: String = sitevet::audit_to_markdown(url, options.clone()).await?;
let score: u8 = sitevet::audit_score(url, options).await?;Or render a report you already have:
let json = sitevet::render(&report, sitevet::Format::Json);
let html = sitevet::render(&report, sitevet::Format::Html);
let md = sitevet::render(&report, sitevet::Format::Markdown);audit returns sitevet::Error only when the whole audit cannot run:
| Variant | When |
|---|---|
InvalidUrl |
The start URL does not parse, or is not http or https |
InvalidOptions |
An option is out of range or needs a feature that is off |
StartPageUnreachable |
The start page did not answer |
NotHtml |
The start page is not HTML |
BrowserNotFound, BrowserFailed
|
browser = true and Chrome is missing or crashed |
History |
The run store failed (with the history feature) |
Cancelled |
You cancelled the audit |
A single page that fails to load does not stop the audit. It shows up in the report with its status and error set.
sitevet is MIT licensed. Source, issues and releases: github.com/Abdulkader-Safi/sitevet.
Getting started
CLI
Library
Reference