aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/mod.rs
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2021-03-13 09:03:19 -0500
committerGitHub <noreply@github.com>2021-03-13 09:03:19 -0500
commit9b43f16d806d54fcfdbdb9b3988a4b0c5c0a5cb1 (patch)
tree4ed1632434b1c321fff4c414314de351fd6145f3 /src/handlers/mod.rs
parent8b97cde7a5b9a0e8c80e658b867339cbc7bca3b6 (diff)
downloadxesite-9b43f16d806d54fcfdbdb9b3988a4b0c5c0a5cb1.tar.xz
xesite-9b43f16d806d54fcfdbdb9b3988a4b0c5c0a5cb1.zip
css/gruvbox-dark: enable light mode if the os tells me to (#342)
* css/gruvbox-dark: enable light mode if the os tells me to Signed-off-by: Christine Dodrill <me@christine.website> * handlers: add Last-Modified support Signed-off-by: Christine Dodrill <me@christine.website>
Diffstat (limited to 'src/handlers/mod.rs')
-rw-r--r--src/handlers/mod.rs42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs
index c6dbd65..798a911 100644
--- a/src/handlers/mod.rs
+++ b/src/handlers/mod.rs
@@ -2,6 +2,7 @@ use crate::{
app::State,
templates::{self, Html, RenderRucte},
};
+use chrono::{Datelike, Timelike, Utc};
use lazy_static::lazy_static;
use prometheus::{opts, register_int_counter_vec, IntCounterVec};
use std::{convert::Infallible, fmt, sync::Arc};
@@ -15,31 +16,52 @@ lazy_static! {
static ref HIT_COUNTER: IntCounterVec =
register_int_counter_vec!(opts!("hits", "Number of hits to various pages"), &["page"])
.unwrap();
+ pub static ref LAST_MODIFIED: String = {
+ let now = Utc::now();
+ format!(
+ "{dayname}, {day} {month} {year} {hour}:{minute}:{second} GMT",
+ dayname = now.weekday(),
+ day = now.day(),
+ month = now.month(),
+ year = now.year(),
+ hour = now.hour(),
+ minute = now.minute(),
+ second = now.second()
+ )
+ };
}
#[instrument]
pub async fn index() -> Result<impl Reply, Rejection> {
HIT_COUNTER.with_label_values(&["index"]).inc();
- Response::builder().html(|o| templates::index_html(o))
+ Response::builder()
+ .header("Last-Modified", &*LAST_MODIFIED)
+ .html(|o| templates::index_html(o))
}
#[instrument]
pub async fn contact() -> Result<impl Reply, Rejection> {
HIT_COUNTER.with_label_values(&["contact"]).inc();
- Response::builder().html(|o| templates::contact_html(o))
+ Response::builder()
+ .header("Last-Modified", &*LAST_MODIFIED)
+ .html(|o| templates::contact_html(o))
}
#[instrument]
pub async fn feeds() -> Result<impl Reply, Rejection> {
HIT_COUNTER.with_label_values(&["feeds"]).inc();
- Response::builder().html(|o| templates::feeds_html(o))
+ Response::builder()
+ .header("Last-Modified", &*LAST_MODIFIED)
+ .html(|o| templates::feeds_html(o))
}
#[instrument(skip(state))]
pub async fn resume(state: Arc<State>) -> Result<impl Reply, Rejection> {
HIT_COUNTER.with_label_values(&["resume"]).inc();
let state = state.clone();
- Response::builder().html(|o| templates::resume_html(o, Html(state.resume.clone())))
+ Response::builder()
+ .header("Last-Modified", &*LAST_MODIFIED)
+ .html(|o| templates::resume_html(o, Html(state.resume.clone())))
}
#[instrument(skip(state))]
@@ -53,7 +75,9 @@ pub async fn patrons(state: Arc<State>) -> Result<impl Reply, Rejection> {
"Could not load patrons, let me know the API token expired again".to_string(),
)
}),
- Some(patrons) => Response::builder().html(|o| templates::patrons_html(o, patrons.clone())),
+ Some(patrons) => Response::builder()
+ .header("Last-Modified", &*LAST_MODIFIED)
+ .html(|o| templates::patrons_html(o, patrons.clone())),
}
}
@@ -61,13 +85,17 @@ pub async fn patrons(state: Arc<State>) -> Result<impl Reply, Rejection> {
pub async fn signalboost(state: Arc<State>) -> Result<impl Reply, Rejection> {
HIT_COUNTER.with_label_values(&["signalboost"]).inc();
let state = state.clone();
- Response::builder().html(|o| templates::signalboost_html(o, state.signalboost.clone()))
+ Response::builder()
+ .header("Last-Modified", &*LAST_MODIFIED)
+ .html(|o| templates::signalboost_html(o, state.signalboost.clone()))
}
#[instrument]
pub async fn not_found() -> Result<impl Reply, Rejection> {
HIT_COUNTER.with_label_values(&["not_found"]).inc();
- Response::builder().html(|o| templates::notfound_html(o, "some path".into()))
+ Response::builder()
+ .header("Last-Modified", &*LAST_MODIFIED)
+ .html(|o| templates::notfound_html(o, "some path".into()))
}
pub mod blog;