From 924b4a2e07f16200a0d18684819876a694a1d8b0 Mon Sep 17 00:00:00 2001 From: Ninjani <48680156+Ninjani@users.noreply.github.com> Date: Sun, 25 Apr 2021 13:34:23 +0200 Subject: [PATCH 1/2] feat(search): add document title to search --- src/gooseberry/search.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/gooseberry/search.rs b/src/gooseberry/search.rs index e04ba1a..6d2bd91 100644 --- a/src/gooseberry/search.rs +++ b/src/gooseberry/search.rs @@ -105,16 +105,36 @@ impl Gooseberry { let (tx_item, rx_item): (SkimItemSender, SkimItemReceiver) = unbounded(); for annotation in &annotations { - let highlight = format!( - "{} | {} |{}| {}", - style(&utils::get_quotes(&annotation).join(" ").replace("\n", " ")), - annotation.text.replace("\n", " "), - style(&annotation.tags.join("|")).fg(dialoguer::console::Color::Red), + let mut title = String::from("Untitled document"); + if let Some(document) = &annotation.document { + if !document.title.is_empty() { + title = document.title[0].to_owned(); + } + } + let mut highlight = format!( + "{}", + style(title.replace("\n", " ")).fg(dialoguer::console::Color::Green) + ); + let quote = utils::get_quotes(&annotation).join(" ").replace("\n", " "); + if !quote.is_empty() { + highlight.push_str(&format!("| {}", quote)); + } + if !annotation.text.is_empty() { + highlight.push_str(&format!("| {}", annotation.text.replace("\n", " "))); + } + if !annotation.tags.is_empty() { + highlight.push_str(&format!( + "|{}", + style(&annotation.tags.join("|")).fg(dialoguer::console::Color::Red) + )); + } + highlight.push_str(&format!( + "| {}", style(&annotation.uri) .fg(dialoguer::console::Color::Cyan) .italic() .underlined() - ); + )); let _ = tx_item.send(Arc::new(SearchAnnotation { highlight, markdown: hbs.render( From b43b065c70352583dfd66085bb9044f5e42f66b1 Mon Sep 17 00:00:00 2001 From: Ninjani <48680156+Ninjani@users.noreply.github.com> Date: Sun, 25 Apr 2021 13:35:55 +0200 Subject: [PATCH 2/2] docs(CHANGELOG): add document title to search --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2840fe1..b0ffb5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Separate make and index commands, allow filtering annotations in both ( Issue [#90](https://github.com/out-of-cheese-error/gooseberry/issues/90)) - Better and more filtering options (Issue [#92](https://github.com/out-of-cheese-error/gooseberry/issues/92)) +- Search by document title (Issue [#93](https://github.com/out-of-cheese-error/gooseberry/issues/93)) ## [0.8.1] - 2021-03-14 ### Changed