From 19d05cf16c13f37def514248e284651ec0ff76dc Mon Sep 17 00:00:00 2001 From: samantha Date: Sat, 24 Oct 2026 10:37:36 +0200 Subject: [PATCH] better --- Cargo.toml | 8 ++++++++ src/main.rs | 35 ++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 51cd6e9..4694712 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,11 @@ version = "0.1.0" edition = "2024" [dependencies] + + +[llvm] +download-ci-llvm = true # download prebuilt LLVM instead of compiling it (saves a lot of time) + +[rust] +debug = false +incremental = true \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 85caa18..3eb0ec2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::BTreeMap; use std::env; use std::fs; use std::io; @@ -22,8 +22,8 @@ impl NoteKind { } } - #[derive(Debug)] +#[allow(dead_code)] struct Note { path: PathBuf, kind: NoteKind, @@ -32,30 +32,34 @@ struct Note { #[derive(Debug, Default)] struct Vault { - notes: Vec, // nodes - tags: HashMap>, // tag -> indices into `notes` (the edges) - images: Vec, // files found in ".images" folders + notes: Vec, // nodes + tags: BTreeMap>, // tag -> indices into `notes` (the edges) + images: Vec, // files found in ".images" folders } fn scan_dir(root: &Path) -> io::Result { let mut vault = Vault::default(); - walk(root, root, &mut vault)?; + walk(root, root, false, &mut vault)?; Ok(vault) } -fn walk(root: &Path, dir: &Path, vault: &mut Vault) -> io::Result<()> { - let in_images = dir.file_name().and_then(|n| n.to_str()) == Some(".images"); +fn walk(root: &Path, dir: &Path, in_images: bool, vault: &mut Vault) -> io::Result<()> { + let mut paths: Vec = fs::read_dir(dir)? + .map(|e| e.map(|e| e.path())) + .collect::>()?; + paths.sort(); - for entry in fs::read_dir(dir)? { - let path = entry?.path(); + for path in paths { + let meta = fs::symlink_metadata(&path)?; - if path.is_dir() { - // skip hidden folders, except ".images" + if meta.is_dir() { let name = path.file_name().and_then(|n| n.to_str()).unwrap_or(""); + // skip hidden folders, except ".images" if name.starts_with('.') && name != ".images" { continue; } - walk(root, &path, vault)?; + // once inside ".images", stay "inside" for all nested folders + walk(root, &path, in_images || name == ".images", vault)?; continue; } @@ -109,9 +113,10 @@ fn main() -> io::Result<()> { for (tag, ids) in &vault.tags { println!("#{tag}"); for &i in ids { - println!(" {}", vault.notes[i].path.display()); + let note = &vault.notes[i]; + println!(" {} [{:?}]", note.path.display(), note.kind); } } - println!("{} notes, {} images", vault.notes.len(), vault.images.len()); + Ok(()) } \ No newline at end of file