// Fetch books from Open Library API document.addEventListener('DOMContentLoaded', async function() { try { const response = await fetch('https://openlibrary.org/subjects/fiction.json?limit=8'); const data = await response.json(); displayBooks(data.works); } catch (error) { console.error('Error fetching books:', error); document.getElementById('featured-books').innerHTML = '
Could not load books. Please try again later.
'; } }); function displayBooks(books) { const container = document.getElementById('featured-books'); if (!books || books.length === 0) { container.innerHTML = '
No books found.
'; return; } container.innerHTML = books.map(book => `
${book.cover_id ? `${book.title}` : `

No cover available

` }

${book.title}

${book.authors ? book.authors.map(a => a.name).join(', ') : 'Unknown Author'}

${book.subject ? book.subject[0] : 'Fiction'} Details
`).join(''); feather.replace(); } // Mobile menu toggle (handled in navbar component)