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

63 lines
1.9 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;
}
*/
function getHeartEmoji(rating:any) {
let heart = '';
if (rating == 5) heart = "❤️";
return heart;
}
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">on the shelf</h2>
<ul class="flex flex-col text-s gap-2 text-l">
<li class="borderbottom">📚 Dune</li>
<li class="borderbottom">📚 The Summit of The Gods: Vol.3 - Vol.5</li>
<li class="borderbottom">📚 Star Wars: The Tales of Kenobi</li>
</ul>
<h2 class="text-xl font-semibold">on the nightstand</h2>
<p class="borderbottom">📖 The Intelligent Investor (NO)</p>
{sortedYears.map(year => (
2023-12-09 23:48:53 +01:00
<section>
<div class="flex items-center gap-2 text-xl font-semibold mb-2">{year}<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>
<p>{getHeartEmoji(book.my_rating)}</p>
2023-12-09 23:48:53 +01:00
</div>
))
}
</ul>
</section>
))
}
</main>
</SectionContainer>