From 47e8c744197f4afc05394390ecaf00f7864b1f84 Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Mon, 6 May 2024 20:54:58 +0200 Subject: [PATCH] add series and author links to books --- calibre-db/src/data/author.rs | 2 +- rusty-library/src/data/book.rs | 16 +++++++++------- rusty-library/static/style.css | 1 + rusty-library/templates/book_card.html | 11 ++++++++++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/calibre-db/src/data/author.rs b/calibre-db/src/data/author.rs index 4b5d631..2ecf9e5 100644 --- a/calibre-db/src/data/author.rs +++ b/calibre-db/src/data/author.rs @@ -6,7 +6,7 @@ use super::{ pagination::{Pagination, SortOrder}, }; -#[derive(Debug, Serialize)] +#[derive(Debug, Clone, Serialize)] pub struct Author { pub id: u64, pub name: String, diff --git a/rusty-library/src/data/book.rs b/rusty-library/src/data/book.rs index bae8a8b..f2f47f0 100644 --- a/rusty-library/src/data/book.rs +++ b/rusty-library/src/data/book.rs @@ -1,6 +1,8 @@ use std::{collections::HashMap, path::Path}; -use calibre_db::data::{book::Book as DbBook, series::Series as DbSeries}; +use calibre_db::data::{ + author::Author as DbAuthor, book::Book as DbBook, series::Series as DbSeries, +}; use serde::Serialize; use crate::app_state::AppState; @@ -11,8 +13,8 @@ pub struct Book { pub title: String, pub sort: String, pub path: String, - pub author: String, - pub series: Option<(String, f64)>, + pub author: DbAuthor, + pub series: Option<(DbSeries, f64)>, pub formats: HashMap, } @@ -20,7 +22,7 @@ impl Book { pub fn from_db_book( db_book: &DbBook, db_series: Option<(DbSeries, f64)>, - author: &str, + author: DbAuthor, formats: HashMap, ) -> Self { Self { @@ -28,8 +30,8 @@ impl Book { title: db_book.title.clone(), sort: db_book.sort.clone(), path: db_book.path.clone(), - author: author.to_string(), - series: db_series.map(|x| (x.0.name, x.1)), + author: author.clone(), + series: db_series.map(|x| (x.0, x.1)), formats, } } @@ -58,6 +60,6 @@ impl Book { let formats = Book::formats(book, &state.config.library_path); let author = state.calibre.book_author(book.id).ok()?; let series = state.calibre.book_series(book.id).ok()?; - Some(Book::from_db_book(book, series, &author.name, formats)) + Some(Book::from_db_book(book, series, author, formats)) } } diff --git a/rusty-library/static/style.css b/rusty-library/static/style.css index f60713c..e0e813b 100644 --- a/rusty-library/static/style.css +++ b/rusty-library/static/style.css @@ -37,4 +37,5 @@ nav ul li { .grid-item { text-align: center; + height: 6rem; } diff --git a/rusty-library/templates/book_card.html b/rusty-library/templates/book_card.html index f9148b3..318fb93 100644 --- a/rusty-library/templates/book_card.html +++ b/rusty-library/templates/book_card.html @@ -2,7 +2,16 @@
{{ book.title }}
-

{{ book.author }}

+

+ {{ book.author.name }} +

+ {% if book.series %} +

+ + {{ book.series.0.name }} ({{ book.series.1 }}) + +

+ {% endif %}
book cover