diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/handlers.rs | 16 | ||||
-rw-r--r-- | src/main.rs | 9 | ||||
-rw-r--r-- | src/posts/fs_post.rs | 4 | ||||
-rw-r--r-- | src/tutors/fs_tutor.rs | 4 | ||||
-rw-r--r-- | src/views.rs | 2 | ||||
-rw-r--r-- | src/views/highered.rs | 6 | ||||
-rw-r--r-- | src/views/pro.rs | 6 |
7 files changed, 42 insertions, 5 deletions
diff --git a/src/handlers.rs b/src/handlers.rs index 43d31fd..aa36e15 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -2,14 +2,16 @@ use crate::posts::abstractions::repo::PostRepo; use crate::tutors::abstractions::tutor_repo::TutorRepo; use crate::views::about::AboutView; use crate::views::brochure::BrochureTemplate; +use crate::views::highered::HigherEdTemplate; use crate::views::index::IndexTemplate; use crate::views::k12::K12Template; use crate::views::policies::PoliciesTemplate; use crate::views::post::PostView; use crate::views::posts::PostsView; +use crate::views::pro::ProTemplate; use askama::Template; use axum::extract::{Path, State}; -use axum::response::Html; +use axum::response::{Html, Redirect}; use std::sync::Arc; pub async fn about_handler(State(repo): State<Arc<impl TutorRepo>>) -> Html<String> { @@ -42,6 +44,18 @@ pub async fn post_handler( Html(view.render().unwrap()) } +pub async fn post_redirect(Path(post_id): Path<String>) -> Redirect { + Redirect::permanent(&format!("/blog/{post_id}")) +} + pub async fn k12_handler() -> Html<String> { Html(K12Template {}.render().unwrap()) } + +pub async fn highered_handler() -> Html<String> { + Html(HigherEdTemplate {}.render().unwrap()) +} + +pub async fn pro_handler() -> Html<String> { + Html(ProTemplate {}.render().unwrap()) +} diff --git a/src/main.rs b/src/main.rs index 57b0256..a9cd722 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use axum::response::Redirect; use axum::{extract::Request, routing::get, Router, ServiceExt}; use middleware::cache_control::cache_static; use posts::fs_post_repo::FsPostRepo; @@ -41,13 +42,17 @@ async fn main() { info!("initializing router..."); let app = Router::new() .route("/", get(handlers::index_handler)) - .route("/posts", get(handlers::posts_handler)) - .route("/posts/:post_id", get(handlers::post_handler)) + .route("/posts", get(|| async { Redirect::permanent("/blog") })) + .route("/posts/{post_id}", get(handlers::post_redirect)) + .route("/blog", get(handlers::posts_handler)) + .route("/blog/{post_id}", get(handlers::post_handler)) .with_state(posts) .route("/policies", get(handlers::policies_handler)) .route("/brochure", get(handlers::brochure_handler)) .route("/about", get(handlers::about_handler)) .route("/k12", get(handlers::k12_handler)) + .route("/highered", get(handlers::highered_handler)) + .route("/professional", get(handlers::pro_handler)) .with_state(tutors) .nest_service("/assets", ServeDir::new(assets_dir)) .nest_service("/team", ServeDir::new(tutor_dir)) diff --git a/src/posts/fs_post.rs b/src/posts/fs_post.rs index 4fc03b2..12ce538 100644 --- a/src/posts/fs_post.rs +++ b/src/posts/fs_post.rs @@ -1,3 +1,5 @@ +use comrak::Options; + use crate::posts::abstractions::post::Post; use std::{borrow::Cow, fs, path::PathBuf}; @@ -19,7 +21,7 @@ impl Post for FsPost { fn get_article(&self) -> Cow<str> { let article = fs::read_to_string(&self.file).unwrap(); - Cow::Owned(article) + Cow::Owned(comrak::markdown_to_html(&article, &Options::default())) } fn get_description(&self) -> Cow<str> { diff --git a/src/tutors/fs_tutor.rs b/src/tutors/fs_tutor.rs index dc8a635..6b05fd8 100644 --- a/src/tutors/fs_tutor.rs +++ b/src/tutors/fs_tutor.rs @@ -1,3 +1,5 @@ +use comrak::Options; + use crate::tutors::abstractions::tutor::Tutor; use std::{borrow::Cow, cmp::Ordering, fs, path::PathBuf}; @@ -25,7 +27,7 @@ impl Tutor for FsTutor { let mut path = self.dir.to_owned(); path.push(format!("{}.md", self.get_id())); let blurb = fs::read_to_string(path).unwrap(); - Cow::Owned(blurb) + Cow::Owned(comrak::markdown_to_html(&blurb, &Options::default())) } } diff --git a/src/views.rs b/src/views.rs index e9f1951..f880818 100644 --- a/src/views.rs +++ b/src/views.rs @@ -1,7 +1,9 @@ pub mod about; pub mod brochure; +pub mod highered; pub mod index; pub mod k12; pub mod policies; pub mod post; pub mod posts; +pub mod pro; diff --git a/src/views/highered.rs b/src/views/highered.rs new file mode 100644 index 0000000..108a76a --- /dev/null +++ b/src/views/highered.rs @@ -0,0 +1,6 @@ +use crate::helpers::*; +use askama::Template; + +#[derive(Template)] +#[template(path = "highered.html.j2")] +pub struct HigherEdTemplate; diff --git a/src/views/pro.rs b/src/views/pro.rs new file mode 100644 index 0000000..eacfd7c --- /dev/null +++ b/src/views/pro.rs @@ -0,0 +1,6 @@ +use crate::helpers::*; +use askama::Template; + +#[derive(Template)] +#[template(path = "pro.html.j2")] +pub struct ProTemplate; |