fix routing?
This commit is contained in:
parent
10346d4621
commit
512e6eb9a5
|
@ -1,5 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
app::State,
|
app::State,
|
||||||
|
post::Post,
|
||||||
templates::{self, Html, RenderRucte},
|
templates::{self, Html, RenderRucte},
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -27,11 +28,44 @@ pub async fn signalboost(state: Arc<State>) -> Result<impl Reply, Rejection> {
|
||||||
Response::builder().html(|o| templates::signalboost_html(o, state.signalboost.clone()))
|
Response::builder().html(|o| templates::signalboost_html(o, state.signalboost.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn not_found(path: String) -> Result<impl Reply, Rejection> {
|
pub async fn not_found() -> Result<impl Reply, Rejection> {
|
||||||
Response::builder().html(|o| templates::notfound_html(o, path))
|
Response::builder().html(|o| templates::notfound_html(o, "some path".into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn blog_index(state: Arc<State>) -> Result<impl Reply, Rejection> {
|
pub async fn blog_index(state: Arc<State>) -> Result<impl Reply, Rejection> {
|
||||||
let state = state.clone();
|
let state = state.clone();
|
||||||
Response::builder().html(|o| templates::blogindex_html(o, state.blog.clone()))
|
Response::builder().html(|o| templates::blogindex_html(o, state.blog.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn blog_series(state: Arc<State>) -> Result<impl Reply, Rejection> {
|
||||||
|
let state = state.clone();
|
||||||
|
let mut series: Vec<String> = 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<State>) -> Result<impl Reply, Rejection> {
|
||||||
|
let state = state.clone();
|
||||||
|
let mut posts: Vec<Post> = 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))
|
||||||
|
}
|
||||||
|
|
26
src/main.rs
26
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 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<State> | handlers::blog_series_view(series, state)));
|
||||||
|
|
||||||
let routes = warp::get()
|
let routes = warp::get()
|
||||||
.and(path::end().and_then(handlers::index))
|
.and(path::end().and_then(handlers::index))
|
||||||
.or(warp::path!("contact").and_then(handlers::contact))
|
.or(warp::path!("contact").and_then(handlers::contact))
|
||||||
|
@ -40,12 +58,8 @@ async fn main() -> Result<()> {
|
||||||
.or(warp::path!("signalboost")
|
.or(warp::path!("signalboost")
|
||||||
.and(with_state(state.clone()))
|
.and(with_state(state.clone()))
|
||||||
.and_then(handlers::signalboost))
|
.and_then(handlers::signalboost))
|
||||||
.or(warp::path!("blog").and(
|
.or(blog)
|
||||||
warp::path::end()
|
.or(warp::any().and_then(handlers::not_found));
|
||||||
.and(with_state(state.clone()))
|
|
||||||
.and_then(handlers::blog_index),
|
|
||||||
));
|
|
||||||
|
|
||||||
let files = warp::path("static")
|
let files = warp::path("static")
|
||||||
.and(warp::fs::dir("./static"))
|
.and(warp::fs::dir("./static"))
|
||||||
.or(warp::path("css").and(warp::fs::dir("./css")))
|
.or(warp::path("css").and(warp::fs::dir("./css")))
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
@use super::{header_html, footer_html};
|
||||||
|
|
||||||
|
@(series: Vec<String>)
|
||||||
|
|
||||||
|
@:header_html(Some("Blog"), None)
|
||||||
|
|
||||||
|
<h1>Post Series</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<ul>
|
||||||
|
@for set in series {
|
||||||
|
<li><a href="/blog/series/@set">@set</a></li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
@:footer_html()
|
|
@ -0,0 +1,18 @@
|
||||||
|
@use crate::post::Post;
|
||||||
|
@use super::{header_html, footer_html};
|
||||||
|
|
||||||
|
@(name: String, posts: &Vec<Post>)
|
||||||
|
|
||||||
|
@:header_html(Some(&name), None)
|
||||||
|
|
||||||
|
<h1>Series: @name</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<ul>
|
||||||
|
@for post in posts {
|
||||||
|
<li>@post.date - <a href="/@post.link">@post.front_matter.title</a></li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
@:footer_html()
|
Loading…
Reference in New Issue