From 754e717a5896d4bb9170418a04b78b18b57c721e Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 9 Nov 2024 17:29:59 +0100 Subject: [PATCH] exlusion function --- src/routes/cours.rs | 10 ++-------- src/utils/routes/cours.rs | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/routes/cours.rs b/src/routes/cours.rs index 39c861b..1504703 100644 --- a/src/routes/cours.rs +++ b/src/routes/cours.rs @@ -9,8 +9,8 @@ use crate::{ template::{InfosPage, NavBar}, utils::{ markdown::{File, TypeFileMetadata}, - routes::cours::get_filetree, misc::{make_kw, read_file, Html}, + routes::cours::{excluded, get_filetree}, }, }; @@ -49,13 +49,7 @@ fn get_content( let filename = path.q.as_ref().map_or("index.md", |q| q); // Exclusion checks - if exclusion_list - .iter() - .any(|excluded_term| filename.contains(excluded_term.as_str())) - { - return None; - } - if exclusion_patterns.iter().any(|re| re.is_match(filename)) { + if excluded(filename, exclusion_list, exclusion_patterns) { return None; } diff --git a/src/utils/routes/cours.rs b/src/utils/routes/cours.rs index 52cab65..7318e86 100644 --- a/src/utils/routes/cours.rs +++ b/src/utils/routes/cours.rs @@ -23,13 +23,7 @@ pub fn get_filetree( let entry_name = entry_path.file_name()?.to_string_lossy().to_string(); // Exclusion checks - if exclusion_list - .iter() - .any(|excluded_term| entry_name.contains(excluded_term.as_str())) - { - return None; - } - if exclusion_patterns.iter().any(|re| re.is_match(&entry_name)) { + if excluded(&entry_name, exclusion_list, exclusion_patterns) { return None; } @@ -65,3 +59,17 @@ pub fn get_filetree( children, } } + +pub fn excluded(element: &str, exclusion_list: &[String], exclusion_patterns: &[Regex]) -> bool { + if exclusion_list + .iter() + .any(|excluded_term| element.contains(excluded_term)) + { + return true; + } + if exclusion_patterns.iter().any(|re| re.is_match(element)) { + return true; + } + + false +}