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;
|
|
|
|
}
|
|
|
|
---
|
|
|
|
<SectionContainer>
|
2023-12-29 16:59:13 +01:00
|
|
|
<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">2023 - Currently Reading:</h2>
|
2023-12-28 21:59:58 +01:00
|
|
|
<p>📖 The Summit Of The Gods: Vol.1</p>
|
2023-12-09 23:48:53 +01:00
|
|
|
{sortedYears.map(year => (
|
|
|
|
<section>
|
2023-12-28 21:59:58 +01:00
|
|
|
<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>
|
|
|
|
{
|
2023-12-28 21:59:58 +01:00
|
|
|
booksByYear[year].map((book) => (
|
2023-12-09 23:48:53 +01:00
|
|
|
<div class="flex justify-between mb-2 break-words gap-2 borderbottom">
|
2023-12-29 17:04:56 +01:00
|
|
|
<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>
|