feat(random): flag --random to open browser on random note

This commit is contained in:
thek4n 2026-03-24 19:24:43 +03:00
parent e3dc697e42
commit 1bf0eec41f
4 changed files with 16 additions and 5 deletions

View File

@ -41,6 +41,6 @@ repos:
- id: check-todos # [NOGREP]
name: check-todos # [NOGREP]
language: system
entry: sh -c "! grep --color=always --binary-files=without-match --dereference-recursive --exclude-dir='notes' --exclude-dir='node_modules' --exclude-dir='.git' --exclude='.pre-commit-config.yaml' --exclude-dir='venv' 'TODO'" # [NOGREP]
entry: sh -c "! grep --color=always --binary-files=without-match --dereference-recursive --exclude-dir='notes' --exclude-dir='target' --exclude-dir='node_modules' --exclude-dir='.git' --exclude='.pre-commit-config.yaml' --exclude-dir='venv' 'TODO'" # [NOGREP]
pass_filenames: false
always_run: true

2
Cargo.lock generated
View File

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

View File

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

View File

@ -61,15 +61,23 @@ pub struct NoteTemplate {
#[derive(clap::Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Host to listen
#[arg(long, default_value_t = String::from("localhost"))]
host: String,
/// Port to listen
#[arg(short, long, default_value_t = 8080)]
port: u16,
#[arg(long)]
/// Open browser
#[arg(long, default_value_t = false)]
browser: bool,
/// Open browser on random note. Requires flag --broswer
#[arg(long, default_value_t = false, requires = "browser")]
random: bool,
/// Notes root
#[arg()]
root: PathBuf,
}
@ -131,7 +139,10 @@ async fn main() {
println!("Server started on http://{actual_addr}");
if args.browser {
let url = format!("http://{actual_addr}");
let mut url = format!("http://{actual_addr}");
if args.random {
url = format!("{url}/random")
}
let _ = webbrowser::open(url.as_str());
}