aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/talks.rs
diff options
context:
space:
mode:
authorXe Iaso <me@christine.website>2022-03-21 20:14:14 -0400
committerGitHub <noreply@github.com>2022-03-21 20:14:14 -0400
commit8b747c1c40876c6668191594eddcb260199cdb7f (patch)
tree86edb9bc382751c6a32f5f2946ff235ea06674ba /src/handlers/talks.rs
parentf45ca40ae1052d46611ff2f27ad281695afc4f8f (diff)
downloadxesite-8b747c1c40876c6668191594eddcb260199cdb7f.tar.xz
xesite-8b747c1c40876c6668191594eddcb260199cdb7f.zip
Rewrite the site routing with Axum (#441)
* broken state Signed-off-by: Xe Iaso <me@christine.website> * fix??? Signed-off-by: Xe Iaso <me@christine.website> * Port everything else to axum Signed-off-by: Xe <me@christine.website> * headers Signed-off-by: Xe Iaso <me@christine.website> * site update post Signed-off-by: Christine Dodrill <me@christine.website> * fix headers Signed-off-by: Xe Iaso <me@christine.website> * remove warp example Signed-off-by: Xe Iaso <me@christine.website> * 80c wrap Signed-off-by: Xe Iaso <me@christine.website> * bump version Signed-off-by: Xe Iaso <me@christine.website>
Diffstat (limited to 'src/handlers/talks.rs')
-rw-r--r--src/handlers/talks.rs30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/handlers/talks.rs b/src/handlers/talks.rs
index 8db5c9e..22ee3cf 100644
--- a/src/handlers/talks.rs
+++ b/src/handlers/talks.rs
@@ -1,14 +1,13 @@
-use super::PostNotFound;
-use crate::{
- app::State,
- post::Post,
- templates::{self, Html, RenderRucte},
+use super::{Error::*, Result};
+use crate::{app::State, post::Post, templates};
+use axum::{
+ extract::{Extension, Path},
+ response::Html,
};
use lazy_static::lazy_static;
use prometheus::{opts, register_int_counter_vec, IntCounterVec};
use std::sync::Arc;
use tracing::instrument;
-use warp::{http::Response, Rejection, Reply};
lazy_static! {
static ref HIT_COUNTER: IntCounterVec = register_int_counter_vec!(
@@ -19,13 +18,18 @@ lazy_static! {
}
#[instrument(skip(state))]
-pub async fn index(state: Arc<State>) -> Result<impl Reply, Rejection> {
+pub async fn index(Extension(state): Extension<Arc<State>>) -> Result {
let state = state.clone();
- Response::builder().html(|o| templates::talkindex_html(o, state.talks.clone()))
+ let mut result: Vec<u8> = vec![];
+ templates::talkindex_html(&mut result, state.talks.clone())?;
+ Ok(Html(result))
}
#[instrument(skip(state))]
-pub async fn post_view(name: String, state: Arc<State>) -> Result<impl Reply, Rejection> {
+pub async fn post_view(
+ Path(name): Path<String>,
+ Extension(state): Extension<Arc<State>>,
+) -> Result {
let mut want: Option<Post> = None;
for post in &state.talks {
@@ -35,13 +39,15 @@ pub async fn post_view(name: String, state: Arc<State>) -> Result<impl Reply, Re
}
match want {
- None => Err(PostNotFound("talks".into(), name).into()),
+ None => Err(PostNotFound(name).into()),
Some(post) => {
HIT_COUNTER
.with_label_values(&[name.clone().as_str()])
.inc();
- let body = Html(post.body_html.clone());
- Response::builder().html(|o| templates::talkpost_html(o, post, body))
+ let body = templates::Html(post.body_html.clone());
+ let mut result: Vec<u8> = vec![];
+ templates::talkpost_html(&mut result, post, body)?;
+ Ok(Html(result))
}
}
}