Basic cours support #44
1 changed files with 18 additions and 3 deletions
|
@ -45,6 +45,8 @@ fn get_filetree(dir_path: &str, exclusion_list: &[&str]) -> FileNode {
|
||||||
for entry in entries.filter_map(Result::ok) {
|
for entry in entries.filter_map(Result::ok) {
|
||||||
let entry_path = entry.path();
|
let entry_path = entry.path();
|
||||||
let entry_name = entry_path.file_name().and_then(|n| n.to_str()).unwrap();
|
let entry_name = entry_path.file_name().and_then(|n| n.to_str()).unwrap();
|
||||||
|
|
||||||
|
// We should support regex?
|
||||||
if !exclusion_list.contains(&entry_name) {
|
if !exclusion_list.contains(&entry_name) {
|
||||||
let filename = entry_name.to_string();
|
let filename = entry_name.to_string();
|
||||||
if entry_path.is_file() {
|
if entry_path.is_file() {
|
||||||
|
@ -71,12 +73,24 @@ fn get_filetree(dir_path: &str, exclusion_list: &[&str]) -> FileNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a page content
|
/// 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 {
|
let filename = match &path.q {
|
||||||
Some(q) => q,
|
Some(q) => q,
|
||||||
None => "index.md",
|
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)
|
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
|
// TODO: Uncomment before release
|
||||||
fn build_page(info: web::Query<PathRequest>, config: Config) -> String {
|
fn build_page(info: web::Query<PathRequest>, config: Config) -> String {
|
||||||
let cours_dir = "data/cours";
|
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(
|
config.tmpl.render(
|
||||||
"cours.html",
|
"cours.html",
|
||||||
|
@ -94,7 +109,7 @@ fn build_page(info: web::Query<PathRequest>, config: Config) -> String {
|
||||||
..NavBar::default()
|
..NavBar::default()
|
||||||
},
|
},
|
||||||
filetree: serde_json::to_string(&filetree).unwrap(),
|
filetree: serde_json::to_string(&filetree).unwrap(),
|
||||||
content: get_content(cours_dir, &info),
|
content: get_content(cours_dir, &info, &exclusion_list),
|
||||||
},
|
},
|
||||||
Infos {
|
Infos {
|
||||||
page_title: Some("Cours".into()),
|
page_title: Some("Cours".into()),
|
||||||
|
|
Loading…
Reference in a new issue