pub fn synchronize_filename<T: Content>(
    path: &Path
) -> Result<PathBuf, NoteError>
Expand description

Open the note file path on disk and read its YAML front matter. Then calculate from the front matter how the filename should be to be in sync. If it is different, rename the note on disk. Returns the note’s new or existing filename. Repeated calls, will reload the environment variables, but not the configuration file. This function is stateless.

Example with TemplateKind::SyncFilename

use tpnote_lib::content::ContentString;
use tpnote_lib::workflow::synchronize_filename;
use std::env::temp_dir;
use std::fs;
use std::path::Path;

// Prepare test: create existing note.
let raw = r#"

---
title: "My day"
subtitle: "Note"
---
Body text
"#;
let notefile = temp_dir().join("20221030-hello.md");
fs::write(&notefile, raw.as_bytes()).unwrap();

let expected = temp_dir().join("20221030-My day--Note.md");
let _ = fs::remove_file(&expected);

// Start test.
// You can plug in your own type (must impl. `Content`).
let n = synchronize_filename::<ContentString>(&notefile).unwrap();

// Check result
assert_eq!(n, expected);
assert!(n.is_file());