diff --git a/src/main.rs b/src/main.rs index fc71132..dcb088d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use copy_dir::copy_dir; use std::fs::{create_dir_all, read_to_string, remove_file, write, File, OpenOptions}; -use std::io::{BufRead, BufReader, Read, Write}; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use std::process::Stdio; @@ -52,6 +52,7 @@ struct Config { #[derive(Debug, Default, Template)] #[template(path = "post.md")] struct PostTemplate { + title: String, date: String, date_title: String, messages: Vec, @@ -161,7 +162,7 @@ async fn main() -> Result<()> { let at = get_msg_attachments(&mut client, &v).await; if text.is_none() && at.is_none() { continue; - } else if sender != &config.allowed_sender { + } else if sender != config.allowed_sender { println!("{:?}", sender); send( &client, @@ -180,30 +181,39 @@ async fn main() -> Result<()> { if cmds.len() >= 2 && cmds[0] == "©" { match cmds[1] { "help" => { - let text = " -Available commands: - - post: Generate post for yesterday - - tz: change timezone -" + let text = "\nAvailable commands:\n - post: Generate post for yesterday\n - tz: change timezone\n" .to_string(); send(&client, sender, text).await?; } "post" => { - let res = generate_post(&config, &mut client).await; - if let Ok(res) = res { + if cmds.len() != 3 { send( &client, sender, - format!("Generated blog post at: {}/{}", config.url, res), + "Wrong number of arguments.\nExpected: 1(title)".to_string(), ) .await?; } else { - send( - &client, - sender, - format!("Error generating blog post:\n{:?}", res), - ) - .await?; + let res = generate_post(&config, &mut client).await; + if let Ok(res) = res { + send( + &client, + sender, + format!( + "Generated blog post at: {}/{}", + config.url, + res.replace("[+:.]", "-").to_lowercase() + ), + ) + .await?; + } else { + send( + &client, + sender, + format!("Error generating blog post:\n{:?}", res), + ) + .await?; + } } } "tz" => { @@ -214,14 +224,15 @@ Available commands: println!("{}", tz_data_path); let mut file = OpenOptions::new() .create(true) + .truncate(true) .write(true) .open(&tz_data_path)?; file.write_all(cmds[2].as_bytes())?; config.timezone = cmds[2].to_string(); - send(&client, sender, format!("Updated tz data")).await?; + send(&client, sender, "Updated tz data".to_string()).await?; } else { - send(&client, sender, format!("Error parsing")).await?; + send(&client, sender, "Error parsing".to_string()).await?; } } _ => { @@ -235,7 +246,7 @@ Available commands: .append(true) .create(true) .open(format!("{}/texts.json", config.data_folder))?; - writeln!(file, "{}", v.to_string())?; + writeln!(file, "{}", v)?; } } async fn send(client: &Client, sender: &str, msg: String) -> Result<()> { diff --git a/templates/post.md b/templates/post.md index 0d4c87c..c21b984 100644 --- a/templates/post.md +++ b/templates/post.md @@ -1,10 +1,10 @@ +++ -title = "Journal for {{ date_title }}" +title = "{{title}} ({{ date_title }})" date = {{ date }} draft = false [taxonomies] -tags = ["Signal to blog"] +tags = ["Signal to blog" "Journal"] +++ {% for msg in messages %}