summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-04-30 20:58:43 +0200
committermetamuffin <metamuffin@disroot.org>2024-04-30 20:58:43 +0200
commita78ba6bc689d9d3eed2c0f49cd075ceee045c95f (patch)
tree76ae90ae71957b59578ef5b7600f9717778b81c8
parent67d97d5c17fb27f496a0b1d8d6ca429cf942bb93 (diff)
downloadmetamuffin-website-a78ba6bc689d9d3eed2c0f49cd075ceee045c95f.tar
metamuffin-website-a78ba6bc689d9d3eed2c0f49cd075ceee045c95f.tar.bz2
metamuffin-website-a78ba6bc689d9d3eed2c0f49cd075ceee045c95f.tar.zst
show new blog posts
-rw-r--r--assets/style.css6
-rw-r--r--src/blog/helper.rs1
-rw-r--r--src/pages.rs37
3 files changed, 40 insertions, 4 deletions
diff --git a/assets/style.css b/assets/style.css
index 888a420..8ac5354 100644
--- a/assets/style.css
+++ b/assets/style.css
@@ -104,3 +104,9 @@ input[type=submit] {
.status-maintained { background-color: #95ff63; }
.status-abandoned-working { background-color: #ff9854; }
.status-abandoned-unfinished { background-color: #ff6854; }
+
+.featured {
+ background-color: var(--bg2);
+ border-radius: 1em;
+ padding: 0.1em;
+}
diff --git a/src/blog/helper.rs b/src/blog/helper.rs
index 6dea529..35396c0 100644
--- a/src/blog/helper.rs
+++ b/src/blog/helper.rs
@@ -10,6 +10,7 @@ use tokio::{
process::Command,
};
+#[derive(Clone)]
pub struct ArticleMeta {
pub title: String,
pub canonical_name: String,
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. "