aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs17
-rw-r--r--src/poetry.rs18
-rw-r--r--src/posts/note.rs7
-rw-r--r--src/templates.rs15
4 files changed, 41 insertions, 16 deletions
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<T> = std::result::Result<T, BlossomError>;
@@ -123,6 +124,20 @@ async fn plants() -> Result<()> {
Err(BlossomError::Unimplemented)
}
+#[handler]
+async fn get_poem(Path(poem): Path<String>) -> Result<templates::Poem> {
+ let poem = Poem::get_article(&poem).await?;
+ Ok(templates::Poem { poem, jiggle: 4 })
+}
+
+#[handler]
+async fn get_poetry() -> Result<templates::Poetry> {
+ 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<String>,
- created_at: DateTime<Utc>,
- published_at: DateTime<Utc>,
- updated_at: Option<DateTime<Utc>>,
- content: String,
+ pub file_name: String,
+ pub title: Option<String>,
+ pub created_at: DateTime<Utc>,
+ pub published_at: DateTime<Utc>,
+ pub updated_at: Option<DateTime<Utc>>,
+ 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};
@@ -44,6 +45,20 @@ pub struct Blog {
}
#[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<poetry::Poem>,
+ pub jiggle: isize,
+}
+
+#[derive(Template)]
#[template(path = "contact.html")]
pub struct Contact;