cargo fmt
This commit is contained in:
parent
eea0cc764d
commit
7e2ebc4efb
5 changed files with 61 additions and 34 deletions
|
@ -15,7 +15,10 @@ use lazy_static::lazy_static;
|
||||||
use prometheus::{opts, Encoder, IntCounterVec, TextEncoder};
|
use prometheus::{opts, Encoder, IntCounterVec, TextEncoder};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tower_http::services::ServeFile;
|
use tower_http::services::ServeFile;
|
||||||
use tracing::{instrument, log::{error, info}};
|
use tracing::{
|
||||||
|
instrument,
|
||||||
|
log::{error, info},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{AppState, WebsiteError};
|
use crate::{AppState, WebsiteError};
|
||||||
|
|
||||||
|
@ -62,13 +65,12 @@ pub async fn index(
|
||||||
error!("Failed rendering index: {}", e);
|
error!("Failed rendering index: {}", e);
|
||||||
WebsiteError::NotFound
|
WebsiteError::NotFound
|
||||||
})?;
|
})?;
|
||||||
Ok(
|
Ok((
|
||||||
(
|
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
[(header::LAST_MODIFIED, state.startup_time.to_rfc2822())],
|
[(header::LAST_MODIFIED, state.startup_time.to_rfc2822())],
|
||||||
Html(res)
|
Html(res),
|
||||||
).into_response()
|
|
||||||
)
|
)
|
||||||
|
.into_response())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn healthcheck() -> &'static str {
|
async fn healthcheck() -> &'static str {
|
||||||
|
|
|
@ -88,7 +88,10 @@ pub async fn index(
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
[(
|
[(
|
||||||
header::LAST_MODIFIED,
|
header::LAST_MODIFIED,
|
||||||
last_changed.map_or_else(|| chrono::offset::Utc::now().to_rfc2822(), |d| d.to_rfc2822()),
|
last_changed.map_or_else(
|
||||||
|
|| chrono::offset::Utc::now().to_rfc2822(),
|
||||||
|
|d| d.to_rfc2822(),
|
||||||
|
),
|
||||||
)],
|
)],
|
||||||
Html(res),
|
Html(res),
|
||||||
)
|
)
|
||||||
|
@ -120,7 +123,10 @@ pub async fn view(
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
[(
|
[(
|
||||||
header::LAST_MODIFIED,
|
header::LAST_MODIFIED,
|
||||||
last_changed.map_or_else(|| chrono::offset::Utc::now().to_rfc2822(), |d| d.to_rfc2822()),
|
last_changed.map_or_else(
|
||||||
|
|| chrono::offset::Utc::now().to_rfc2822(),
|
||||||
|
|d| d.to_rfc2822(),
|
||||||
|
),
|
||||||
)],
|
)],
|
||||||
Html(res),
|
Html(res),
|
||||||
)
|
)
|
||||||
|
@ -149,7 +155,10 @@ pub async fn feed(
|
||||||
(CONTENT_TYPE, "application/atom+xml"),
|
(CONTENT_TYPE, "application/atom+xml"),
|
||||||
(
|
(
|
||||||
header::LAST_MODIFIED,
|
header::LAST_MODIFIED,
|
||||||
&last_changed.map_or_else(|| chrono::offset::Utc::now().to_rfc2822(), |d| d.to_rfc2822()),
|
&last_changed.map_or_else(
|
||||||
|
|| chrono::offset::Utc::now().to_rfc2822(),
|
||||||
|
|d| d.to_rfc2822(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
crate::feed::render_atom_feed(&state)?,
|
crate::feed::render_atom_feed(&state)?,
|
||||||
|
|
|
@ -6,7 +6,10 @@ use axum::{
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use hyper::{header::{CONTENT_TYPE, self}, HeaderMap, StatusCode};
|
use hyper::{
|
||||||
|
header::{self, CONTENT_TYPE},
|
||||||
|
HeaderMap, StatusCode,
|
||||||
|
};
|
||||||
use serde_derive::Serialize;
|
use serde_derive::Serialize;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
|
@ -42,8 +45,9 @@ pub async fn index(State(state): State<Arc<AppState>>) -> Result<Response, Websi
|
||||||
Ok((
|
Ok((
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
[(header::LAST_MODIFIED, state.startup_time.to_rfc2822())],
|
[(header::LAST_MODIFIED, state.startup_time.to_rfc2822())],
|
||||||
Html(res)
|
Html(res),
|
||||||
).into_response())
|
)
|
||||||
|
.into_response())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(state))]
|
#[instrument(skip(state))]
|
||||||
|
@ -78,18 +82,18 @@ pub async fn view(
|
||||||
|
|
||||||
let res = state.tera.render("tag.html", &c)?;
|
let res = state.tera.render("tag.html", &c)?;
|
||||||
|
|
||||||
Ok(
|
Ok((
|
||||||
(
|
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
[
|
[(
|
||||||
(
|
|
||||||
header::LAST_MODIFIED,
|
header::LAST_MODIFIED,
|
||||||
&last_changed.map_or_else(|| chrono::offset::Utc::now().to_rfc2822(), |d| d.to_rfc2822()),
|
&last_changed.map_or_else(
|
||||||
)
|
|| chrono::offset::Utc::now().to_rfc2822(),
|
||||||
],
|
|d| d.to_rfc2822(),
|
||||||
Html(res)
|
),
|
||||||
).into_response()
|
)],
|
||||||
|
Html(res),
|
||||||
)
|
)
|
||||||
|
.into_response())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn feed(
|
pub async fn feed(
|
||||||
|
@ -117,11 +121,15 @@ pub async fn feed(
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
[(CONTENT_TYPE, "application/atom+xml"),
|
[
|
||||||
|
(CONTENT_TYPE, "application/atom+xml"),
|
||||||
(
|
(
|
||||||
header::LAST_MODIFIED,
|
header::LAST_MODIFIED,
|
||||||
&last_changed.map_or_else(|| chrono::offset::Utc::now().to_rfc2822(), |d| d.to_rfc2822()),
|
&last_changed.map_or_else(
|
||||||
)
|
|| chrono::offset::Utc::now().to_rfc2822(),
|
||||||
|
|d| d.to_rfc2822(),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
crate::feed::render_atom_tag_feed(tag, &state)?,
|
crate::feed::render_atom_tag_feed(tag, &state)?,
|
||||||
)
|
)
|
||||||
|
|
|
@ -91,7 +91,10 @@ fn make_span(request: &Request<Body>) -> Span {
|
||||||
.map(axum::extract::MatchedPath::as_str)
|
.map(axum::extract::MatchedPath::as_str)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let method = request.method().as_str();
|
let method = request.method().as_str();
|
||||||
let target = uri.path_and_query().map(axum::http::uri::PathAndQuery::as_str).unwrap_or_default();
|
let target = uri
|
||||||
|
.path_and_query()
|
||||||
|
.map(axum::http::uri::PathAndQuery::as_str)
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
let name = format!("{method} {route}");
|
let name = format!("{method} {route}");
|
||||||
|
|
||||||
|
|
13
src/post.rs
13
src/post.rs
|
@ -9,7 +9,10 @@ use regex::Regex;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
use tracing::{instrument, log::{debug, warn}};
|
use tracing::{
|
||||||
|
instrument,
|
||||||
|
log::{debug, warn},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{markdown, AppState, WebsiteError};
|
use crate::{markdown, AppState, WebsiteError};
|
||||||
|
|
||||||
|
@ -106,8 +109,7 @@ pub async fn load_post(slug: &str) -> color_eyre::eyre::Result<Post> {
|
||||||
let (tomlfm, content) = parse_frontmatter(content)?;
|
let (tomlfm, content) = parse_frontmatter(content)?;
|
||||||
let tomlfm = tomlfm.expect("Missing frontmatter");
|
let tomlfm = tomlfm.expect("Missing frontmatter");
|
||||||
|
|
||||||
let content = content
|
let content = content.map(|c| markdown::render_markdown_to_html(&c));
|
||||||
.map(|c| markdown::render_markdown_to_html(&c));
|
|
||||||
|
|
||||||
Ok(Post::new(
|
Ok(Post::new(
|
||||||
slug.to_string(),
|
slug.to_string(),
|
||||||
|
@ -143,7 +145,10 @@ pub async fn render_post(state: &AppState, post: &Post) -> Result<String, Websit
|
||||||
ctx.insert("page", &post);
|
ctx.insert("page", &post);
|
||||||
ctx.insert("base_url", &state.base_url);
|
ctx.insert("base_url", &state.base_url);
|
||||||
|
|
||||||
state.tera.render("post.html", &ctx).map_err(std::convert::Into::into)
|
state
|
||||||
|
.tera
|
||||||
|
.render("post.html", &ctx)
|
||||||
|
.map_err(std::convert::Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue