From bb9c9a2a12fae743638bac91267206bd47af2607 Mon Sep 17 00:00:00 2001 From: Ninjani <48680156+Ninjani@users.noreply.github.com> Date: Wed, 14 Apr 2021 10:28:59 +0200 Subject: [PATCH 1/2] feat(hierarchy): nested tags create nested folders Closes #85 --- CHANGELOG.md | 4 ++++ src/gooseberry/knowledge_base.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb64d5e..f0a6943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased +### Added +- Nested tag support - "parent/child" tags used with the "Tag" hierarchy create nested folders. + ## [0.8.1] - 2021-03-14 ### Changed - Use local time instead of UTC for search (Issue [#77](https://github.com/out-of-cheese-error/gooseberry/issues/77)) diff --git a/src/gooseberry/knowledge_base.rs b/src/gooseberry/knowledge_base.rs index 846a65c..5eb2117 100644 --- a/src/gooseberry/knowledge_base.rs +++ b/src/gooseberry/knowledge_base.rs @@ -367,6 +367,10 @@ impl Gooseberry { .collect::, _>>()?, raw_annotations: inner_annotations, }; + // TODO: check if nested tags work on Windows + if let Some(prefix) = path.parent() { + fs::create_dir_all(prefix)?; + } fs::File::create(&path)? .write_all(hbs.render("page", &page_data)?.as_bytes())?; } else { From c0e91569935447b2e50e60afc2cd2e5941c5ad99 Mon Sep 17 00:00:00 2001 From: Ninjani <48680156+Ninjani@users.noreply.github.com> Date: Wed, 14 Apr 2021 10:53:16 +0200 Subject: [PATCH 2/2] feat(hierarchy): replace / with path separator --- src/gooseberry/knowledge_base.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gooseberry/knowledge_base.rs b/src/gooseberry/knowledge_base.rs index 5eb2117..6a186c5 100644 --- a/src/gooseberry/knowledge_base.rs +++ b/src/gooseberry/knowledge_base.rs @@ -206,6 +206,7 @@ impl Gooseberry { let mut order_to_annotations = HashMap::new(); match order { OrderBy::Tag => { + let path_separator = &std::path::MAIN_SEPARATOR.to_string(); for annotation in annotations { if annotation.annotation.tags.is_empty() { order_to_annotations @@ -214,8 +215,9 @@ impl Gooseberry { .push(annotation); } else { for tag in &annotation.annotation.tags { + let tag = tag.replace("/", path_separator); order_to_annotations - .entry(tag.to_owned()) + .entry(tag) .or_insert_with(Vec::new) .push(annotation.clone()); } @@ -368,6 +370,7 @@ impl Gooseberry { raw_annotations: inner_annotations, }; // TODO: check if nested tags work on Windows + // TODO: add tests for nested tags if let Some(prefix) = path.parent() { fs::create_dir_all(prefix)?; }