diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index c956fdf6..73b1b78e 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -11,21 +11,24 @@ interface BookData {
}
// Component for the home page
-function HomePage({ books, formatBookName }: { books: string[], formatBookName: (name: string) => string }) {
+function HomePage({ books, formatBookName, getBookUrlName }: { books: string[], formatBookName: (name: string) => string, getBookUrlName: (name: string) => string }) {
const navigate = useNavigate();
const handleBookSelect = (book: string) => {
- navigate(`/book/${book}`);
+ const urlName = getBookUrlName(book);
+ navigate(`/book/${urlName}`);
};
return ;
}
// Component for book chapters page
-function BookPage({ books, formatBookName }: { books: string[], formatBookName: (name: string) => string }) {
+function BookPage({ books, formatBookName, getBookFromUrl }: { books: string[], formatBookName: (name: string) => string, getBookFromUrl: (urlName: string) => string }) {
const { bookName } = useParams<{ bookName: string }>();
const navigate = useNavigate();
+ const actualBookName = bookName ? getBookFromUrl(bookName) : '';
+
const handleChapterSelect = (chapter: string) => {
navigate(`/book/${bookName}/chapter/${chapter}`);
};
@@ -34,13 +37,13 @@ function BookPage({ books, formatBookName }: { books: string[], formatBookName:
navigate('/');
};
- if (!bookName || !books.includes(bookName)) {
+ if (!bookName || !actualBookName || !books.includes(actualBookName)) {
return
Book not found
;
}
return (
string }) {
+function ChapterPage({ formatBookName, getBookFromUrl }: { formatBookName: (name: string) => string, getBookFromUrl: (urlName: string) => string }) {
const { bookName, chapterNumber } = useParams<{ bookName: string, chapterNumber: string }>();
const navigate = useNavigate();
+ const actualBookName = bookName ? getBookFromUrl(bookName) : '';
+
const handleBack = () => {
navigate(`/book/${bookName}`);
};
- if (!bookName || !chapterNumber) {
+ if (!bookName || !chapterNumber || !actualBookName) {
return Chapter not found
;
}
return (
{
+ // Find the book that matches the display name
+ const book = books.find(b => formatBookName(b) === displayName);
+ return book || displayName;
+ };
+
+ // Helper function to convert book file name to URL-safe name
+ const getBookUrlName = (bookName: string): string => {
+ // Remove leading numbers and convert spaces to underscores for URL
+ return bookName.replace(/^\d+_/, '').replace(/ /g, '_');
+ };
+
+ // Helper function to convert URL name back to file name
+ const getBookFromUrl = (urlName: string): string => {
+ // Convert URL name back to display name, then find the file name
+ const displayName = urlName.replace(/_/g, ' ');
+ return getBookFileName(displayName);
+ };
+
const loadBooks = async () => {
try {
console.log('Loading books from API...');
@@ -218,9 +243,9 @@ function App() {
{/* Main Content */}
- } />
- } />
- } />
+ } />
+ } />
+ } />