From 2a44f1240f363977b136223c34869d4666e89602 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 1 Nov 2023 17:03:03 +0100 Subject: [PATCH] WIP: Exclusion support --- src/routes/cours.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/routes/cours.rs b/src/routes/cours.rs index 0019edc..f843bd5 100644 --- a/src/routes/cours.rs +++ b/src/routes/cours.rs @@ -45,6 +45,8 @@ fn get_filetree(dir_path: &str, exclusion_list: &[&str]) -> FileNode { for entry in entries.filter_map(Result::ok) { let entry_path = entry.path(); let entry_name = entry_path.file_name().and_then(|n| n.to_str()).unwrap(); + + // We should support regex? if !exclusion_list.contains(&entry_name) { let filename = entry_name.to_string(); if entry_path.is_file() { @@ -71,12 +73,24 @@ fn get_filetree(dir_path: &str, exclusion_list: &[&str]) -> FileNode { } /// Get a page content -fn get_content(cours_dir: &str, path: &web::Query) -> Option { +fn get_content( + cours_dir: &str, + path: &web::Query, + exclusion_list: &[&str], +) -> Option { let filename = match &path.q { Some(q) => q, None => "index.md", }; + // We should support regex? + if exclusion_list + .iter() + .any(|&excluded_term| filename.contains(excluded_term)) + { + return None; + } + read_file(&format!("{cours_dir}/{filename}"), TypeFileMetadata::Cours) } @@ -84,7 +98,8 @@ fn get_content(cours_dir: &str, path: &web::Query) -> Option // TODO: Uncomment before release fn build_page(info: web::Query, config: Config) -> String { let cours_dir = "data/cours"; - let filetree = get_filetree(cours_dir, &[]); + let exclusion_list = []; + let filetree = get_filetree(cours_dir, &exclusion_list); config.tmpl.render( "cours.html", @@ -94,7 +109,7 @@ fn build_page(info: web::Query, config: Config) -> String { ..NavBar::default() }, filetree: serde_json::to_string(&filetree).unwrap(), - content: get_content(cours_dir, &info), + content: get_content(cours_dir, &info, &exclusion_list), }, Infos { page_title: Some("Cours".into()),