feat(bookshelf): show one line of book description in list view of the bookshelf, closes #2955 (#2990)

This commit is contained in:
Huang Xin
2026-01-18 17:16:54 +01:00
committed by GitHub
parent fd299a61a7
commit f0722ec0fe
2 changed files with 14 additions and 2 deletions
@@ -14,7 +14,7 @@ import { useTranslation } from '@/hooks/useTranslation';
import { useResponsiveSize } from '@/hooks/useResponsiveSize';
import { LibraryCoverFitType, LibraryViewModeType } from '@/types/settings';
import { navigateToLogin } from '@/utils/nav';
import { formatAuthors } from '@/utils/book';
import { formatAuthors, formatDescription } from '@/utils/book';
import ReadingProgress from './ReadingProgress';
import BookCover from '@/components/BookCover';
@@ -91,7 +91,7 @@ const BookItem: React.FC<BookItemProps> = ({
className={clsx(
'flex w-full flex-col p-0',
mode === 'grid' && 'pt-2',
mode === 'list' && 'py-2',
mode === 'list' && 'gap-2 py-0',
)}
>
<div className={clsx('min-w-0 flex-1', mode === 'list' && 'flex flex-col gap-2')}>
@@ -110,6 +110,9 @@ const BookItem: React.FC<BookItemProps> = ({
</p>
)}
</div>
<h4 className='text-neutral-content line-clamp-1 text-sm'>
{formatDescription(book.metadata?.description)}
</h4>
<div
className={clsx('flex items-center', book.progress ? 'justify-between' : 'justify-end')}
style={{
+9
View File
@@ -133,6 +133,15 @@ export const formatTitle = (title: string | LanguageMap) => {
return typeof title === 'string' ? title : formatLanguageMap(title);
};
export const formatDescription = (description?: string | LanguageMap) => {
if (!description) return '';
const text = typeof description === 'string' ? description : formatLanguageMap(description);
return text
.replace(/<\/?[^>]+(>|$)/g, '')
.replace(/&#\d+;/g, '')
.trim();
};
export const formatPublisher = (publisher: string | LanguageMap) => {
return typeof publisher === 'string' ? publisher : formatLanguageMap(publisher);
};