♻️ refactor booklog

Signed-off-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
Sindre Kjelsrud 2024-06-02 11:50:21 +02:00
parent 98bc1ba1c9
commit 51095476d6
Signed by untrusted user who does not match committer: sidski
GPG key ID: D2BBDF3EDE6BA9A6
2 changed files with 332 additions and 289 deletions

View file

@ -1,7 +1,44 @@
[ {
"name": "Sid's Biblioteca",
"url": "https://kjelsrud.dev/",
"bio": "A collection of books I've read with some ratings aswell.",
"lists":[
{
"name": "Currently reading",
"url": "https://kjelsrud.dev/logs/books/",
"books":[
{
"title": "The Intelligent Investor (NO)",
"isbn": 9788271463823,
"author": "Benjamin Graham"
}
]
},
{
"name": "On the shelf",
"url": "https://kjelsrud.dev/logs/books/",
"books":[
{
"title": "Dune",
"isbn": 9780340960196,
"author": "Frank Herbert"
},
{
"title": "The Summit of The Gods: Vol.3 - Vol.5"
},
{
"title": "Star Wars: The Tales of Kenobi"
}
]
},
{
"name": "Read",
"url": "https://kjelsrud.dev/logs/books/",
"books":[
{ {
"isbn": "9788822651518",
"title": "One Piece: Vol.108", "title": "One Piece: Vol.108",
"isbn": 9788822651518,
"author": "Eiichiro Oda",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -9,12 +46,12 @@
"day": "19", "day": "19",
"string": "2024-05-19" "string": "2024-05-19"
}, },
"my_rating": 5, "rating": 5
"author": "Eiichiro Oda"
}, },
{ {
"isbn": "9781974749799",
"title": "One Piece: Vol.107", "title": "One Piece: Vol.107",
"isbn": 9781974749799,
"author": "Eiichiro Oda",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -22,12 +59,12 @@
"day": "19", "day": "19",
"string": "2024-05-19" "string": "2024-05-19"
}, },
"my_rating": 5, "rating": 5
"author": "Eiichiro Oda"
}, },
{ {
"isbn": "9781591161844",
"title": "One Piece: Vol.3", "title": "One Piece: Vol.3",
"isbn": 9781591161844,
"author": "Eiichiro Oda",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -35,12 +72,12 @@
"day": "12", "day": "12",
"string": "2024-05-12" "string": "2024-05-12"
}, },
"my_rating": 3, "rating": 3
"author": "Eiichiro Oda"
}, },
{ {
"isbn": "9788248932505",
"title": "Maskiner som tenker", "title": "Maskiner som tenker",
"isbn": 9788248932505,
"author": "Inga Strümke",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -48,12 +85,12 @@
"day": "11", "day": "11",
"string": "2024-05-11" "string": "2024-05-11"
}, },
"my_rating": 5, "rating": 5
"author": "Inga Strümke"
}, },
{ {
"isbn": "9781646090259",
"title": "Hi Score Girl 10", "title": "Hi Score Girl 10",
"isbn": 9781646090259,
"author": "Rensuke Oshikiri",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -61,12 +98,12 @@
"day": "10", "day": "10",
"string": "2024-05-10" "string": "2024-05-10"
}, },
"my_rating": 5, "rating": 5
"author": "Rensuke Oshikiri"
}, },
{ {
"isbn": "9781646090242",
"title": "Hi Score Girl 09", "title": "Hi Score Girl 09",
"isbn": 9781646090242,
"author": "Rensuke Oshikiri",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -74,12 +111,12 @@
"day": "10", "day": "10",
"string": "2024-05-10" "string": "2024-05-10"
}, },
"my_rating": 4, "rating": 4
"author": "Rensuke Oshikiri"
}, },
{ {
"isbn": "9781646090235",
"title": "Hi Score Girl 08", "title": "Hi Score Girl 08",
"isbn": 9781646090235,
"author": "Rensuke Oshikiri",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -87,12 +124,12 @@
"day": "10", "day": "10",
"string": "2024-05-10" "string": "2024-05-10"
}, },
"my_rating": 5, "rating": 5
"author": "Rensuke Oshikiri"
}, },
{ {
"isbn": "9781646090228",
"title": "Hi Score Girl 07", "title": "Hi Score Girl 07",
"isbn": 9781646090228,
"author": "Rensuke Oshikiri",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -100,12 +137,12 @@
"day": "10", "day": "10",
"string": "2024-05-10" "string": "2024-05-10"
}, },
"my_rating": 4, "rating": 4
"author": "Rensuke Oshikiri"
}, },
{ {
"isbn": "",
"title": "YOU HAVE TOO MUCH SHIT", "title": "YOU HAVE TOO MUCH SHIT",
"isbn": null,
"author": "Chris Thomas",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -113,12 +150,12 @@
"day": "07", "day": "07",
"string": "2024-05-07" "string": "2024-05-07"
}, },
"my_rating": 3, "rating": 3
"author": "Chris Thomas"
}, },
{ {
"isbn": "9781646090211",
"title": "Hi Score Girl 06", "title": "Hi Score Girl 06",
"isbn": 9781646090211,
"author": "Rensuke Oshikiri",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -126,12 +163,12 @@
"day": "06", "day": "06",
"string": "2024-05-06" "string": "2024-05-06"
}, },
"my_rating": 5, "rating": 5
"author": "Rensuke Oshikiri"
}, },
{ {
"isbn": "9781646090204",
"title": "Hi Score Girl 05", "title": "Hi Score Girl 05",
"isbn": 9781646090204,
"author": "Rensuke Oshikiri",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -139,12 +176,12 @@
"day": "06", "day": "06",
"string": "2024-05-06" "string": "2024-05-06"
}, },
"my_rating": 4, "rating": 4
"author": "Rensuke Oshikiri"
}, },
{ {
"isbn": "9781646090198",
"title": "Hi Score Girl 04", "title": "Hi Score Girl 04",
"isbn": 9781646090198,
"author": "Rensuke Oshikiri",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -152,12 +189,12 @@
"day": "29", "day": "29",
"string": "2024-04-29" "string": "2024-04-29"
}, },
"my_rating": 3, "rating": 3
"author": "Rensuke Oshikiri"
}, },
{ {
"isbn": "9781646090181",
"title": "Hi Score Girl 03", "title": "Hi Score Girl 03",
"isbn": 9781646090181,
"author": "Rensuke Oshikiri",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -165,12 +202,12 @@
"day": "29", "day": "29",
"string": "2024-04-29" "string": "2024-04-29"
}, },
"my_rating": 4, "rating": 4
"author": "Rensuke Oshikiri"
}, },
{ {
"isbn": "9781646090174",
"title": "Hi Score Girl 02", "title": "Hi Score Girl 02",
"isbn": 9781646090174,
"author": "Rensuke Oshikiri",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -178,12 +215,12 @@
"day": "08", "day": "08",
"string": "2024-04-08" "string": "2024-04-08"
}, },
"my_rating": 4, "rating": 4
"author": "Rensuke Oshikiri"
}, },
{ {
"isbn": "9781646090167",
"title": "Hi Score Girl 01", "title": "Hi Score Girl 01",
"isbn": 9781646090167,
"author": "Rensuke Oshikiri",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -191,12 +228,12 @@
"day": "08", "day": "08",
"string": "2024-04-08" "string": "2024-04-08"
}, },
"my_rating": 4, "rating": 4
"author": "Rensuke Oshikiri"
}, },
{ {
"isbn": "9781421550794",
"title": "Neon Genesis Evangelion: Vol. 1", "title": "Neon Genesis Evangelion: Vol. 1",
"isbn": 9781421550794,
"author": "Yoshiyuki Sadamoto",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -204,12 +241,12 @@
"day": "01", "day": "01",
"string": "2024-04-01" "string": "2024-04-01"
}, },
"my_rating": 4, "rating": 4
"author": "Yoshiyuki Sadamoto"
}, },
{ {
"isbn": "9781784706289",
"title": "Invisible Women: Exposing Data Bias in a World Designed for Men", "title": "Invisible Women: Exposing Data Bias in a World Designed for Men",
"isbn": 9781784706289,
"author": "Caroline Criado Perez",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -217,12 +254,12 @@
"day": "18", "day": "18",
"string": "2024-03-18" "string": "2024-03-18"
}, },
"my_rating": 5, "rating": 5
"author": "Caroline Criado Perez"
}, },
{ {
"isbn": "9780575078697",
"title": "One Piece: Vol.2", "title": "One Piece: Vol.2",
"isbn": 9780575078697,
"author": "Eiichiro Oda",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -230,12 +267,12 @@
"day": "08", "day": "08",
"string": "2024-03-08" "string": "2024-03-08"
}, },
"my_rating": 4, "rating": 4
"author": "Eiichiro Oda"
}, },
{ {
"isbn": "9781569319017",
"title": "One Piece: Vol.1", "title": "One Piece: Vol.1",
"isbn": 9781569319017,
"author": "Eiichiro Oda",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -243,12 +280,12 @@
"day": "06", "day": "06",
"string": "2024-03-06" "string": "2024-03-06"
}, },
"my_rating": 5, "rating": 5
"author": "Eiichiro Oda"
}, },
{ {
"isbn": "9781529035667",
"title": "Permanent Record", "title": "Permanent Record",
"isbn": 9781529035667,
"author": "Edward Snowden",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -256,12 +293,12 @@
"day": "19", "day": "19",
"string": "2024-02-19" "string": "2024-02-19"
}, },
"my_rating": 5, "rating": 5
"author": "Edward Snowden"
}, },
{ {
"isbn": "9788492444328",
"title": "The Summit of the Gods: Vol.2", "title": "The Summit of the Gods: Vol.2",
"isbn": 9788492444328,
"author": "Jiro Taniguchi, Yumemakura Baku",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -269,12 +306,12 @@
"day": "23", "day": "23",
"string": "2024-01-23" "string": "2024-01-23"
}, },
"my_rating": 4, "rating": 4
"author": "Jiro Taniguchi, Yumemakura Baku"
}, },
{ {
"isbn": "9781803362328",
"title": "Multiverses: An anthology of alternate realities", "title": "Multiverses: An anthology of alternate realities",
"isbn": 9781803362328,
"author": "Preston Grassmann, Alix Harrow, Ken Liu, Alastair Reynolds, Clive Barker",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -282,12 +319,12 @@
"day": "22", "day": "22",
"string": "2024-01-22" "string": "2024-01-22"
}, },
"my_rating": 3, "rating": 3
"author": "Preston Grassmann, Alix Harrow, Ken Liu, Alastair Reynolds, Clive Barker"
}, },
{ {
"isbn": "",
"title": "Lacero", "title": "Lacero",
"isbn": null,
"author": "Andy Weir",
"date": "date":
{ {
"year": "2024", "year": "2024",
@ -295,12 +332,12 @@
"day": "08", "day": "08",
"string": "2024-01-08" "string": "2024-01-08"
}, },
"my_rating": 5, "rating": 5
"author": "Andy Weir"
}, },
{ {
"isbn": "9788496427877",
"title": "The Summit of the Gods: Vol.1", "title": "The Summit of the Gods: Vol.1",
"isbn": 9788496427877,
"author": "Jiro Taniguchi, Yumemakura Baku",
"date": "date":
{ {
"year": "2023", "year": "2023",
@ -308,12 +345,12 @@
"day": "29", "day": "29",
"string": "2023-12-29" "string": "2023-12-29"
}, },
"my_rating": 5, "rating": 5
"author": "Jiro Taniguchi, Yumemakura Baku"
}, },
{ {
"isbn": "9788202662721",
"title": "A Promised Land", "title": "A Promised Land",
"isbn": 9788202662721,
"author": "Barack Obama",
"date": "date":
{ {
"year": "2023", "year": "2023",
@ -321,12 +358,12 @@
"day": "28", "day": "28",
"string": "2023-12-28" "string": "2023-12-28"
}, },
"my_rating": 3, "rating": 3
"author": "Barack Obama"
}, },
{ {
"isbn": "9781506727615",
"title": "Mob Psycho 100: Vol. 9", "title": "Mob Psycho 100: Vol. 9",
"isbn": 9781506727615,
"author": "ONE",
"date": "date":
{ {
"year": "2023", "year": "2023",
@ -334,12 +371,12 @@
"day": "12", "day": "12",
"string": "2023-12-12" "string": "2023-12-12"
}, },
"my_rating": 4, "rating": 4
"author": "ONE"
}, },
{ {
"isbn": "9781506727608",
"title": "Mob Psycho 100: Vol. 8", "title": "Mob Psycho 100: Vol. 8",
"isbn": 9781506727608,
"author": "ONE",
"date": "date":
{ {
"year": "2023", "year": "2023",
@ -347,12 +384,12 @@
"day": "30", "day": "30",
"string": "2023-11-30" "string": "2023-11-30"
}, },
"my_rating": 4, "rating": 4
"author": "ONE"
}, },
{ {
"isbn": "9780140455526",
"title": "The Art of War", "title": "The Art of War",
"isbn": 9780140455526,
"author": "Sun-tzu",
"date": "date":
{ {
"year": "2023", "year": "2023",
@ -360,12 +397,12 @@
"day": "12", "day": "12",
"string": "2023-07-12" "string": "2023-07-12"
}, },
"my_rating": 4, "rating": 4
"author": "Sun-tzu"
}, },
{ {
"isbn": "9781506727592",
"title": "Mob Psycho 100: Vol. 7", "title": "Mob Psycho 100: Vol. 7",
"isbn": 9781506727592,
"author": "ONE",
"date": "date":
{ {
"year": "2023", "year": "2023",
@ -373,12 +410,12 @@
"day": "16", "day": "16",
"string": "2023-06-16" "string": "2023-06-16"
}, },
"my_rating": 3, "rating": 3
"author": "ONE"
}, },
{ {
"isbn": "9781529392401",
"title": "Will Artificial Intelligence Outsmart Us?", "title": "Will Artificial Intelligence Outsmart Us?",
"isbn": 9781529392401,
"author": "Stephen Hawking",
"date": "date":
{ {
"year": "2023", "year": "2023",
@ -386,12 +423,12 @@
"day": "13", "day": "13",
"string": "2023-06-13" "string": "2023-06-13"
}, },
"my_rating": 3, "rating": 3
"author": "Stephen Hawking"
}, },
{ {
"isbn": "9788269259346",
"title": "Magnus", "title": "Magnus",
"isbn": 9788269259346,
"author": "Magnus Midtbø, Thor Gotaas",
"date": "date":
{ {
"year": "2023", "year": "2023",
@ -399,12 +436,12 @@
"day": "01", "day": "01",
"string": "2023-06-01" "string": "2023-06-01"
}, },
"my_rating": 5, "rating": 5
"author": "Magnus Midtbø, Thor Gotaas"
}, },
{ {
"isbn": "9788234713538",
"title": "Hjertet i to: Seks måneder med Karpe", "title": "Hjertet i to: Seks måneder med Karpe",
"isbn": 9788234713538,
"author": "Yohan Shanmugaratnam",
"date": "date":
{ {
"year": "2023", "year": "2023",
@ -412,12 +449,12 @@
"day": "28", "day": "28",
"string": "2023-05-28" "string": "2023-05-28"
}, },
"my_rating": 5, "rating": 5
"author": "Yohan Shanmugaratnam"
}, },
{ {
"isbn": "9781421578798",
"title": "JoJo's Bizarre Adventure: Phantom Blood Vol. 1", "title": "JoJo's Bizarre Adventure: Phantom Blood Vol. 1",
"isbn": 9781421578798,
"author": "Araki, Hirohiko",
"date": "date":
{ {
"year": "2023", "year": "2023",
@ -425,12 +462,12 @@
"day": "22", "day": "22",
"string": "2023-05-22" "string": "2023-05-22"
}, },
"my_rating": 3, "rating": 3
"author": "Araki, Hirohiko"
}, },
{ {
"isbn": "9788202410445",
"title": "Steve Jobs", "title": "Steve Jobs",
"isbn": 9788202410445,
"author": "Walter Isaacson",
"date": "date":
{ {
"year": "2023", "year": "2023",
@ -438,7 +475,9 @@
"day": "15", "day": "15",
"string": "2023-05-15" "string": "2023-05-15"
}, },
"my_rating": 4, "rating": 4
"author": "Walter Isaacson"
} }
] ]
}
]
}

View file

@ -1,8 +1,26 @@
--- ---
import SectionContainer from '../../components/SectionContainer.astro'; import SectionContainer from '../../components/SectionContainer.astro';
import books from '../../data/biblioteca.json' import biblioteca from '../../data/biblioteca.json'
const booksByYear = books.reduce((acc:any, book) => { let booksRead = [];
let booksShelf = [];
let booksReading = [];
biblioteca.lists.forEach(list => {
switch (list.name) {
case "Read":
booksRead = list.books;
break;
case "On the shelf":
booksShelf = list.books;
break;
case "Currently reading":
booksReading = list.books;
break;
}
});
const booksByYear = booksRead.reduce((acc, book) => {
const year = new Date(book.date.string).getFullYear(); const year = new Date(book.date.string).getFullYear();
if (!acc[year]) { if (!acc[year]) {
acc[year] = []; acc[year] = [];
@ -11,52 +29,38 @@ const booksByYear = books.reduce((acc:any, book) => {
return acc; return acc;
}, {}); }, {});
const sortedYears = Object.keys(booksByYear).sort((a:any, b:any) => b - a); const sortedYears = Object.keys(booksByYear).sort((a: any, b: any) => b - a);
/*
function getEmojiStars(rating:any) {
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();
--- ---
<SectionContainer> <SectionContainer>
<main class="flex flex-col gap-4 mt-4"> <main class="flex flex-col flex-1 gap-4 mt-4">
<h1 class="text-3xl font-extrabold">📚 ¿Dónde está la biblioteca?</h1> <h1 class="text-3xl font-extrabold">📚 ¿Dónde está la biblioteca?</h1>
<h2 class="text-xl font-semibold">on the shelf</h2> <h2 class="text-xl font-semibold">on the shelf</h2>
<ul class="flex flex-col text-s gap-2 text-l"> <ul class="flex flex-col text-s gap-2 text-l">
<li class="borderbottom">📚 Dune</li> {booksShelf.map((book) => (
<li class="borderbottom">📚 The Summit of The Gods: Vol.3 - Vol.5</li> <li class="borderbottom">📚 {book.title}</li>
<li class="borderbottom">📚 Star Wars: The Tales of Kenobi</li> ))}
</ul> </ul>
<h2 class="text-xl font-semibold">on the nightstand</h2> <h2 class="text-xl font-semibold">on the nightstand</h2>
<p class="borderbottom">📖 The Intelligent Investor (NO)</p>
{sortedYears.map(year => (
<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>
<ul> <ul>
{ {booksReading.map((book) => (
booksByYear[year].map((book) => ( <li class="borderbottom">📖 {book.title}</li>
))}
</ul>
{sortedYears.map(year => (
<details>
<summary class="text-xl font-semibold cursor-pointer">{year} <span class="text-xs">({booksByYear[year].length} entries)</span></summary>
<ul class="mt-2">
{booksByYear[year].map((book) => (
<div class="flex justify-between mb-2 break-words gap-2 borderbottom"> <div class="flex justify-between mb-2 break-words gap-2 borderbottom">
<p class="text-s">{book.title}</p> <p class="text-s">{book.title}</p>
<p>{getHeartEmoji(book.my_rating)}</p> <p>{book.rating === 5 ? "❤️" : ""}</p>
</div> </div>
)) ))}
}
</ul> </ul>
</section> </details>
)) ))}
}
</main> </main>
</SectionContainer> </SectionContainer>