aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/gallery.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/handlers/gallery.rs')
-rw-r--r--src/handlers/gallery.rs28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/handlers/gallery.rs b/src/handlers/gallery.rs
index ae6c411..25c8dfa 100644
--- a/src/handlers/gallery.rs
+++ b/src/handlers/gallery.rs
@@ -1,10 +1,8 @@
-use super::{Error::*, Result};
-use crate::{app::State, post::Post, templates};
-use axum::{
- extract::{Extension, Path},
- response::Html,
-};
+use crate::{app::State, post::Post, tmpl};
+use axum::extract::{Extension, Path};
+use http::StatusCode;
use lazy_static::lazy_static;
+use maud::Markup;
use prometheus::{opts, register_int_counter_vec, IntCounterVec};
use std::sync::Arc;
use tracing::instrument;
@@ -18,36 +16,32 @@ lazy_static! {
}
#[instrument(skip(state))]
-pub async fn index(Extension(state): Extension<Arc<State>>) -> Result {
+pub async fn index(Extension(state): Extension<Arc<State>>) -> Markup {
let state = state.clone();
- let mut result: Vec<u8> = vec![];
- templates::galleryindex_html(&mut result, state.gallery.clone())?;
- Ok(Html(result))
+ tmpl::gallery_index(&state.gallery)
}
#[instrument(skip(state))]
pub async fn post_view(
Path(name): Path<String>,
Extension(state): Extension<Arc<State>>,
-) -> Result {
+) -> (StatusCode, Markup) {
let mut want: Option<Post> = None;
+ let link = format!("gallery/{}", name);
for post in &state.gallery {
- if post.link == format!("gallery/{}", name) {
+ if post.link == link {
want = Some(post.clone());
}
}
match want {
- None => Err(PostNotFound(name)),
+ None => (StatusCode::NOT_FOUND, tmpl::not_found(link)),
Some(post) => {
HIT_COUNTER
.with_label_values(&[name.clone().as_str()])
.inc();
- let body = templates::Html(post.body_html.clone());
- let mut result: Vec<u8> = vec![];
- templates::gallerypost_html(&mut result, post, body)?;
- Ok(Html(result))
+ (StatusCode::OK, tmpl::blog::gallery(&post))
}
}
}