From 4914007165935718d9c737ee677944a9168d40dd Mon Sep 17 00:00:00 2001 From: Volodymyr Patuta <6977238-fiplox@users.noreply.gitlab.com> Date: Thu, 11 Feb 2021 12:41:43 +0100 Subject: [PATCH] add header to a note with title, author and date --- src/rnote/notes.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/rnote/notes.rs b/src/rnote/notes.rs index 18bfe14..adbaee2 100644 --- a/src/rnote/notes.rs +++ b/src/rnote/notes.rs @@ -155,8 +155,18 @@ pub fn create(header: &str, category: &str) -> Result<()> { create_dir(category)?; is_duplicate(header, category)?; let mut f = fs::File::create(&file)?; + let username = env::var("USER").unwrap_or("".to_owned()); + let date = Utc::now().format("%d-%m-%Y"); + let note_header = format!( + r#"--- +title: {} +author: {} +date: {} +---"#, + header, username, date + ); f.set_permissions(fs::Permissions::from_mode(0o600))?; - f.write(format!("# {}\n", header).as_bytes())?; + f.write(format!("{}\n", note_header).as_bytes())?; Command::new(editor).arg(&file).status()?; Ok(()) }