feat(footer): add package name, version and authors to footer

This commit is contained in:
thek4n 2026-03-28 20:40:01 +03:00
parent b990725af1
commit 3b0de79a17
5 changed files with 39 additions and 4 deletions

2
Cargo.lock generated
View File

@ -982,7 +982,7 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94"
[[package]] [[package]]
name = "mdpreview" name = "mdpreview"
version = "0.4.1" version = "0.4.2"
dependencies = [ dependencies = [
"askama", "askama",
"askama_axum", "askama_axum",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "mdpreview" name = "mdpreview"
version = "0.4.1" version = "0.4.2"
edition = "2024" edition = "2024"
authors = ["Vladislav Kan <thek4n@yandex.ru>"] authors = ["Vladislav Kan <thek4n@yandex.ru>"]

3
rust-toolchain.toml Normal file
View File

@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
components = ["clippy", "rustfmt", "chef"]

View File

@ -2,7 +2,10 @@ use askama::Template;
use axum::{ use axum::{
Router, Router,
extract::{Path as AxumPath, State}, extract::{Path as AxumPath, State},
http::{HeaderMap, StatusCode, header}, http::{
HeaderMap, StatusCode,
header::{self},
},
response::{IntoResponse, Redirect, Sse}, response::{IntoResponse, Redirect, Sse},
routing::get, routing::get,
}; };
@ -47,6 +50,9 @@ pub struct FileEntry {
pub struct DirectoryTemplate { pub struct DirectoryTemplate {
pub title_path: String, pub title_path: String,
pub files: Vec<FileEntry>, pub files: Vec<FileEntry>,
pub package_name: String,
pub authors: String,
pub version: String,
} }
#[derive(Template)] #[derive(Template)]
@ -57,8 +63,15 @@ pub struct NoteTemplate {
pub content: String, pub content: String,
pub sse_url: String, pub sse_url: String,
pub copy_path: 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)] #[derive(clap::Parser, Debug)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
struct Args { struct Args {
@ -232,6 +245,9 @@ async fn render_single_file(
content: html_content, content: html_content,
sse_url, sse_url,
copy_path, 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, content: html_content,
sse_url, sse_url,
copy_path, copy_path,
package_name: PACKAGE_NAME.to_string(),
authors: AUTHORS.to_string(),
version: VERSION.to_string(),
}; };
Ok(template.into_response()) Ok(template.into_response())
@ -388,7 +407,17 @@ async fn render_directory_index(
let title_path = request_path.trim_start_matches('/').to_string(); 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( async fn sse_handler(

View File

@ -165,6 +165,9 @@
<div class="footer"> <div class="footer">
<a href="/">← Main</a> <a href="/">← Main</a>
<a href="/random">🎲 Random note</a> <a href="/random">🎲 Random note</a>
{% block footer %}
<p>{{ package_name }} - {{ authors }} - v{{ version }}</p>
{% endblock %}
</div> </div>
</div> </div>