diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs
index 85e8bbf..b30cd07 100644
--- a/src/handlers/mod.rs
+++ b/src/handlers/mod.rs
@@ -1,5 +1,6 @@
use crate::{
app::State,
+ post::Post,
templates::{self, Html, RenderRucte},
};
use std::sync::Arc;
@@ -27,11 +28,44 @@ pub async fn signalboost(state: Arc) -> Result {
Response::builder().html(|o| templates::signalboost_html(o, state.signalboost.clone()))
}
-pub async fn not_found(path: String) -> Result {
- Response::builder().html(|o| templates::notfound_html(o, path))
+pub async fn not_found() -> Result {
+ Response::builder().html(|o| templates::notfound_html(o, "some path".into()))
}
pub async fn blog_index(state: Arc) -> Result {
let state = state.clone();
Response::builder().html(|o| templates::blogindex_html(o, state.blog.clone()))
}
+
+pub async fn blog_series(state: Arc) -> Result {
+ let state = state.clone();
+ let mut series: Vec = vec![];
+
+ for post in &state.blog {
+ if post.front_matter.series.is_some() {
+ series.push(post.front_matter.series.as_ref().unwrap().clone());
+ }
+ }
+
+ series.sort();
+ series.dedup();
+
+ Response::builder().html(|o| templates::series_html(o, series))
+}
+
+pub async fn blog_series_view(series: String, state: Arc) -> Result {
+ let state = state.clone();
+ let mut posts: Vec = vec![];
+
+ for post in &state.blog {
+ if post.front_matter.series.is_none() {
+ continue;
+ }
+ if post.front_matter.series.as_ref().unwrap() != &series {
+ continue;
+ }
+ posts.push(post.clone());
+ }
+
+ Response::builder().html(|o| templates::series_posts_html(o, series, &posts))
+}
diff --git a/src/main.rs b/src/main.rs
index edb1029..61647c1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -30,6 +30,24 @@ async fn main() -> Result<()> {
let healthcheck = warp::get().and(warp::path(".within").and(warp::path("health")).map(|| "OK"));
+ let blog = {
+ let base = warp::path!("blog" / ..);
+ let index = base
+ .and(warp::path::end())
+ .and(with_state(state.clone()))
+ .and_then(handlers::blog_index);
+ let series = base.and(
+ warp::path!("series").and(with_state(state.clone()).and_then(handlers::blog_series)),
+ );
+
+ index.or(series)
+ };
+
+ // let blog_series_view = warp::path!("blog" / "series" / String)
+ // .and(warp::get())
+ // .and(with_state(state.clone())
+ // .and_then( move | series: String, state: Arc | handlers::blog_series_view(series, state)));
+
let routes = warp::get()
.and(path::end().and_then(handlers::index))
.or(warp::path!("contact").and_then(handlers::contact))
@@ -40,12 +58,8 @@ async fn main() -> Result<()> {
.or(warp::path!("signalboost")
.and(with_state(state.clone()))
.and_then(handlers::signalboost))
- .or(warp::path!("blog").and(
- warp::path::end()
- .and(with_state(state.clone()))
- .and_then(handlers::blog_index),
- ));
-
+ .or(blog)
+ .or(warp::any().and_then(handlers::not_found));
let files = warp::path("static")
.and(warp::fs::dir("./static"))
.or(warp::path("css").and(warp::fs::dir("./css")))
diff --git a/templates/series.rs.html b/templates/series.rs.html
new file mode 100644
index 0000000..acf5d95
--- /dev/null
+++ b/templates/series.rs.html
@@ -0,0 +1,17 @@
+@use super::{header_html, footer_html};
+
+@(series: Vec)
+
+@:header_html(Some("Blog"), None)
+
+Post Series
+
+
+
+ @for set in series {
+ - @set
+ }
+
+
+
+@:footer_html()
diff --git a/templates/series_posts.rs.html b/templates/series_posts.rs.html
new file mode 100644
index 0000000..327950c
--- /dev/null
+++ b/templates/series_posts.rs.html
@@ -0,0 +1,18 @@
+@use crate::post::Post;
+@use super::{header_html, footer_html};
+
+@(name: String, posts: &Vec)
+
+@:header_html(Some(&name), None)
+
+Series: @name
+
+
+
+
+
+@:footer_html()