diff options
| author | Xe Iaso <me@christine.website> | 2022-06-08 14:58:29 -0400 |
|---|---|---|
| committer | Xe Iaso <me@christine.website> | 2022-06-08 15:02:52 -0400 |
| commit | dc3f6471e774eaafab92dfcd73dd089707646469 (patch) | |
| tree | 3b69a8d6f1f05b6c59086f14ae0cbef9ae248a24 /src/handlers | |
| parent | 396150f72bcd4545864d96f50afbf39cb6c15afb (diff) | |
| download | xesite-dc3f6471e774eaafab92dfcd73dd089707646469.tar.xz xesite-dc3f6471e774eaafab92dfcd73dd089707646469.zip | |
Add hero image support with <xeblog-hero>
Also lightens the JavaScript load and shifts ad impressions to only when
people from Reddit and Hacker News visit. I may have this include
Twitter in the future.
Signed-off-by: Xe <me@christine.website>
Diffstat (limited to 'src/handlers')
| -rw-r--r-- | src/handlers/blog.rs | 13 | ||||
| -rw-r--r-- | src/handlers/mod.rs | 3 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/handlers/blog.rs b/src/handlers/blog.rs index f6aae06..6c66c97 100644 --- a/src/handlers/blog.rs +++ b/src/handlers/blog.rs @@ -4,6 +4,7 @@ use axum::{ extract::{Extension, Path}, response::Html, }; +use http::HeaderMap; use lazy_static::lazy_static; use prometheus::{opts, register_int_counter_vec, IntCounterVec}; use std::sync::Arc; @@ -72,10 +73,11 @@ pub async fn series_view( Ok(Html(result)) } -#[instrument(skip(state))] +#[instrument(skip(state, headers))] pub async fn post_view( Path(name): Path<String>, Extension(state): Extension<Arc<State>>, + headers: HeaderMap, ) -> Result { let mut want: Option<Post> = None; @@ -85,6 +87,13 @@ pub async fn post_view( } } + let referer = if let Some(referer) = headers.get(http::header::REFERER) { + let referer = referer.to_str()?.to_string(); + Some(referer) + } else { + None + }; + match want { None => Err(super::Error::PostNotFound(name)), Some(post) => { @@ -93,7 +102,7 @@ pub async fn post_view( .inc(); let body = templates::Html(post.body_html.clone()); let mut result: Vec<u8> = vec![]; - templates::blogpost_html(&mut result, post, body)?; + templates::blogpost_html(&mut result, post, body, referer)?; Ok(Html(result)) } } diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 97e0cb2..fa8203c 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -130,6 +130,9 @@ pub enum Error { #[error("axum http error: {0}")] AxumHTTP(#[from] axum::http::Error), + + #[error("string conversion error: {0}")] + ToStr(#[from] http::header::ToStrError), } pub type Result<T = Html<Vec<u8>>> = std::result::Result<T, Error>; |
