add series and author links to books
This commit is contained in:
parent
ab937d0201
commit
47e8c74419
@ -6,7 +6,7 @@ use super::{
|
|||||||
pagination::{Pagination, SortOrder},
|
pagination::{Pagination, SortOrder},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct Author {
|
pub struct Author {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use std::{collections::HashMap, path::Path};
|
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 serde::Serialize;
|
||||||
|
|
||||||
use crate::app_state::AppState;
|
use crate::app_state::AppState;
|
||||||
@ -11,8 +13,8 @@ pub struct Book {
|
|||||||
pub title: String,
|
pub title: String,
|
||||||
pub sort: String,
|
pub sort: String,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub author: String,
|
pub author: DbAuthor,
|
||||||
pub series: Option<(String, f64)>,
|
pub series: Option<(DbSeries, f64)>,
|
||||||
pub formats: HashMap<String, String>,
|
pub formats: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,7 +22,7 @@ impl Book {
|
|||||||
pub fn from_db_book(
|
pub fn from_db_book(
|
||||||
db_book: &DbBook,
|
db_book: &DbBook,
|
||||||
db_series: Option<(DbSeries, f64)>,
|
db_series: Option<(DbSeries, f64)>,
|
||||||
author: &str,
|
author: DbAuthor,
|
||||||
formats: HashMap<String, String>,
|
formats: HashMap<String, String>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -28,8 +30,8 @@ impl Book {
|
|||||||
title: db_book.title.clone(),
|
title: db_book.title.clone(),
|
||||||
sort: db_book.sort.clone(),
|
sort: db_book.sort.clone(),
|
||||||
path: db_book.path.clone(),
|
path: db_book.path.clone(),
|
||||||
author: author.to_string(),
|
author: author.clone(),
|
||||||
series: db_series.map(|x| (x.0.name, x.1)),
|
series: db_series.map(|x| (x.0, x.1)),
|
||||||
formats,
|
formats,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,6 +60,6 @@ impl Book {
|
|||||||
let formats = Book::formats(book, &state.config.library_path);
|
let formats = Book::formats(book, &state.config.library_path);
|
||||||
let author = state.calibre.book_author(book.id).ok()?;
|
let author = state.calibre.book_author(book.id).ok()?;
|
||||||
let series = state.calibre.book_series(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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,4 +37,5 @@ nav ul li {
|
|||||||
|
|
||||||
.grid-item {
|
.grid-item {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
height: 6rem;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,16 @@
|
|||||||
<header class="grid-item">
|
<header class="grid-item">
|
||||||
<hgroup>
|
<hgroup>
|
||||||
<h5>{{ book.title }}</h5>
|
<h5>{{ book.title }}</h5>
|
||||||
<p>{{ book.author }}</p>
|
<p>
|
||||||
|
<a class="secondary" href="/authors/{{ book.author.id }}">{{ book.author.name }}</a>
|
||||||
|
</p>
|
||||||
|
{% if book.series %}
|
||||||
|
<p>
|
||||||
|
<small>
|
||||||
|
<a class="secondary" href="/series/{{ book.series.0.id }}">{{ book.series.0.name }} ({{ book.series.1 }})</a>
|
||||||
|
</small>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
</hgroup>
|
</hgroup>
|
||||||
</header>
|
</header>
|
||||||
<img class="cover" src="/cover/{{ book.id }}" alt="book cover">
|
<img class="cover" src="/cover/{{ book.id }}" alt="book cover">
|
||||||
|
Loading…
Reference in New Issue
Block a user