fix: compatibility fix for some formerly imported corrupted metadata (#307)
* fix: compatibility fix for some formerly imported corrupted metadata * fix: use font family names of sys fonts
This commit is contained in:
@@ -77,7 +77,7 @@ async fn list_fonts() -> Result<Vec<String>, String> {
|
||||
let font_collection = font_enumeration::Collection::new().unwrap();
|
||||
let mut fonts = Vec::new();
|
||||
for font in font_collection.all() {
|
||||
fonts.push(font.font_name.clone());
|
||||
fonts.push(font.family_name.clone());
|
||||
}
|
||||
Ok(fonts)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { LiaCloudUploadAltSolid, LiaCloudDownloadAltSolid } from 'react-icons/li
|
||||
import { Book } from '@/types/book';
|
||||
import { useEnv } from '@/context/EnvContext';
|
||||
import { useResponsiveSize } from '@/hooks/useResponsiveSize';
|
||||
import { formatAuthors, formatTitle } from '@/utils/book';
|
||||
import ReadingProgress from './ReadingProgress';
|
||||
|
||||
interface BookItemProps {
|
||||
@@ -61,11 +62,13 @@ const BookItem: React.FC<BookItemProps> = ({
|
||||
)}
|
||||
>
|
||||
<div className='flex h-1/2 items-center justify-center'>
|
||||
<span className='line-clamp-3 text-lg'>{book.title}</span>
|
||||
<span className='line-clamp-3 text-lg'>{formatTitle(book.title)}</span>
|
||||
</div>
|
||||
<div className='h-1/6'></div>
|
||||
<div className='flex h-1/3 items-center justify-center'>
|
||||
<span className='text-neutral-content/50 line-clamp-1 text-base'>{book.author}</span>
|
||||
<span className='text-neutral-content/50 line-clamp-1 text-base'>
|
||||
{formatAuthors(book.author)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{(selectedBooks.includes(book.hash) || clickedBookHash === book.hash) && (
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Image from 'next/image';
|
||||
import { BooksGroup } from '@/types/book';
|
||||
import { formatAuthors, formatTitle } from '@/utils/book';
|
||||
import ReadingProgress from './ReadingProgress';
|
||||
|
||||
interface GroupItemProps {
|
||||
@@ -21,8 +22,10 @@ const GroupItem: React.FC<GroupItemProps> = ({ group }) => {
|
||||
/>
|
||||
</figure>
|
||||
<div className='card-body p-4'>
|
||||
<h3 className='card-title line-clamp-2 text-sm'>{book.title}</h3>
|
||||
<p className='text-neutral-content line-clamp-1 text-xs'>{book.author}</p>
|
||||
<h3 className='card-title line-clamp-2 text-sm'>{formatTitle(book.title)}</h3>
|
||||
<p className='text-neutral-content line-clamp-1 text-xs'>
|
||||
{formatAuthors(book.author)}
|
||||
</p>
|
||||
<ReadingProgress book={book} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -25,7 +25,7 @@ const FontDropdown: React.FC<DropdownProps> = ({
|
||||
const _ = useTranslation();
|
||||
const iconSize16 = useResponsiveSize(16);
|
||||
const defaultIconSize = useDefaultIconSize();
|
||||
const selectedOption = options.find((option) => option.option === selected)!;
|
||||
const selectedOption = options.find((option) => option.option === selected) || options[0]!;
|
||||
return (
|
||||
<div className='dropdown dropdown-top'>
|
||||
<button
|
||||
|
||||
@@ -30,7 +30,7 @@ const BookCard = ({ book }: { book: Book }) => {
|
||||
/>
|
||||
<div className='min-w-0 flex-1'>
|
||||
<h4 className='line-clamp-2 w-[90%] text-sm font-semibold'>{formatTitle(title)}</h4>
|
||||
<p className='text-neutral-content truncate text-xs'>{formatAuthors(undefined, author)}</p>
|
||||
<p className='text-neutral-content truncate text-xs'>{formatAuthors(author)}</p>
|
||||
</div>
|
||||
<button
|
||||
className='btn btn-ghost hover:bg-base-300 h-6 min-h-6 w-6 rounded-full p-0 transition-colors'
|
||||
|
||||
@@ -115,7 +115,7 @@ const BookDetailModal = ({ book, isOpen, onClose }: BookDetailModalProps) => {
|
||||
{formatTitle(book.title) || _('Untitled')}
|
||||
</p>
|
||||
<p className='text-neutral-content line-clamp-1'>
|
||||
{formatAuthors(bookMeta.language, book.author) || _('Unknown')}
|
||||
{formatAuthors(book.author, bookMeta.language) || _('Unknown')}
|
||||
</p>
|
||||
</div>
|
||||
{window.innerWidth >= 400 && (
|
||||
|
||||
@@ -156,7 +156,7 @@ export abstract class BaseAppService implements AppService {
|
||||
hash,
|
||||
format,
|
||||
title: formatTitle(loadedBook.metadata.title),
|
||||
author: formatAuthors(loadedBook.metadata.language, loadedBook.metadata.author),
|
||||
author: formatAuthors(loadedBook.metadata.author, loadedBook.metadata.language),
|
||||
createdAt: existingBook ? existingBook.createdAt : Date.now(),
|
||||
uploadedAt: existingBook ? existingBook.uploadedAt : null,
|
||||
downloadedAt: Date.now(),
|
||||
|
||||
@@ -64,8 +64,8 @@ export const getBookLangCode = (lang: string | string[] | undefined) => {
|
||||
};
|
||||
|
||||
export const formatAuthors = (
|
||||
bookLang: string | string[] | undefined,
|
||||
contributors: string | Contributor | [string | Contributor],
|
||||
bookLang?: string | string[],
|
||||
) => {
|
||||
const langCode = getBookLangCode(bookLang);
|
||||
return Array.isArray(contributors)
|
||||
|
||||
@@ -17,7 +17,7 @@ export const getSysFontsList = async (): Promise<string[]> => {
|
||||
const osPlatform = getOSPlatform();
|
||||
if (FONT_ENUM_SUPPORTED_OS_PLATFORMS.includes(osPlatform)) {
|
||||
const fonts = await invoke<string[]>('list_fonts');
|
||||
cachedSysFonts = fonts.filter((font) => !isSymbolicFontName(font)).sort();
|
||||
cachedSysFonts = [...new Set(fonts.filter((font) => !isSymbolicFontName(font)))].sort();
|
||||
console.log('Fetched font list:', cachedSysFonts);
|
||||
return cachedSysFonts;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user