diff options
Diffstat (limited to 'src/pages.rs')
-rw-r--r-- | src/pages.rs | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/pages.rs b/src/pages.rs index b9831cc..4990491 100644 --- a/src/pages.rs +++ b/src/pages.rs @@ -1,9 +1,16 @@ -use crate::layout::{DynScaffold, Scaffold}; -use rocket::{get, http::ContentType, response::Redirect, uri}; +use crate::uri; +use crate::{ + helper::get_articles, + layout::{DynScaffold, Scaffold}, + rocket_uri_macro_r_blog_article, ARTICLE_ROOT, +}; +use chrono::{NaiveTime, Utc}; +use rocket::{get, http::ContentType, response::Redirect}; +use std::{path::PathBuf, str::FromStr}; #[get("/")] pub fn r_root() -> Redirect { - Redirect::to(uri!(r_about())) + Redirect::to(rocket::uri!(r_about())) } #[get("/hello")] @@ -12,10 +19,32 @@ pub fn r_hello() -> &'static str { } #[get("/about")] -pub fn r_about() -> DynScaffold<'static> { +pub async fn r_about<'a>() -> DynScaffold<'a> { + let articles = get_articles(&PathBuf::from_str(ARTICLE_ROOT).unwrap()) + .await + .unwrap_or_default(); + let mut newest = articles.first().cloned(); + if let Some(n) = &newest { + if n.date + .into_naive() + .unwrap() + .and_time(NaiveTime::default()) + .and_utc() + .signed_duration_since(Utc::now()) + .num_days() + < -8 + { + newest = None; + } + } Scaffold { title: "about".to_string(), content: markup::new! { + @if let Some(a) = &newest { + .featured { + p { "Read the newest blog post: " a[href=uri!(r_blog_article(&a.canonical_name))] { @a.title } } + } + } p { "Hi. I am a normal person from planet earth. " "I enjoy starting projects and never finishing them. " |