mirror of
https://github.com/rust-unofficial/awesome-rust.git
synced 2024-12-02 02:56:33 +02:00
Merge branch 'master' into patch-1
This commit is contained in:
commit
3a191b6e59
38
src/main.rs
38
src/main.rs
@ -1,5 +1,5 @@
|
||||
use pulldown_cmark::{Parser, Event, Tag};
|
||||
use std::fs;
|
||||
use std::{cmp::Ordering, fs};
|
||||
use futures::future::{select_all, BoxFuture, FutureExt};
|
||||
use std::collections::{BTreeSet, BTreeMap};
|
||||
use serde::{Serialize, Deserialize};
|
||||
@ -293,12 +293,14 @@ async fn main() -> Result<(), Error> {
|
||||
url_checks.push(check);
|
||||
};
|
||||
|
||||
let mut to_check: Vec<String> = vec![];
|
||||
|
||||
for (event, _range) in parser.into_offset_iter() {
|
||||
match event {
|
||||
Event::Start(tag) => {
|
||||
match tag {
|
||||
Tag::Link(_link_type, url, _title) | Tag::Image(_link_type, url, _title) => {
|
||||
do_check(url.to_string());
|
||||
to_check.push(url.to_string());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@ -310,6 +312,38 @@ async fn main() -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
to_check.sort_by(|a,b| {
|
||||
let get_time = |k| {
|
||||
let res = results.get(k);
|
||||
if let Some(link) = res {
|
||||
if let Some(last_working) = link.last_working {
|
||||
Some(last_working)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
let res_a = get_time(a);
|
||||
let res_b = get_time(b);
|
||||
if res_a.is_none() {
|
||||
if res_b.is_none() {
|
||||
return a.cmp(b);
|
||||
} else {
|
||||
Ordering::Less
|
||||
}
|
||||
} else if res_b.is_none() {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
res_a.unwrap().cmp(&res_b.unwrap())
|
||||
}
|
||||
});
|
||||
|
||||
for url in to_check {
|
||||
do_check(url)
|
||||
}
|
||||
|
||||
let results_keys = results.keys().cloned().collect::<BTreeSet<String>>();
|
||||
let old_links = results_keys.difference(&used);
|
||||
for link in old_links {
|
||||
|
Loading…
Reference in New Issue
Block a user