--- // src/pages/books.astro import SiteLayout from '../components/SiteLayout.astro'; import MediaCard from '../components/MediaCard.astro'; import '../styles/global.css'; const bookImports = import.meta.glob('../../content/books/*.md'); let allBooksAstro = []; // Use let to reassign after sorting for (const path in bookImports) { const bookModule = await bookImports[path](); allBooksAstro.push({ frontmatter: bookModule.frontmatter, url: bookModule.url || path.replace('../../content', '').replace('.md', ''), description: bookModule.frontmatter.description || bookModule.rawContent()?.substring(0, 100) + '...' || 'No description available.', // Ensure all necessary fields for filtering are directly accessible genre: bookModule.frontmatter.genre, rating: bookModule.frontmatter.rating, title: bookModule.frontmatter.title, // for sorting cover: bookModule.frontmatter.cover // for MediaCard }); } // Sort books by title alphabetically allBooksAstro.sort((a, b) => a.title.localeCompare(b.title)); const uniqueGenres = [...new Set(allBooksAstro.map(book => book.genre).filter(Boolean))].sort(); const ratings = [5, 4, 3, 2, 1]; const pageTitle = "My Books Collection"; const booksFoundCount = allBooksAstro.length; // Data to pass to Alpine.js const alpineData = { alpineBooks: allBooksAstro, uniqueGenres, ratings }; ---

{pageTitle}

{booksFoundCount > 0 && (

Displaying of {booksFoundCount} books.

)}
{booksFoundCount > 0 && (
)} {booksFoundCount > 0 ? (
) : (

No books found in your collection yet.

Try adding some markdown files to the content/books directory.

)}