diff --git a/src/router.rs b/src/router.rs index fa5c03c..11fe26f 100644 --- a/src/router.rs +++ b/src/router.rs @@ -13,24 +13,30 @@ pub fn init_notes_routes() -> Router { pub fn update_route(router: Router, file_name_str: String, file_path_str: String) -> Router { let route = format!("/{}", file_name_str); + println!("{}", route); router.route( route.clone().as_str(), get(move || routes::tuts_builder(file_path_str)), ) } + // put all tutorial routes here pub fn init_tuts_routes() -> Router { - let mut router = Router::new().route("/", get(routes::tuts)); - let path = env::current_dir().unwrap(); - let mut path_string = path.clone().into_os_string(); - path_string.push("/tuts"); - for entry in fs::read_dir(path_string).unwrap() { - let entry = entry.unwrap(); + let mut current_dir = env::current_dir().unwrap().into_os_string(); + current_dir.push("/tuts"); + let directory = fs::read_dir(current_dir).unwrap(); + let mut file_dir_vec = Vec::::new(); + + let mut router = Router::new(); + for file in directory { + let entry = file.unwrap(); let file_path = entry.path().to_str().unwrap().to_string(); let file_name = entry.file_name(); let file_name_str = file_name.to_str().unwrap().to_string(); + file_dir_vec.push(file_name_str.clone()); router = update_route(router, file_name_str, file_path); } + router = router.route("/", get(move || routes::tuts(file_dir_vec))); router } diff --git a/src/routes.rs b/src/routes.rs index dcf85b6..3ea6fbf 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,5 +1,3 @@ -use std::{fs::File, io::Read}; - use askama::Template; use axum::{ http::StatusCode, @@ -20,12 +18,8 @@ pub async fn notes() -> impl IntoResponse { templates::Notes } -pub async fn tuts() -> impl IntoResponse { - let tuts_list = Vec::new(); - - templates::Tuts { - tuts_list: tuts_list, - } +pub async fn tuts(paths: Vec) -> impl IntoResponse { + templates::Tuts { tuts_list: paths } } pub async fn tuts_builder(path: String) -> Result { diff --git a/src/templates.rs b/src/templates.rs index 3c442bd..24e297b 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -10,8 +10,8 @@ pub struct Notes; #[derive(Template)] #[template(path = "tuts.html")] -pub struct Tuts<'a> { - pub tuts_list: Vec<&'a str>, +pub struct Tuts { + pub tuts_list: Vec, } #[derive(Template)] diff --git a/templates/tuts.html b/templates/tuts.html index 7013191..cbb19c6 100644 --- a/templates/tuts.html +++ b/templates/tuts.html @@ -8,5 +8,9 @@ content %}

Notes

Here all my Micro Tuts

-{{tuts_list}} +
    + {% for tut in tuts_list %} +
  • {{tut}}
  • + {% endfor %} +
{% endblock content%}