cargo fix & fmt
This commit is contained in:
parent
e0237555cd
commit
982a642d17
3 changed files with 26 additions and 29 deletions
|
@ -3,12 +3,9 @@ use std::sync::Arc;
|
||||||
use tracing::log::*;
|
use tracing::log::*;
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::Path,
|
|
||||||
response::{Html, IntoResponse, Response},
|
response::{Html, IntoResponse, Response},
|
||||||
http::{StatusCode, Uri},
|
|
||||||
Extension,
|
Extension,
|
||||||
};
|
};
|
||||||
use pulldown_cmark::{html, Options, Parser};
|
|
||||||
|
|
||||||
use crate::State;
|
use crate::State;
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use axum::{extract::Path, Extension, response::Html};
|
use axum::{extract::Path, response::Html, Extension};
|
||||||
use pulldown_cmark::{Options, Parser, html};
|
use pulldown_cmark::{html, Options, Parser};
|
||||||
use tracing::log::*;
|
use tracing::log::*;
|
||||||
|
|
||||||
use crate::{State, handlers::PageContext};
|
use super::{Error, Result};
|
||||||
use super::{Result, Error};
|
use crate::{handlers::PageContext, State};
|
||||||
|
|
||||||
pub async fn view(
|
pub async fn view(Path(slug): Path<String>, Extension(state): Extension<Arc<State>>) -> Result {
|
||||||
Path(slug): Path<String>,
|
|
||||||
Extension(state): Extension<Arc<State>>,
|
|
||||||
) -> Result {
|
|
||||||
let post = state
|
let post = state
|
||||||
.posts
|
.posts
|
||||||
.iter()
|
.iter()
|
||||||
|
|
39
src/main.rs
39
src/main.rs
|
@ -1,6 +1,11 @@
|
||||||
use std::{path::PathBuf, sync::Arc};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use axum::{routing::{get, get_service}, Extension, Router, handler::Handler, http::StatusCode};
|
use axum::{
|
||||||
|
handler::Handler,
|
||||||
|
http::StatusCode,
|
||||||
|
routing::{get, get_service},
|
||||||
|
Extension, Router,
|
||||||
|
};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
use serde_derive::Serialize;
|
use serde_derive::Serialize;
|
||||||
|
@ -32,18 +37,18 @@ async fn main() -> Result<()> {
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
let path = p.unwrap();
|
let path = p.unwrap();
|
||||||
|
|
||||||
let filename = path
|
let filename = path.file_name().unwrap().to_string_lossy();
|
||||||
.file_name()
|
|
||||||
.unwrap()
|
|
||||||
.to_string_lossy();
|
|
||||||
|
|
||||||
let (filename, _) = filename.rsplit_once('.')
|
let (filename, _) = filename.rsplit_once('.').unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let slug = if filename.eq_ignore_ascii_case("index") {
|
let slug = if filename.eq_ignore_ascii_case("index") {
|
||||||
path.parent().unwrap().file_name().unwrap().to_string_lossy().into_owned()
|
path.parent()
|
||||||
}
|
.unwrap()
|
||||||
else {
|
.file_name()
|
||||||
|
.unwrap()
|
||||||
|
.to_string_lossy()
|
||||||
|
.into_owned()
|
||||||
|
} else {
|
||||||
filename.to_owned()
|
filename.to_owned()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -64,9 +69,11 @@ async fn main() -> Result<()> {
|
||||||
.route("/", get(handlers::index))
|
.route("/", get(handlers::index))
|
||||||
.route("/posts/", get(handlers::posts::index))
|
.route("/posts/", get(handlers::posts::index))
|
||||||
.route("/posts/:slug/", get(handlers::posts::view))
|
.route("/posts/:slug/", get(handlers::posts::view))
|
||||||
.nest("/static", get_service(tower_http::services::ServeDir::new("./static")).handle_error(|e| async {
|
.nest(
|
||||||
(StatusCode::NOT_FOUND, "not found")
|
"/static",
|
||||||
}))
|
get_service(tower_http::services::ServeDir::new("./static"))
|
||||||
|
.handle_error(|_e| async { (StatusCode::NOT_FOUND, "not found") }),
|
||||||
|
)
|
||||||
.fallback((|| async { (StatusCode::NOT_FOUND, "not found") }).into_service())
|
.fallback((|| async { (StatusCode::NOT_FOUND, "not found") }).into_service())
|
||||||
.layer(middleware);
|
.layer(middleware);
|
||||||
|
|
||||||
|
@ -78,7 +85,3 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn healthcheck() -> &'static str {
|
|
||||||
"OK"
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue