kjelsrud.dev/src/pages/logs/books.astro

48 lines
1.5 KiB
Text
Raw Normal View History

2023-12-09 23:48:53 +01:00
---
import SectionContainer from '../../components/SectionContainer.astro';
import books from '../../data/biblioteca.json'
2023-12-10 01:14:17 +01:00
const booksByYear = books.reduce((acc:any, book) => {
2023-12-09 23:48:53 +01:00
const year = new Date(book.date.string).getFullYear();
if (!acc[year]) {
acc[year] = [];
}
acc[year].push(book);
return acc;
}, {});
2023-12-10 01:14:17 +01:00
const sortedYears = Object.keys(booksByYear).sort((a:any, b:any) => b - a);
2023-12-09 23:48:53 +01:00
2023-12-10 01:14:17 +01:00
function getEmojiStars(rating:any) {
2023-12-09 23:48:53 +01:00
let stars = '';
for (let i = 0; i < rating; i++) {
stars += '⭐';
}
return stars;
}
const today = new Date();
2023-12-09 23:48:53 +01:00
---
<SectionContainer>
<main class="flex flex-col gap-4 mt-4">
2023-12-09 23:48:53 +01:00
<h1 class="text-3xl font-extrabold">📚 ¿Dónde está la biblioteca?</h1>
<h2 class="text-xl font-semibold">{today.getFullYear()} - Currently Reading:</h2>
<p>📖 Permanent Record</p>
2023-12-09 23:48:53 +01:00
{sortedYears.map(year => (
<section>
<div class="flex items-center gap-2 text-xl font-semibold mb-2">{year} - Finished <p class="text-xs">({booksByYear[year].length} entries)</p></div>
2023-12-09 23:48:53 +01:00
<ul>
{
booksByYear[year].map((book) => (
2023-12-09 23:48:53 +01:00
<div class="flex justify-between mb-2 break-words gap-2 borderbottom">
<p class="text-s">{book.title}</p>
2023-12-09 23:48:53 +01:00
<p>{getEmojiStars(book.my_rating)}</p>
</div>
))
}
</ul>
</section>
))
}
</main>
</SectionContainer>