(feat): add new struct for the file display logic

This commit is contained in:
Triston Armstrong 2024-03-31 16:54:11 -05:00
parent d463da8489
commit 785ca3b0d1
5 changed files with 45 additions and 4 deletions

View File

@ -1,2 +1,2 @@
// use serde::{Deserialize, Serialize};
// put models here
// put DB models here

View File

@ -1,7 +1,11 @@
use shuttle_axum::AxumService;
use shuttle_runtime;
mod db_models;
mod errors;
mod models;
mod router;
mod routes;
mod structs;
mod templates;
mod utils;

View File

@ -7,7 +7,9 @@ use comrak::markdown_to_html;
use crate::{
errors::ApiError,
structs::FileDisplay,
templates::{self, Tut},
utils,
};
pub async fn portfolio() -> impl IntoResponse {
@ -19,7 +21,24 @@ pub async fn notes() -> impl IntoResponse {
}
pub async fn tuts(paths: Vec<String>) -> impl IntoResponse {
templates::Tuts { tuts_list: paths }
let mut new_paths: Vec<FileDisplay> = vec![];
for path in paths {
let new_struct = FileDisplay {
file_path: path.clone().to_string(),
title: utils::upper_all_words_first_letters(utils::rm_delimeter(
utils::rm_path_ext(path),
"_".to_string(),
" ".to_string(),
))
.unwrap(),
};
new_paths.push(new_struct);
}
templates::Tuts {
tuts_list: new_paths,
}
}
pub async fn tuts_builder(path: String, tut_title: String) -> Result<impl IntoResponse, ApiError> {

16
src/structs.rs Normal file
View File

@ -0,0 +1,16 @@
use std::fmt::Display;
impl Display for FileDisplay {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{{file_path: {}, title: {}}}",
self.file_path, self.title
)
}
}
pub struct FileDisplay {
pub file_path: String,
pub title: String,
}

View File

@ -1,5 +1,7 @@
use askama::Template;
use crate::structs::FileDisplay;
#[derive(Template)]
#[template(path = "portfolio.html")]
pub struct Portfolio;
@ -11,7 +13,7 @@ pub struct Notes;
#[derive(Template)]
#[template(path = "tuts.html")]
pub struct Tuts {
pub tuts_list: Vec<String>,
pub tuts_list: Vec<FileDisplay>,
}
#[derive(Template)]