From f50141ef233116b2e458e714af72b527f619227e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arma=C3=ABl=20Gu=C3=A9neau?= Date: Wed, 27 Nov 2024 19:36:47 +0100 Subject: [PATCH] filter out users with an empty profile --- src/main.rs | 36 ++++++++++++++++++++++++++++++------ templates/macros.html | 4 +++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 72a3d5b..76c7a5b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,6 +57,15 @@ struct Db { } impl UserData { + fn is_empty(&self) -> bool { + self.full_name.is_none() + && self.location.is_none() + && self.website.is_none() + && self.description.is_none() + && self.repos.is_empty() + && self.issues.is_empty() + } + fn to_tokens(&self) -> Vec { let mut text = String::new(); let mut add = |s: &str| { @@ -226,6 +235,14 @@ async fn scrape_users(forge: &Forgejo) -> anyhow::Result anyhow::Result> { let mut data = HashMap::new(); + let discard_empty = |o: Option| { + match o { + None => None, + Some(s) if s.is_empty() => None, + Some(s) => Some(s), + } + }; + eprintln!("Fetching users..."); for user in scrape_users(&forge).await? { let Some(id) = user.id else { @@ -248,10 +265,10 @@ async fn get_users_data(forge: &Forgejo) -> anyhow::Result anyhow::Result anyhow::Result, q: web::Query) -> impl Re let db = &data.db.lock().unwrap(); eprintln!("scoring users..."); - let mut users: Vec<_> = db.unclassified_users() + let mut users: Vec<_> = db + .unclassified_users() .into_iter() .map(|(id, u)| (id, u, *db.score.get(id).unwrap())) .collect(); diff --git a/templates/macros.html b/templates/macros.html index 72ffde2..5e7843d 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -1,5 +1,7 @@ {% macro compact(name, desc) %} - {% if desc | length <= 150 %} + {% if not desc %} + {{ name }} + {% elif desc | length <= 150 %} {{ name }} | {{ desc }} {% else %}