make tuts list page render properly
This commit is contained in:
parent
c2732fe85c
commit
cd75b598bb
@ -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::<String>::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
|
||||
}
|
||||
|
@ -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<String>) -> impl IntoResponse {
|
||||
templates::Tuts { tuts_list: paths }
|
||||
}
|
||||
|
||||
pub async fn tuts_builder(path: String) -> Result<impl IntoResponse, ApiError> {
|
||||
|
@ -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<String>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
|
@ -8,5 +8,9 @@ content %}
|
||||
|
||||
<h1>Notes</h1>
|
||||
<p>Here all my Micro Tuts</p>
|
||||
{{tuts_list}}
|
||||
<ul>
|
||||
{% for tut in tuts_list %}
|
||||
<li><a href="tuts/{{tut}}">{{tut}}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock content%}
|
||||
|
Loading…
Reference in New Issue
Block a user