From 2ac490aca1be78d5cb01eeeb9639c6d02ccf40e5 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Wed, 31 Jan 2024 21:02:28 +0000 Subject: add poetry --- src/main.rs | 17 +++++++++++++++++ src/poetry.rs | 18 +++++++++--------- src/posts/note.rs | 7 ------- src/templates.rs | 15 +++++++++++++++ 4 files changed, 41 insertions(+), 16 deletions(-) delete mode 100644 src/posts/note.rs (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 4f8ec55..5ee3b2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,7 @@ use tracing_subscriber::FmtSubscriber; use crate::article::Article; use crate::blog::Blogpost; +use crate::poetry::Poem; use crate::posts::Post; type Result = std::result::Result; @@ -123,6 +124,20 @@ async fn plants() -> Result<()> { Err(BlossomError::Unimplemented) } +#[handler] +async fn get_poem(Path(poem): Path) -> Result { + let poem = Poem::get_article(&poem).await?; + Ok(templates::Poem { poem, jiggle: 4 }) +} + +#[handler] +async fn get_poetry() -> Result { + let mut poems = Poem::get_articles().await?; + poems.sort_by_key(|poem| poem.created_at); + poems.reverse(); + Ok(templates::Poetry { poems, jiggle: 16 }) +} + async fn custom_error(err: poem::Error) -> impl IntoResponse { templates::Error { status: err.status(), @@ -143,6 +158,8 @@ async fn main() -> std::result::Result<(), std::io::Error> { .at("/", get(home)) .at("/blog", get(get_blog)) .at("/blog/:blogpost", get(blogpost)) + .at("/poetry", get(get_poetry)) + .at("/poetry/:poem", get(get_poem)) .at("/feed", get(feed)) .at("/contact", get(contact)) .at("/plants", get(plants)) diff --git a/src/poetry.rs b/src/poetry.rs index 6429bd3..ef168e8 100644 --- a/src/poetry.rs +++ b/src/poetry.rs @@ -7,14 +7,14 @@ use crate::{article::Article, posts::Post}; static DIRECTORY: &str = "./poetry"; pub struct Poem { - file_name: String, - title: Option, - created_at: DateTime, - published_at: DateTime, - updated_at: Option>, - content: String, + pub file_name: String, + pub title: Option, + pub created_at: DateTime, + pub published_at: DateTime, + pub updated_at: Option>, + pub content: String, // TODO: localisation (get lang from file names) - lang: String, + pub lang: String, } #[derive(Deserialize)] @@ -78,10 +78,10 @@ impl Post for Poem { } fn post_type(&self) -> crate::posts::PostType { - todo!() + crate::posts::PostType::Article } fn content(&self) -> &str { - todo!() + &self.content } } diff --git a/src/posts/note.rs b/src/posts/note.rs deleted file mode 100644 index d7fa6c9..0000000 --- a/src/posts/note.rs +++ /dev/null @@ -1,7 +0,0 @@ -enum TextFormat { - Markdown, - Plaintext, - Html, -} - -struct Note {} diff --git a/src/templates.rs b/src/templates.rs index 861930f..8eafd98 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -4,6 +4,7 @@ use askama::Template; use poem::http::StatusCode; use rand::{thread_rng, Rng}; +use crate::poetry; use crate::posts::Post; use crate::{blog, scrobbles::NowPlayingData}; @@ -43,6 +44,20 @@ pub struct Blog { pub filter_tags: HashSet, } +#[derive(Template)] +#[template(path = "poem.html")] +pub struct Poem { + pub poem: poetry::Poem, + pub jiggle: isize, +} + +#[derive(Template)] +#[template(path = "poetry.html")] +pub struct Poetry { + pub poems: Vec, + pub jiggle: isize, +} + #[derive(Template)] #[template(path = "contact.html")] pub struct Contact; -- cgit