diff --git a/Cargo.lock b/Cargo.lock index f460700..f3e9f08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -982,7 +982,7 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "mdpreview" -version = "0.4.1" +version = "0.4.2" dependencies = [ "askama", "askama_axum", diff --git a/Cargo.toml b/Cargo.toml index 4e20698..d6be546 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mdpreview" -version = "0.4.1" +version = "0.4.2" edition = "2024" authors = ["Vladislav Kan "] diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..52b5624 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "stable" +components = ["clippy", "rustfmt", "chef"] diff --git a/src/main.rs b/src/main.rs index 5e6023d..a7453a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,10 @@ use askama::Template; use axum::{ Router, extract::{Path as AxumPath, State}, - http::{HeaderMap, StatusCode, header}, + http::{ + HeaderMap, StatusCode, + header::{self}, + }, response::{IntoResponse, Redirect, Sse}, routing::get, }; @@ -47,6 +50,9 @@ pub struct FileEntry { pub struct DirectoryTemplate { pub title_path: String, pub files: Vec, + pub package_name: String, + pub authors: String, + pub version: String, } #[derive(Template)] @@ -57,8 +63,15 @@ pub struct NoteTemplate { pub content: String, pub sse_url: String, pub copy_path: String, + pub package_name: String, + pub authors: String, + pub version: String, } +const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME"); +const AUTHORS: &str = env!("CARGO_PKG_AUTHORS"); +const VERSION: &str = env!("CARGO_PKG_VERSION"); + #[derive(clap::Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { @@ -232,6 +245,9 @@ async fn render_single_file( content: html_content, sse_url, copy_path, + package_name: PACKAGE_NAME.to_string(), + authors: AUTHORS.to_string(), + version: VERSION.to_string(), }) } @@ -338,6 +354,9 @@ async fn serve_file( content: html_content, sse_url, copy_path, + package_name: PACKAGE_NAME.to_string(), + authors: AUTHORS.to_string(), + version: VERSION.to_string(), }; Ok(template.into_response()) @@ -388,7 +407,17 @@ async fn render_directory_index( let title_path = request_path.trim_start_matches('/').to_string(); - Ok(DirectoryTemplate { title_path, files }) + let package_name = env!("CARGO_PKG_NAME").to_string(); + let authors = env!("CARGO_PKG_AUTHORS").to_string(); + let version = env!("CARGO_PKG_VERSION").to_string(); + + Ok(DirectoryTemplate { + title_path, + files, + package_name, + authors, + version, + }) } async fn sse_handler( diff --git a/templates/base.html b/templates/base.html index 60ba7ed..6c43937 100644 --- a/templates/base.html +++ b/templates/base.html @@ -165,6 +165,9 @@