diff --git a/src/feed.rs b/src/feed.rs index 1f1a138..e111e12 100644 --- a/src/feed.rs +++ b/src/feed.rs @@ -1,12 +1,10 @@ -use serde::Serialize; +use color_eyre::Result; +use serde_derive::Serialize; use tera::Tera; use tracing::instrument; -use serde_derive::Serialize; -use color_eyre::Result; use crate::{post::Post, tag::Tag}; - #[derive(Serialize)] struct FeedContext<'a> { feed_url: &'a str, @@ -38,7 +36,7 @@ pub fn render_atom_tag_feed(tag: &Tag, posts: &[&Post], tera: &Tera) -> Result) -> Router> { "/posts/:slug/*path", tower_http::services::ServeDir::new("./").fallback(ServeFile::new("./404.html")), ) - .route_service("/static/*path", tower_http::services::ServeDir::new("./").fallback(ServeFile::new("./404.html"))) + .route_service( + "/static/*path", + tower_http::services::ServeDir::new("./").fallback(ServeFile::new("./404.html")), + ) .fallback_service(ServeFile::new("./404.html")) } diff --git a/src/handlers/posts.rs b/src/handlers/posts.rs index 7b88333..3b5ce9d 100644 --- a/src/handlers/posts.rs +++ b/src/handlers/posts.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use axum::{ extract::{Path, State}, - response::{Html, Redirect, IntoResponse}, + response::{Html, IntoResponse, Redirect}, routing::get, Router, }; @@ -82,21 +82,18 @@ pub async fn view( Ok(Html(res)) } -pub async fn feed( - State(state): State>, -) -> Result { - - let mut posts: Vec<&Post> = state - .posts - .values() - .filter(|p| p.is_published()) - .collect(); +pub async fn feed(State(state): State>) -> Result { + let mut posts: Vec<&Post> = state.posts.values().filter(|p| p.is_published()).collect(); posts.sort_by_key(|p| &p.date); posts.reverse(); posts.truncate(10); - Ok((StatusCode::OK, [(CONTENT_TYPE, "application/atom+xml")], crate::feed::render_atom_feed(&posts, &state.tera)?)) + Ok(( + StatusCode::OK, + [(CONTENT_TYPE, "application/atom+xml")], + crate::feed::render_atom_feed(&posts, &state.tera)?, + )) } #[instrument(skip(state))] diff --git a/src/handlers/tags.rs b/src/handlers/tags.rs index 49cceec..d72b6df 100644 --- a/src/handlers/tags.rs +++ b/src/handlers/tags.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use axum::{ extract::{Path, State}, - response::{Html, Redirect, IntoResponse}, + response::{Html, IntoResponse, Redirect}, routing::get, Router, }; @@ -83,7 +83,11 @@ pub async fn feed( posts.reverse(); posts.truncate(10); - Ok((StatusCode::OK, [(CONTENT_TYPE, "application/atom+xml")], crate::feed::render_atom_tag_feed(tag, &posts, &state.tera)?)) + Ok(( + StatusCode::OK, + [(CONTENT_TYPE, "application/atom+xml")], + crate::feed::render_atom_tag_feed(tag, &posts, &state.tera)?, + )) } #[instrument(skip(state))] diff --git a/src/main.rs b/src/main.rs index d41a4b4..a184671 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,10 +12,10 @@ use tower_http::{compression::CompressionLayer, cors::CorsLayer}; use tracing::{info_span, log::*, Span}; use tracing_subscriber::{prelude::*, EnvFilter}; +mod feed; mod handlers; mod post; mod tag; -mod feed; pub struct AppState { base_url: String, @@ -31,11 +31,18 @@ async fn main() -> Result<()> { info!("Starting server..."); - let base_url = option_env!("SITE_BASE_URL").unwrap_or("http://localhost:8180").to_string(); + let base_url = option_env!("SITE_BASE_URL") + .unwrap_or("http://localhost:8180") + .to_string(); let tera = Tera::new("templates/**/*")?; let posts = post::load_all().await?; let tags = tag::get_tags(posts.values()); - let state = Arc::new(AppState { base_url, tera, posts, tags }); + let state = Arc::new(AppState { + base_url, + tera, + posts, + tags, + }); let app = handlers::routes(&state) .layer(CorsLayer::permissive())