mirror of
https://github.com/Hopiu/lychee.git
synced 2026-05-02 10:54:46 +00:00
Add support for website input
This commit is contained in:
parent
bbfe6a8531
commit
8356ef1d03
1 changed files with 9 additions and 3 deletions
12
src/main.rs
12
src/main.rs
|
|
@ -89,11 +89,17 @@ fn print_summary(found: &HashSet<Url>, results: &Vec<CheckStatus>) {
|
|||
println!("🚫Errors: {}", errors);
|
||||
}
|
||||
|
||||
fn collect_links(inputs: Vec<String>) -> Result<HashSet<Url>> {
|
||||
async fn collect_links(inputs: Vec<String>) -> Result<HashSet<Url>> {
|
||||
let mut links = HashSet::new();
|
||||
|
||||
for input in inputs {
|
||||
let content = fs::read_to_string(input)?;
|
||||
let content = match Url::parse(&input) {
|
||||
Ok(url) => {
|
||||
let res = reqwest::get(url).await?;
|
||||
res.text().await?
|
||||
}
|
||||
Err(_) => fs::read_to_string(input)?,
|
||||
};
|
||||
links.extend(extract_links(&content));
|
||||
}
|
||||
Ok(links)
|
||||
|
|
@ -111,7 +117,7 @@ async fn run(opts: LycheeOptions) -> Result<()> {
|
|||
opts.verbose,
|
||||
)?;
|
||||
|
||||
let links = collect_links(opts.inputs)?;
|
||||
let links = collect_links(opts.inputs).await?;
|
||||
let futures: Vec<_> = links.iter().map(|l| checker.check(&l)).collect();
|
||||
let results = join_all(futures).await;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue