aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/talks.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/handlers/talks.rs')
-rw-r--r--src/handlers/talks.rs34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/handlers/talks.rs b/src/handlers/talks.rs
index 3b33431..6d0e782 100644
--- a/src/handlers/talks.rs
+++ b/src/handlers/talks.rs
@@ -3,6 +3,7 @@ use crate::{app::State, post::Post, templates};
use axum::{
extract::{Extension, Path},
response::Html,
+ Json,
};
use http::header::HeaderMap;
use lazy_static::lazy_static;
@@ -16,6 +17,11 @@ lazy_static! {
&["name"]
)
.unwrap();
+ static ref HIT_COUNTER_JSON: IntCounterVec = register_int_counter_vec!(
+ opts!("talks_json_hits", "Number of hits to talks images"),
+ &["name"]
+ )
+ .unwrap();
}
#[instrument(skip(state))]
@@ -33,9 +39,10 @@ pub async fn post_view(
headers: HeaderMap,
) -> Result {
let mut want: Option<Post> = None;
+ let want_link = format!("talks/{}", name);
for post in &state.talks {
- if post.link == format!("talks/{}", name) {
+ if post.link == want_link {
want = Some(post.clone());
}
}
@@ -60,3 +67,28 @@ pub async fn post_view(
}
}
}
+
+#[instrument(skip(state))]
+pub async fn post_json(
+ Path(name): Path<String>,
+ Extension(state): Extension<Arc<State>>,
+) -> Result<Json<xe_jsonfeed::Item>> {
+ let mut want: Option<Post> = None;
+ let want_link = format!("talks/{}", name);
+
+ for post in &state.talks {
+ if post.link == want_link {
+ want = Some(post.clone());
+ }
+ }
+
+ match want {
+ None => Err(super::Error::PostNotFound(name)),
+ Some(post) => {
+ HIT_COUNTER_JSON
+ .with_label_values(&[name.clone().as_str()])
+ .inc();
+ Ok(Json(post.into()))
+ }
+ }
+}