summaryrefslogtreecommitdiff
path: root/src/blog
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2021-12-22 01:06:39 -0500
committerCara Salter <cara@devcara.com>2021-12-22 01:06:39 -0500
commit3d7cd8a7addd86b7a97a50821eb348345e0d427a (patch)
tree875aecda597c8161359005c33a147097fa36c807 /src/blog
parentc4d7f8f50d53057005d6bb28ac487f69ea45bd5e (diff)
downloadsite-3d7cd8a7addd86b7a97a50821eb348345e0d427a.tar.gz
site-3d7cd8a7addd86b7a97a50821eb348345e0d427a.zip
Work for the day
Post parsing, index page, navbar, CSS, blog listings There's something weird with the path matching that's making it miss the post view page in favor of the list view page.
Diffstat (limited to 'src/blog')
-rw-r--r--src/blog/mod.rs25
-rw-r--r--src/blog/post.rs18
2 files changed, 38 insertions, 5 deletions
diff --git a/src/blog/mod.rs b/src/blog/mod.rs
index 3640bcd..c227f22 100644
--- a/src/blog/mod.rs
+++ b/src/blog/mod.rs
@@ -2,6 +2,7 @@ pub mod post;
pub mod handlers {
use std::sync::Arc;
+use color_eyre::eyre::eyre;
use warp::{Reply, Rejection};
use warp::http::Response;
@@ -9,13 +10,31 @@ use crate::templates::{self, Html, RenderRucte};
use crate::internal::SiteState;
+use super::post::Post;
+
pub async fn list(state: Arc<SiteState>) -> Result<impl Reply, Rejection> {
let state = state.clone();
Response::builder()
- .html(|o| templates::index_html(o))
+ .html(|o| templates::bloglist_html(o, state.blog.clone()))
}
- pub async fn post(name: String) -> Result<impl Reply, Rejection> {
- Ok("Post test")
+ pub async fn post(name: String, state: Arc<SiteState>) -> Result<impl Reply, Rejection> {
+ let mut want: Option<Post> = None;
+
+ for post in &state.blog {
+ if post.link == format!("blog/{}", name) {
+ want = Some(post.clone());
+ break;
+ }
+ }
+
+ match want {
+ Some(post) => {
+ let body = Html(post.body_html.clone());
+ Response::builder()
+ .html(|o| templates::post_html(o, post, body))
+ },
+ None => panic!("No post found"),
+ }
}
}
diff --git a/src/blog/post.rs b/src/blog/post.rs
index abe57aa..3c27690 100644
--- a/src/blog/post.rs
+++ b/src/blog/post.rs
@@ -1,7 +1,7 @@
use std::{cmp::Ordering, path::PathBuf};
use glob::glob;
use color_eyre::eyre::{Result, Context, eyre};
-use tokio::fs;
+use tokio::{fs};
use chrono::prelude::*;
@@ -11,6 +11,7 @@ pub struct Post {
pub front_matter: frontmatter::Data,
pub body_html: String,
pub date: DateTime<FixedOffset>,
+ pub link: String,
}
impl Ord for Post {
@@ -46,6 +47,7 @@ async fn read_post(dir: &str, fname: PathBuf) -> Result<Post> {
Ok(Post {
front_matter,
body_html,
+ link,
date
} )
}
@@ -55,7 +57,19 @@ pub async fn load(dir: &str) -> Result<Vec<Post>> {
.filter_map(Result::ok)
.map(|fname| read_post(dir, fname));
- Ok(Vec::new())
+ let mut result: Vec<Post> = futures::future::join_all(futs)
+ .await
+ .into_iter()
+ .map(Result::unwrap)
+ .collect();
+
+ if result.len() == 0 {
+ Err(eyre!("No posts found"))
+ } else {
+ result.sort();
+ result.reverse();
+ Ok(result)
+ }
}
mod frontmatter {