fix(knowledge): restore classification colors and scroll-synced outline
This commit is contained in:
parent
3466b507c6
commit
71cece74b0
10 changed files with 404 additions and 38 deletions
|
|
@ -200,7 +200,14 @@ fn copy_import(src: &Path, dst: &Path, count: &mut usize) -> Result<(), String>
|
|||
continue;
|
||||
}
|
||||
if p.is_dir() {
|
||||
copy_import(&p, dst, count)?;
|
||||
let folder_name = clean_title(
|
||||
p.file_name()
|
||||
.and_then(|value| value.to_str())
|
||||
.unwrap_or("未命名分类"),
|
||||
)?;
|
||||
let child = dst.join(folder_name);
|
||||
fs::create_dir_all(&child).map_err(|e| e.to_string())?;
|
||||
copy_import(&p, &child, count)?;
|
||||
continue;
|
||||
}
|
||||
let ext = p
|
||||
|
|
@ -243,7 +250,12 @@ async fn import_knowledge_folder(app: AppHandle) -> Result<Option<MutationReceip
|
|||
};
|
||||
let src = folder.into_path().map_err(|e| e.to_string())?;
|
||||
let root = storage::knowledge_root(&app)?;
|
||||
let dst = root.join("docs").join("导入");
|
||||
let source_name = clean_title(
|
||||
src.file_name()
|
||||
.and_then(|value| value.to_str())
|
||||
.unwrap_or("外部知识库"),
|
||||
)?;
|
||||
let dst = root.join("docs").join("导入").join(source_name);
|
||||
fs::create_dir_all(&dst).map_err(|e| e.to_string())?;
|
||||
let mut count = 0;
|
||||
copy_import(&src, &dst, &mut count)?;
|
||||
|
|
@ -367,4 +379,27 @@ mod tests {
|
|||
fn title_sanitizes_paths() {
|
||||
assert_eq!(clean_title("a/b").unwrap(), "a-b")
|
||||
}
|
||||
#[test]
|
||||
fn folder_import_preserves_classification_tree() {
|
||||
let source = tempfile::tempdir().unwrap();
|
||||
let destination = tempfile::tempdir().unwrap();
|
||||
let category = source.path().join("产品架构");
|
||||
fs::create_dir_all(&category).unwrap();
|
||||
fs::write(category.join("决定.txt"), "分类内容").unwrap();
|
||||
let mut count = 0;
|
||||
copy_import(source.path(), destination.path(), &mut count).unwrap();
|
||||
assert_eq!(count, 1);
|
||||
let imported = fs::read_dir(destination.path().join("产品架构"))
|
||||
.unwrap()
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
assert_eq!(imported.len(), 1);
|
||||
assert_eq!(
|
||||
imported[0]
|
||||
.path()
|
||||
.extension()
|
||||
.and_then(|value| value.to_str()),
|
||||
Some("md")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue