(feat): use new util functions
This commit is contained in:
parent
5330d5fab0
commit
d668eb2d9d
@ -1,7 +1,10 @@
|
||||
use axum::{routing::get, Router};
|
||||
use std::{env, fs};
|
||||
|
||||
use crate::routes;
|
||||
use crate::{routes, utils};
|
||||
|
||||
const FILE_NAME_DELIMETER: &str = "_";
|
||||
const FILE_NAME_DELIMETER_REPLACEMENT: &str = " ";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {}
|
||||
@ -11,12 +14,22 @@ pub fn init_notes_routes() -> Router {
|
||||
Router::new().route("/", get(routes::notes))
|
||||
}
|
||||
|
||||
pub fn update_route(router: Router, file_name_str: String, file_path_str: String) -> Router {
|
||||
pub fn update_tuts_route(router: Router, file_name_str: String, file_path_str: String) -> Router {
|
||||
let route = format!("/{}", file_name_str);
|
||||
println!("{}", route);
|
||||
let tut_title = utils::rm_path_ext(utils::rm_delimeter(
|
||||
file_name_str,
|
||||
FILE_NAME_DELIMETER.to_string(),
|
||||
FILE_NAME_DELIMETER_REPLACEMENT.to_string(),
|
||||
));
|
||||
|
||||
router.route(
|
||||
route.clone().as_str(),
|
||||
get(move || routes::tuts_builder(file_path_str)),
|
||||
get(move || {
|
||||
routes::tuts_builder(
|
||||
file_path_str,
|
||||
utils::upper_all_words_first_letters(tut_title).unwrap(),
|
||||
)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@ -34,8 +47,9 @@ pub fn init_tuts_routes() -> Router {
|
||||
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 = update_tuts_route(router, file_name_str, file_path);
|
||||
}
|
||||
|
||||
router = router.route("/", get(move || routes::tuts(file_dir_vec)));
|
||||
|
||||
router
|
||||
|
@ -22,12 +22,12 @@ 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> {
|
||||
pub async fn tuts_builder(path: String, tut_title: String) -> Result<impl IntoResponse, ApiError> {
|
||||
let file_contents = std::fs::read_to_string(path).unwrap();
|
||||
let file_contents_to_html =
|
||||
markdown_to_html(file_contents.as_str(), &comrak::Options::default());
|
||||
let file_template = Tut {
|
||||
title: "Note",
|
||||
title: &tut_title,
|
||||
content: file_contents_to_html.as_str(),
|
||||
};
|
||||
let response = Response::builder()
|
||||
|
Loading…
Reference in New Issue
Block a user