2020-07-12 23:26:53 +00:00
|
|
|
use crate::{
|
|
|
|
app::State,
|
2020-07-13 02:58:00 +00:00
|
|
|
post::Post,
|
2020-07-12 23:30:01 +00:00
|
|
|
templates::{self, Html, RenderRucte},
|
2020-07-12 23:26:53 +00:00
|
|
|
};
|
|
|
|
use std::sync::Arc;
|
2020-07-12 23:30:01 +00:00
|
|
|
use warp::{http::Response, Rejection, Reply};
|
2020-07-12 22:39:50 +00:00
|
|
|
|
|
|
|
pub async fn index() -> Result<impl Reply, Rejection> {
|
|
|
|
Response::builder().html(|o| templates::index_html(o))
|
|
|
|
}
|
2020-07-12 22:58:38 +00:00
|
|
|
|
|
|
|
pub async fn contact() -> Result<impl Reply, Rejection> {
|
|
|
|
Response::builder().html(|o| templates::contact_html(o))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn feeds() -> Result<impl Reply, Rejection> {
|
|
|
|
Response::builder().html(|o| templates::feeds_html(o))
|
|
|
|
}
|
2020-07-12 23:26:53 +00:00
|
|
|
|
|
|
|
pub async fn resume(state: Arc<State>) -> Result<impl Reply, Rejection> {
|
|
|
|
let state = state.clone();
|
|
|
|
Response::builder().html(|o| templates::resume_html(o, Html(state.resume.clone())))
|
|
|
|
}
|
2020-07-12 23:37:01 +00:00
|
|
|
|
|
|
|
pub async fn signalboost(state: Arc<State>) -> Result<impl Reply, Rejection> {
|
|
|
|
let state = state.clone();
|
|
|
|
Response::builder().html(|o| templates::signalboost_html(o, state.signalboost.clone()))
|
|
|
|
}
|
2020-07-13 00:51:58 +00:00
|
|
|
|
2020-07-13 02:58:00 +00:00
|
|
|
pub async fn not_found() -> Result<impl Reply, Rejection> {
|
|
|
|
Response::builder().html(|o| templates::notfound_html(o, "some path".into()))
|
2020-07-13 00:51:58 +00:00
|
|
|
}
|
2020-07-13 02:16:59 +00:00
|
|
|
|
|
|
|
pub async fn blog_index(state: Arc<State>) -> Result<impl Reply, Rejection> {
|
|
|
|
let state = state.clone();
|
|
|
|
Response::builder().html(|o| templates::blogindex_html(o, state.blog.clone()))
|
|
|
|
}
|
2020-07-13 02:58:00 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|