aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorlukeflo2024-10-19 21:30:37 +0200
committerlukeflo2024-10-19 21:30:37 +0200
commit8beb373c4a587cdcea772f725f51c2ff2db7273d (patch)
tree184e429f9ccc95437d6b7fb74baeaafd9610ca88 /src/backend
parentb5538d8c8408f1afbcfecb2a3b0407c3ad53ebe5 (diff)
downloadbibiman-8beb373c4a587cdcea772f725f51c2ff2db7273d.tar.gz
bibiman-8beb373c4a587cdcea772f725f51c2ff2db7273d.zip
reinvent BibiData, start integrating yaml
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/bib.rs101
1 files changed, 75 insertions, 26 deletions
diff --git a/src/backend/bib.rs b/src/backend/bib.rs
index 1f5d05d..29ce22e 100644
--- a/src/backend/bib.rs
+++ b/src/backend/bib.rs
@@ -17,6 +17,7 @@
use biblatex::{self, Bibliography};
use biblatex::{ChunksExt, Type};
+use hayagriva::io::from_yaml_str;
use itertools::Itertools;
use std::{fs, path::PathBuf};
@@ -36,6 +37,20 @@ pub struct BibiMain {
pub bibliography: Bibliography, // parsed bibliography
pub citekeys: Vec<String>, // list of all citekeys
pub keyword_list: Vec<String>, // list of all available keywords
+ pub entry_list: Vec<BibiData>, // List of all entries
+}
+
+#[derive(Debug, Clone)]
+pub struct BibiData {
+ pub authors: String,
+ pub title: String,
+ pub year: String,
+ pub pubtype: String,
+ pub keywords: String,
+ pub citekey: String,
+ pub abstract_text: String,
+ pub doi_url: String,
+ pub filepath: String,
}
impl BibiMain {
@@ -47,6 +62,7 @@ impl BibiMain {
let bibliography = biblatex::Bibliography::parse(&bibfilestring).unwrap();
let citekeys = Self::get_citekeys(&bibliography);
let keyword_list = Self::collect_tag_list(&citekeys, &bibliography);
+ let entry_list = Self::create_entry_list(&citekeys, &bibliography, &bibfile_format);
Self {
bibfile,
bibfile_format,
@@ -54,6 +70,15 @@ impl BibiMain {
bibliography,
citekeys,
keyword_list,
+ entry_list,
+ }
+ }
+
+ fn parse_bibliography(format: &FileFormat, bibfilestring: &str) -> Bibliography {
+ if let FileFormat::BibLatex = format {
+ biblatex::Bibliography::parse(bibfilestring).unwrap()
+ } else if let FileFormat::Hayagriva = format {
+ from_yaml_str(&bibfilestring).unwrap()
}
}
@@ -70,6 +95,27 @@ impl BibiMain {
}
}
+ fn create_entry_list(
+ citekeys: &[String],
+ bibliography: &Bibliography,
+ format: &FileFormat,
+ ) -> Vec<BibiData> {
+ citekeys
+ .into_iter()
+ .map(|k| BibiData {
+ authors: Self::get_authors(&k, &bibliography, format),
+ title: Self::get_title(&k, &bibliography),
+ year: Self::get_year(&k, &bibliography),
+ pubtype: Self::get_pubtype(&k, &bibliography),
+ keywords: Self::get_keywords(&k, &bibliography),
+ citekey: k.to_owned(),
+ abstract_text: Self::get_abstract(&k, &bibliography),
+ doi_url: Self::get_weblink(&k, &bibliography),
+ filepath: Self::get_filepath(&k, &bibliography),
+ })
+ .collect()
+ }
+
// get list of citekeys from the given bibfile
// this list is the base for further operations on the bibentries
// since it is the entry point of the biblatex crate.
@@ -112,38 +158,41 @@ impl BibiMain {
keyword_list
}
- pub fn get_authors(citekey: &str, biblio: &Bibliography) -> String {
- if biblio.get(&citekey).unwrap().author().is_ok() {
- let authors = biblio.get(&citekey).unwrap().author().unwrap();
- if authors.len() > 1 {
- let all_authors = authors.iter().map(|a| &a.name).join(", ");
- all_authors
- } else if authors.len() == 1 {
- let authors = authors[0].name.to_string();
- authors
- } else {
- let editors_authors = format!("empty");
- editors_authors
- }
- } else {
- if !biblio.get(&citekey).unwrap().editors().unwrap().is_empty() {
- let editors = biblio.get(&citekey).unwrap().editors().unwrap();
- if editors[0].0.len() > 1 {
- // let editors = format!("{} (ed.) et al.", editors[0].0[0].name);
- let mut editors = editors[0].0.iter().map(|e| &e.name).join(", ");
- editors.push_str(" (ed.)");
- editors
- } else if editors[0].0.len() == 1 {
- let editors = format!("{} (ed.)", editors[0].0[0].name);
- editors
+ pub fn get_authors(citekey: &str, biblio: &Bibliography, format: &FileFormat) -> String {
+ if let FileFormat::BibLatex = format {
+ if biblio.get(&citekey).unwrap().author().is_ok() {
+ let authors = biblio.get(&citekey).unwrap().author().unwrap();
+ if authors.len() > 1 {
+ let all_authors = authors.iter().map(|a| &a.name).join(", ");
+ all_authors
+ } else if authors.len() == 1 {
+ let authors = authors[0].name.to_string();
+ authors
} else {
let editors_authors = format!("empty");
editors_authors
}
} else {
- let editors_authors = format!("empty");
- editors_authors
+ if !biblio.get(&citekey).unwrap().editors().unwrap().is_empty() {
+ let editors = biblio.get(&citekey).unwrap().editors().unwrap();
+ if editors[0].0.len() > 1 {
+ // let editors = format!("{} (ed.) et al.", editors[0].0[0].name);
+ let mut editors = editors[0].0.iter().map(|e| &e.name).join(", ");
+ editors.push_str(" (ed.)");
+ editors
+ } else if editors[0].0.len() == 1 {
+ let editors = format!("{} (ed.)", editors[0].0[0].name);
+ editors
+ } else {
+ let editors_authors = format!("empty");
+ editors_authors
+ }
+ } else {
+ let editors_authors = format!("empty");
+ editors_authors
+ }
}
+ } else if let FileFormat::Hayagriva = format {
}
}