aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/handlers/blog.rs18
-rw-r--r--src/handlers/feeds.rs6
-rw-r--r--src/handlers/gallery.rs16
-rw-r--r--src/handlers/mod.rs42
-rw-r--r--src/handlers/talks.rs16
5 files changed, 73 insertions, 25 deletions
diff --git a/src/handlers/blog.rs b/src/handlers/blog.rs
index fbc0c24..007b8e0 100644
--- a/src/handlers/blog.rs
+++ b/src/handlers/blog.rs
@@ -1,4 +1,4 @@
-use super::{PostNotFound, SeriesNotFound};
+use super::{PostNotFound, SeriesNotFound, LAST_MODIFIED};
use crate::{
app::State,
post::Post,
@@ -21,7 +21,9 @@ lazy_static! {
#[instrument(skip(state))]
pub async fn index(state: Arc<State>) -> Result<impl Reply, Rejection> {
let state = state.clone();
- Response::builder().html(|o| templates::blogindex_html(o, state.blog.clone()))
+ Response::builder()
+ .header("Last-Modified", &*LAST_MODIFIED)
+ .html(|o| templates::blogindex_html(o, state.blog.clone()))
}
#[instrument(skip(state))]
@@ -38,7 +40,9 @@ pub async fn series(state: Arc<State>) -> Result<impl Reply, Rejection> {
series.sort();
series.dedup();
- Response::builder().html(|o| templates::series_html(o, series))
+ Response::builder()
+ .header("Last-Modified", &*LAST_MODIFIED)
+ .html(|o| templates::series_html(o, series))
}
#[instrument(skip(state))]
@@ -60,7 +64,9 @@ pub async fn series_view(series: String, state: Arc<State>) -> Result<impl Reply
error!("series not found");
Err(SeriesNotFound(series).into())
} else {
- Response::builder().html(|o| templates::series_posts_html(o, series, &posts))
+ Response::builder()
+ .header("Last-Modified", &*LAST_MODIFIED)
+ .html(|o| templates::series_posts_html(o, series, &posts))
}
}
@@ -81,7 +87,9 @@ pub async fn post_view(name: String, state: Arc<State>) -> Result<impl Reply, Re
.with_label_values(&[name.clone().as_str()])
.inc();
let body = Html(post.body_html.clone());
- Response::builder().html(|o| templates::blogpost_html(o, post, body))
+ Response::builder()
+ .header("Last-Modified", &*LAST_MODIFIED)
+ .html(|o| templates::blogpost_html(o, post, body))
}
}
}
diff --git a/src/handlers/feeds.rs b/src/handlers/feeds.rs
index 5b5987d..d3f0289 100644
--- a/src/handlers/feeds.rs
+++ b/src/handlers/feeds.rs
@@ -1,3 +1,4 @@
+use super::LAST_MODIFIED;
use crate::{app::State, templates};
use lazy_static::lazy_static;
use prometheus::{opts, register_int_counter_vec, IntCounterVec};
@@ -6,7 +7,7 @@ use tracing::instrument;
use warp::{http::Response, Rejection, Reply};
lazy_static! {
- static ref HIT_COUNTER: IntCounterVec = register_int_counter_vec!(
+ pub static ref HIT_COUNTER: IntCounterVec = register_int_counter_vec!(
opts!("feed_hits", "Number of hits to various feeds"),
&["kind"]
)
@@ -56,6 +57,7 @@ pub async fn atom(state: Arc<State>, since: Option<String>) -> Result<impl Reply
.status(200)
.header("Content-Type", "application/atom+xml")
.header("ETag", ETAG.clone())
+ .header("Last-Modified", &*LAST_MODIFIED)
.body(buf)
.map_err(RenderError::Build)
.map_err(warp::reject::custom)
@@ -88,6 +90,7 @@ pub async fn rss(state: Arc<State>, since: Option<String>) -> Result<impl Reply,
.status(200)
.header("Content-Type", "application/rss+xml")
.header("ETag", ETAG.clone())
+ .header("Last-Modified", &*LAST_MODIFIED)
.body(buf)
.map_err(RenderError::Build)
.map_err(warp::reject::custom)
@@ -100,6 +103,7 @@ pub async fn sitemap(state: Arc<State>) -> Result<impl Reply, Rejection> {
Response::builder()
.status(200)
.header("Content-Type", "application/xml")
+ .header("Last-Modified", &*LAST_MODIFIED)
.body(state.sitemap.clone())
.map_err(RenderError::Build)
.map_err(warp::reject::custom)
diff --git a/src/handlers/gallery.rs b/src/handlers/gallery.rs
index ba3cba2..02bc01b 100644
--- a/src/handlers/gallery.rs
+++ b/src/handlers/gallery.rs
@@ -5,15 +5,17 @@ use crate::{
templates::{self, Html, RenderRucte},
};
use lazy_static::lazy_static;
-use prometheus::{IntCounterVec, register_int_counter_vec, opts};
+use prometheus::{opts, register_int_counter_vec, IntCounterVec};
use std::sync::Arc;
-use warp::{http::Response, Rejection, Reply};
use tracing::instrument;
+use warp::{http::Response, Rejection, Reply};
lazy_static! {
- static ref HIT_COUNTER: IntCounterVec =
- register_int_counter_vec!(opts!("gallery_hits", "Number of hits to gallery images"), &["name"])
- .unwrap();
+ static ref HIT_COUNTER: IntCounterVec = register_int_counter_vec!(
+ opts!("gallery_hits", "Number of hits to gallery images"),
+ &["name"]
+ )
+ .unwrap();
}
#[instrument(skip(state))]
@@ -35,7 +37,9 @@ pub async fn post_view(name: String, state: Arc<State>) -> Result<impl Reply, Re
match want {
None => Err(PostNotFound("gallery".into(), name).into()),
Some(post) => {
- HIT_COUNTER.with_label_values(&[name.clone().as_str()]).inc();
+ HIT_COUNTER
+ .with_label_values(&[name.clone().as_str()])
+ .inc();
let body = Html(post.body_html.clone());
Response::builder().html(|o| templates::gallerypost_html(o, post, body))
}
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;
diff --git a/src/handlers/talks.rs b/src/handlers/talks.rs
index b64575c..8db5c9e 100644
--- a/src/handlers/talks.rs
+++ b/src/handlers/talks.rs
@@ -5,15 +5,17 @@ use crate::{
templates::{self, Html, RenderRucte},
};
use lazy_static::lazy_static;
-use prometheus::{IntCounterVec, register_int_counter_vec, opts};
+use prometheus::{opts, register_int_counter_vec, IntCounterVec};
use std::sync::Arc;
-use warp::{http::Response, Rejection, Reply};
use tracing::instrument;
+use warp::{http::Response, Rejection, Reply};
lazy_static! {
- static ref HIT_COUNTER: IntCounterVec =
- register_int_counter_vec!(opts!("talks_hits", "Number of hits to talks images"), &["name"])
- .unwrap();
+ static ref HIT_COUNTER: IntCounterVec = register_int_counter_vec!(
+ opts!("talks_hits", "Number of hits to talks images"),
+ &["name"]
+ )
+ .unwrap();
}
#[instrument(skip(state))]
@@ -35,7 +37,9 @@ pub async fn post_view(name: String, state: Arc<State>) -> Result<impl Reply, Re
match want {
None => Err(PostNotFound("talks".into(), name).into()),
Some(post) => {
- HIT_COUNTER.with_label_values(&[name.clone().as_str()]).inc();
+ 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))
}