diff --git a/src-tauri/src/theme.rs b/src-tauri/src/theme.rs index fc5907ba..492d23c0 100644 --- a/src-tauri/src/theme.rs +++ b/src-tauri/src/theme.rs @@ -135,7 +135,11 @@ fn seed_dir_with_files(dir: &Path, files: &[(&str, &str)], log_msg: &str) { pub fn seed_default_themes(vault_path: &str) { seed_dir_with_files( &Path::new(vault_path).join("_themes"), - &[("default.json", DEFAULT_THEME), ("dark.json", DARK_THEME), ("minimal.json", MINIMAL_THEME)], + &[ + ("default.json", DEFAULT_THEME), + ("dark.json", DARK_THEME), + ("minimal.json", MINIMAL_THEME), + ], "Seeded _themes/ with built-in themes", ); } @@ -145,7 +149,11 @@ pub fn seed_default_themes(vault_path: &str) { pub fn seed_vault_themes(vault_path: &str) { seed_dir_with_files( &Path::new(vault_path).join("theme"), - &[("default.md", DEFAULT_VAULT_THEME), ("dark.md", DARK_VAULT_THEME), ("minimal.md", MINIMAL_VAULT_THEME)], + &[ + ("default.md", DEFAULT_VAULT_THEME), + ("dark.md", DARK_VAULT_THEME), + ("minimal.md", MINIMAL_VAULT_THEME), + ], "Seeded theme/ with built-in vault themes", ); } @@ -154,8 +162,7 @@ pub fn seed_vault_themes(vault_path: &str) { /// Returns the absolute path to the newly created theme note. pub fn create_vault_theme(vault_path: &str, name: Option<&str>) -> Result { let theme_dir = Path::new(vault_path).join("theme"); - fs::create_dir_all(&theme_dir) - .map_err(|e| format!("Failed to create theme directory: {e}"))?; + fs::create_dir_all(&theme_dir).map_err(|e| format!("Failed to create theme directory: {e}"))?; let display_name = name.unwrap_or("Untitled Theme"); let slug = slugify(display_name); @@ -163,8 +170,7 @@ pub fn create_vault_theme(vault_path: &str, name: Option<&str>) -> Result) -> Result String { name.chars() - .map(|c| if c.is_ascii_alphanumeric() { c.to_ascii_lowercase() } else { '-' }) + .map(|c| { + if c.is_ascii_alphanumeric() { + c.to_ascii_lowercase() + } else { + '-' + } + }) .collect::() .split('-') .filter(|s| !s.is_empty()) @@ -206,7 +218,9 @@ fn vault_theme_note_content(name: &str, vars: &[(&str, &str)]) -> String { } } fm.push_str("---\n\n"); - fm.push_str(&format!("# {name} Theme\n\nA custom {name} theme for Laputa.\n")); + fm.push_str(&format!( + "# {name} Theme\n\nA custom {name} theme for Laputa.\n" + )); fm } @@ -424,7 +438,10 @@ pub const DEFAULT_VAULT_THEME_VARS: [(&str, &str); 46] = [ ("accent-red-light", "#E03E3E14"), ("accent-yellow-light", "#F0B10014"), // Typography - ("font-family", "'Inter', -apple-system, BlinkMacSystemFont, sans-serif"), + ( + "font-family", + "'Inter', -apple-system, BlinkMacSystemFont, sans-serif", + ), ("font-size-base", "14px"), // Editor ("editor-font-size", "16"), diff --git a/src-tauri/src/vault/cache.rs b/src-tauri/src/vault/cache.rs index 3da79a38..e10bcf10 100644 --- a/src-tauri/src/vault/cache.rs +++ b/src-tauri/src/vault/cache.rs @@ -366,27 +366,65 @@ mod tests { let dir = TempDir::new().unwrap(); let vault = dir.path(); - std::process::Command::new("git").args(["init"]).current_dir(vault).output().unwrap(); - std::process::Command::new("git").args(["config", "user.email", "t@t.com"]).current_dir(vault).output().unwrap(); - std::process::Command::new("git").args(["config", "user.name", "T"]).current_dir(vault).output().unwrap(); + std::process::Command::new("git") + .args(["init"]) + .current_dir(vault) + .output() + .unwrap(); + std::process::Command::new("git") + .args(["config", "user.email", "t@t.com"]) + .current_dir(vault) + .output() + .unwrap(); + std::process::Command::new("git") + .args(["config", "user.name", "T"]) + .current_dir(vault) + .output() + .unwrap(); create_test_file(vault, "note.md", "# Note\n\nContent."); - std::process::Command::new("git").args(["add", "."]).current_dir(vault).output().unwrap(); - std::process::Command::new("git").args(["commit", "-m", "init"]).current_dir(vault).output().unwrap(); + std::process::Command::new("git") + .args(["add", "."]) + .current_dir(vault) + .output() + .unwrap(); + std::process::Command::new("git") + .args(["commit", "-m", "init"]) + .current_dir(vault) + .output() + .unwrap(); // Build initial cache let entries = scan_vault_cached(vault).unwrap(); assert_eq!(entries.len(), 1); // Add a new DIRECTORY with files (simulating seed_vault_themes) — NOT committed - create_test_file(vault, "theme/default.md", "---\nIs A: Theme\n---\n# Default Theme\n"); - create_test_file(vault, "theme/dark.md", "---\nIs A: Theme\n---\n# Dark Theme\n"); + create_test_file( + vault, + "theme/default.md", + "---\nIs A: Theme\n---\n# Default Theme\n", + ); + create_test_file( + vault, + "theme/dark.md", + "---\nIs A: Theme\n---\n# Dark Theme\n", + ); // Re-scan — should find the new untracked files inside the untracked directory let entries2 = scan_vault_cached(vault).unwrap(); - assert_eq!(entries2.len(), 3, "Should include theme files from untracked directory"); + assert_eq!( + entries2.len(), + 3, + "Should include theme files from untracked directory" + ); let titles: Vec<&str> = entries2.iter().map(|e| e.title.as_str()).collect(); - assert!(titles.contains(&"Default Theme"), "Should find default.md in untracked theme/ dir"); - assert!(titles.contains(&"Dark Theme"), "Should find dark.md in untracked theme/ dir"); + assert!( + titles.contains(&"Default Theme"), + "Should find default.md in untracked theme/ dir" + ); + assert!( + titles.contains(&"Dark Theme"), + "Should find dark.md in untracked theme/ dir" + ); } }