summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-04-06 12:22:54 -0400
committerCara Salter <cara@devcara.com>2022-04-06 12:22:54 -0400
commitaef8039358b3d9f0cbd47dfa04ab3d24a2c05e5c (patch)
tree820961116cb84d98514877bc049003afc1e36e0c /src
parentc9b5f2c8bd5aa6ba00ae7d3a8935e0add429b110 (diff)
downloadsite-aef8039358b3d9f0cbd47dfa04ab3d24a2c05e5c.tar.gz
site-aef8039358b3d9f0cbd47dfa04ab3d24a2c05e5c.zip
flakes + projects
Diffstat (limited to 'src')
-rw-r--r--src/blog/mod.rs2
-rw-r--r--src/internal/mod.rs4
-rw-r--r--src/main.rs9
-rw-r--r--src/projects/mod.rs38
4 files changed, 51 insertions, 2 deletions
diff --git a/src/blog/mod.rs b/src/blog/mod.rs
index 811de15..ac1413e 100644
--- a/src/blog/mod.rs
+++ b/src/blog/mod.rs
@@ -14,7 +14,7 @@ pub mod handlers {
pub async fn list(state: Arc<SiteState>) -> Result<impl Reply, Rejection> {
let state = state.clone();
- Response::builder().html(|o| templates::bloglist_html(o, state.blog.clone()))
+ Response::builder().html(|o| templates::bloglist_html(o, state.blog.clone(), "Posts".into()))
}
pub async fn post(name: String, state: Arc<SiteState>) -> Result<impl Reply, Rejection> {
diff --git a/src/internal/mod.rs b/src/internal/mod.rs
index 2a5fa56..5f42764 100644
--- a/src/internal/mod.rs
+++ b/src/internal/mod.rs
@@ -5,10 +5,12 @@ pub mod markdown;
pub struct SiteState {
pub blog: Vec<Post>,
+ pub projects: Vec<Post>,
}
pub async fn init() -> Result<SiteState> {
let blog = crate::blog::post::load("blog").await?;
+ let projects = crate::blog::post::load("projects").await?;
- Ok(SiteState { blog })
+ Ok(SiteState { blog, projects })
}
diff --git a/src/main.rs b/src/main.rs
index 21eac18..b4801ad 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,6 +8,7 @@ use warp::{path, Filter};
use std::str::FromStr;
pub mod blog;
+pub mod projects;
mod internal;
pub mod misc;
@@ -35,9 +36,17 @@ async fn main() -> Result<()> {
.and(give_site_state(state.clone()))
.and_then(blog::handlers::post);
+ let project_index = warp::path!("projects")
+ .and(give_site_state(state.clone()))
+ .and_then(projects::handlers::list);
+ let project = warp::path!("projects" / String)
+ .and(give_site_state(state.clone()))
+ .and_then(projects::handlers::project);
+
let static_files = warp::path("static").and(warp::fs::dir("./statics"));
let site = index.or(about)
.or(blog_index.or(blog_post))
+ .or(project_index.or(project))
.or(static_files)
.with(warp::log("site"));
diff --git a/src/projects/mod.rs b/src/projects/mod.rs
new file mode 100644
index 0000000..f69c2c0
--- /dev/null
+++ b/src/projects/mod.rs
@@ -0,0 +1,38 @@
+use crate::blog::post;
+pub mod handlers {
+
+ use color_eyre::eyre::eyre;
+ use std::sync::Arc;
+
+ use crate::templates::{self, Html, RenderRucte};
+ use warp::http::Response;
+ use warp::{Rejection, Reply};
+
+ use crate::internal::SiteState;
+
+ use crate::blog::post::Post;
+
+ pub async fn list(state: Arc<SiteState>) -> Result<impl Reply, Rejection> {
+ let state = state.clone();
+ Response::builder().html(|o| templates::bloglist_html(o, state.projects.clone(), "Projects".into()))
+ }
+
+ pub async fn project(name: String, state: Arc<SiteState>) -> Result<impl Reply, Rejection> {
+ let mut want: Option<Post> = None;
+
+ for post in &state.projects {
+ if post.link == format!("projects/{}", 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"),
+ }
+ }
+}