Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hierarchy): nested tags create nested folders #87

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 8 additions & 1 deletion src/gooseberry/knowledge_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
Expand Down Expand Up @@ -367,6 +369,11 @@ impl Gooseberry {
.collect::<Result<Vec<String>, _>>()?,
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)?;
}
fs::File::create(&path)?
.write_all(hbs.render("page", &page_data)?.as_bytes())?;
} else {
Expand Down