better
This commit is contained in:
@@ -4,3 +4,11 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
|
||||||
|
[llvm]
|
||||||
|
download-ci-llvm = true # download prebuilt LLVM instead of compiling it (saves a lot of time)
|
||||||
|
|
||||||
|
[rust]
|
||||||
|
debug = false
|
||||||
|
incremental = true
|
||||||
+20
-15
@@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::BTreeMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
@@ -22,8 +22,8 @@ impl NoteKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct Note {
|
struct Note {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
kind: NoteKind,
|
kind: NoteKind,
|
||||||
@@ -32,30 +32,34 @@ struct Note {
|
|||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct Vault {
|
struct Vault {
|
||||||
notes: Vec<Note>, // nodes
|
notes: Vec<Note>, // nodes
|
||||||
tags: HashMap<String, Vec<usize>>, // tag -> indices into `notes` (the edges)
|
tags: BTreeMap<String, Vec<usize>>, // tag -> indices into `notes` (the edges)
|
||||||
images: Vec<PathBuf>, // files found in ".images" folders
|
images: Vec<PathBuf>, // files found in ".images" folders
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scan_dir(root: &Path) -> io::Result<Vault> {
|
fn scan_dir(root: &Path) -> io::Result<Vault> {
|
||||||
let mut vault = Vault::default();
|
let mut vault = Vault::default();
|
||||||
walk(root, root, &mut vault)?;
|
walk(root, root, false, &mut vault)?;
|
||||||
Ok(vault)
|
Ok(vault)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn walk(root: &Path, dir: &Path, vault: &mut Vault) -> io::Result<()> {
|
fn walk(root: &Path, dir: &Path, in_images: bool, vault: &mut Vault) -> io::Result<()> {
|
||||||
let in_images = dir.file_name().and_then(|n| n.to_str()) == Some(".images");
|
let mut paths: Vec<PathBuf> = fs::read_dir(dir)?
|
||||||
|
.map(|e| e.map(|e| e.path()))
|
||||||
|
.collect::<io::Result<_>>()?;
|
||||||
|
paths.sort();
|
||||||
|
|
||||||
for entry in fs::read_dir(dir)? {
|
for path in paths {
|
||||||
let path = entry?.path();
|
let meta = fs::symlink_metadata(&path)?;
|
||||||
|
|
||||||
if path.is_dir() {
|
if meta.is_dir() {
|
||||||
// skip hidden folders, except ".images"
|
|
||||||
let name = path.file_name().and_then(|n| n.to_str()).unwrap_or("");
|
let name = path.file_name().and_then(|n| n.to_str()).unwrap_or("");
|
||||||
|
// skip hidden folders, except ".images"
|
||||||
if name.starts_with('.') && name != ".images" {
|
if name.starts_with('.') && name != ".images" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
walk(root, &path, vault)?;
|
// once inside ".images", stay "inside" for all nested folders
|
||||||
|
walk(root, &path, in_images || name == ".images", vault)?;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,9 +113,10 @@ fn main() -> io::Result<()> {
|
|||||||
for (tag, ids) in &vault.tags {
|
for (tag, ids) in &vault.tags {
|
||||||
println!("#{tag}");
|
println!("#{tag}");
|
||||||
for &i in ids {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user