exlusion function
This commit is contained in:
parent
77970da8b3
commit
754e717a58
2 changed files with 17 additions and 15 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue