diff options
| author | lukeflo | 2024-10-07 16:15:49 +0200 |
|---|---|---|
| committer | lukeflo | 2024-10-12 22:41:38 +0200 |
| commit | c9e749f811b16f7ec352d2aa8773105af046fad8 (patch) | |
| tree | 812d5917d968226fb532aad5c6c2d2198d6a4c29 /src/backend | |
| parent | ff539341267df56d99d379066396f63fd7991bd6 (diff) | |
| download | bibiman-c9e749f811b16f7ec352d2aa8773105af046fad8.tar.gz bibiman-c9e749f811b16f7ec352d2aa8773105af046fad8.zip | |
add func for entry items, UI enhancement
- add functions to get url/doi and filepath
- get values for entry info from structs not by calling funcs again
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/bib.rs | 15 | ||||
| -rw-r--r-- | src/backend/search.rs | 29 |
2 files changed, 38 insertions, 6 deletions
diff --git a/src/backend/bib.rs b/src/backend/bib.rs index 957adb1..3e0e844 100644 --- a/src/backend/bib.rs +++ b/src/backend/bib.rs @@ -15,10 +15,10 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. ///// -use std::{fs, path::PathBuf}; - use biblatex::{self, Bibliography}; use biblatex::{ChunksExt, Type}; +use color_eyre::eyre::ErrReport; +use std::{fs, path::PathBuf}; // Set necessary fields // TODO: can surely be made more efficient/simpler @@ -128,6 +128,8 @@ pub struct BibiEntry { pub pubtype: String, pub keywords: String, pub citekey: String, + pub weblink: String, + pub filepath: String, } impl BibiEntry { @@ -139,6 +141,9 @@ impl BibiEntry { Self::get_pubtype(&citekey, &biblio), Self::get_keywords(&citekey, &biblio), citekey.to_string(), + Self::get_abstract(&citekey, &biblio), + Self::get_weblink(&citekey, &biblio), + Self::get_filepath(&citekey, &biblio), ] } @@ -265,13 +270,13 @@ impl BibiEntry { } } - pub fn get_filepath(citekey: &str, biblio: &Bibliography) -> PathBuf { + pub fn get_filepath(citekey: &str, biblio: &Bibliography) -> String { if let true = biblio.get(&citekey).unwrap().file().is_ok() { let file = biblio.get(&citekey).unwrap().file().unwrap(); - file.into() + file } else { let file = "".to_string(); - file.into() + file } } } diff --git a/src/backend/search.rs b/src/backend/search.rs index 7319acc..2c11355 100644 --- a/src/backend/search.rs +++ b/src/backend/search.rs @@ -26,7 +26,7 @@ impl Default for BibiSearch { impl BibiSearch { // Stringify inner Vec<String> by joining/concat fn convert_to_string(inner_vec: &Vec<String>) -> String { - inner_vec.join(" ") + inner_vec[0..6].join(" ") } // Return a filtered entry list @@ -89,3 +89,30 @@ impl BibiSearch { filtered_list } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_vector_join() { + let bibvec = vec![ + "Author".to_string(), + "Title".to_string(), + "1999".to_string(), + "article".to_string(), + "hello, bye".to_string(), + "author_1999".to_string(), + "An abstract with multiple sentences. Sometimes thats necessary".to_string(), + "www.bibiman.org".to_string(), + "/home/file/path.pdf".to_string(), + ]; + + let joined_vec = BibiSearch::convert_to_string(&bibvec); + + assert_eq!( + joined_vec, + "Author Title 1999 article hello, bye author_1999" + ) + } +} |
