diff --git a/Documentation.md b/Documentation.md index 59e38d3..4c8b154 100644 --- a/Documentation.md +++ b/Documentation.md @@ -13,6 +13,7 @@ - [Blog](#blog) - [Projects](#projects) - [Contacts](#contacts) + - [Courses](#courses) # Installation @@ -204,3 +205,7 @@ Custom project description - `user` is the username used in the platform - `description` will be rendered as HTML "title" (text will appear when cursor is hover the link) + +## Courses + +Markdown files are stored in `/app/data/cours/` diff --git a/src/misc/markdown.rs b/src/misc/markdown.rs index 9a08fab..9ba2aaf 100644 --- a/src/misc/markdown.rs +++ b/src/misc/markdown.rs @@ -34,10 +34,14 @@ pub struct FileMetadataPortfolio { pub language: Option, } +#[derive(Default, Deserialize, Content, Debug)] +pub struct FileMetadataCours {} + pub enum TypeFileMetadata { Blog, Contact, Portfolio, + Cours, } #[derive(Default, Deserialize, Content, Debug)] @@ -45,6 +49,7 @@ pub struct FileMetadata { pub blog: Option, pub contact: Option, pub portfolio: Option, + pub cours: Option, } #[derive(Content, Debug, Clone)] @@ -227,6 +232,10 @@ pub fn get_metadata<'a>(root: &'a AstNode<'a>, mtype: TypeFileMetadata) -> FileM portfolio: Some(deserialize_metadata(text)), ..FileMetadata::default() }, + TypeFileMetadata::Cours => FileMetadata { + cours: Some(deserialize_metadata(text)), + ..FileMetadata::default() + }, }), _ => None, }) { @@ -244,6 +253,10 @@ pub fn get_metadata<'a>(root: &'a AstNode<'a>, mtype: TypeFileMetadata) -> FileM portfolio: Some(FileMetadataPortfolio::default()), ..FileMetadata::default() }, + TypeFileMetadata::Cours => FileMetadata { + cours: Some(FileMetadataCours::default()), + ..FileMetadata::default() + }, }, } } diff --git a/src/routes/cours.rs b/src/routes/cours.rs index d7df58d..1ce7074 100644 --- a/src/routes/cours.rs +++ b/src/routes/cours.rs @@ -1,9 +1,13 @@ use actix_web::{get, web, Responder}; +use glob::glob; use ramhorns::Content; use crate::{ config::Config, - misc::utils::{make_kw, Html}, + misc::{ + markdown::{read_file, TypeFileMetadata}, + utils::{make_kw, Html}, + }, template::{Infos, NavBar}, }; @@ -15,6 +19,20 @@ async fn page(config: web::Data) -> impl Responder { #[derive(Content, Debug)] struct CoursTemplate { navbar: NavBar, + /* filetree: Truc, */ +} + +/// Get the filetree +fn get_filetree() { + let cours_dir = "data/cours"; + glob(&format!("{cours_dir}/*")).unwrap(); +} + +/// Get a page +fn get_page(filename: &str) { + let cours_dir = "data/cours"; + + let post = read_file(&format!("{cours_dir}/{filename}"), TypeFileMetadata::Cours); } // #[once(time = 60)]