WIP: Exclusion support
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-11-01 17:03:03 +01:00
parent a738d492d2
commit 2a44f1240f
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -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<PathRequest>) -> Option<File> {
fn get_content(
cours_dir: &str,
path: &web::Query<PathRequest>,
exclusion_list: &[&str],
) -> Option<File> {
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<PathRequest>) -> Option<File>
// TODO: Uncomment before release
fn build_page(info: web::Query<PathRequest>, 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<PathRequest>, 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()),