1
0
Fork 0

cargo fmt

This commit is contained in:
Adrian Hedqvist 2023-07-29 12:12:46 +02:00
parent eea0cc764d
commit 7e2ebc4efb
5 changed files with 61 additions and 34 deletions

View file

@ -15,7 +15,10 @@ use lazy_static::lazy_static;
use prometheus::{opts, Encoder, IntCounterVec, TextEncoder};
use std::sync::Arc;
use tower_http::services::ServeFile;
use tracing::{instrument, log::{error, info}};
use tracing::{
instrument,
log::{error, info},
};
use crate::{AppState, WebsiteError};
@ -62,13 +65,12 @@ pub async fn index(
error!("Failed rendering index: {}", e);
WebsiteError::NotFound
})?;
Ok(
(
StatusCode::OK,
[(header::LAST_MODIFIED, state.startup_time.to_rfc2822())],
Html(res)
).into_response()
Ok((
StatusCode::OK,
[(header::LAST_MODIFIED, state.startup_time.to_rfc2822())],
Html(res),
)
.into_response())
}
async fn healthcheck() -> &'static str {

View file

@ -88,7 +88,10 @@ pub async fn index(
StatusCode::OK,
[(
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),
)
@ -120,7 +123,10 @@ pub async fn view(
StatusCode::OK,
[(
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),
)
@ -149,7 +155,10 @@ pub async fn feed(
(CONTENT_TYPE, "application/atom+xml"),
(
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)?,

View file

@ -6,7 +6,10 @@ use axum::{
routing::get,
Router,
};
use hyper::{header::{CONTENT_TYPE, self}, HeaderMap, StatusCode};
use hyper::{
header::{self, CONTENT_TYPE},
HeaderMap, StatusCode,
};
use serde_derive::Serialize;
use tracing::instrument;
@ -42,8 +45,9 @@ pub async fn index(State(state): State<Arc<AppState>>) -> Result<Response, Websi
Ok((
StatusCode::OK,
[(header::LAST_MODIFIED, state.startup_time.to_rfc2822())],
Html(res)
).into_response())
Html(res),
)
.into_response())
}
#[instrument(skip(state))]
@ -78,18 +82,18 @@ pub async fn view(
let res = state.tera.render("tag.html", &c)?;
Ok(
(
StatusCode::OK,
[
(
header::LAST_MODIFIED,
&last_changed.map_or_else(|| chrono::offset::Utc::now().to_rfc2822(), |d| d.to_rfc2822()),
)
],
Html(res)
).into_response()
Ok((
StatusCode::OK,
[(
header::LAST_MODIFIED,
&last_changed.map_or_else(
|| chrono::offset::Utc::now().to_rfc2822(),
|d| d.to_rfc2822(),
),
)],
Html(res),
)
.into_response())
}
pub async fn feed(
@ -117,11 +121,15 @@ pub async fn feed(
Ok((
StatusCode::OK,
[(CONTENT_TYPE, "application/atom+xml"),
(
header::LAST_MODIFIED,
&last_changed.map_or_else(|| chrono::offset::Utc::now().to_rfc2822(), |d| d.to_rfc2822()),
)
[
(CONTENT_TYPE, "application/atom+xml"),
(
header::LAST_MODIFIED,
&last_changed.map_or_else(
|| chrono::offset::Utc::now().to_rfc2822(),
|d| d.to_rfc2822(),
),
),
],
crate::feed::render_atom_tag_feed(tag, &state)?,
)

View file

@ -91,7 +91,10 @@ fn make_span(request: &Request<Body>) -> Span {
.map(axum::extract::MatchedPath::as_str)
.unwrap_or_default();
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}");

View file

@ -9,7 +9,10 @@ use regex::Regex;
use serde_derive::{Deserialize, Serialize};
use tokio::fs;
use tracing::{instrument, log::{debug, warn}};
use tracing::{
instrument,
log::{debug, warn},
};
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 = tomlfm.expect("Missing frontmatter");
let content = content
.map(|c| markdown::render_markdown_to_html(&c));
let content = content.map(|c| markdown::render_markdown_to_html(&c));
Ok(Post::new(
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("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)]