From b58ea63bc1f983e5daf611ccaaf939961721de1d Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Wed, 28 Jun 2023 20:18:39 -0700 Subject: [PATCH] chore: refactor book data --- src/_data/books.js | 50 ++++++++++++++++----------------- src/_data/site.json | 4 +-- src/_includes/now-topper.liquid | 4 +-- src/_includes/now.liquid | 6 ++-- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/_data/books.js b/src/_data/books.js index 86d8f4c1..2daf15ef 100644 --- a/src/_data/books.js +++ b/src/_data/books.js @@ -1,29 +1,29 @@ -const { extract } = require('@extractus/feed-extractor') -const { AssetCache } = require('@11ty/eleventy-fetch') +const EleventyFetch = require('@11ty/eleventy-fetch') module.exports = async function () { - const url = 'https://oku.club/rss/collection/POaRa' - // noinspection JSCheckFunctionSignatures - const asset = new AssetCache('books_data') - if (asset.isCacheValid('1h')) return await asset.getCachedValue() - const res = await extract(url, { - getExtraEntryFields: (feedEntry) => { - return { - image: - feedEntry['oku:cover'] || - `https://cdn.coryd.dev/books/${feedEntry.title - .replace(/\s+/g, '-') - .replace(':', '') - .toLowerCase()}.jpg` || - 'https://cdn.coryd.dev/books/missing-book.jpg', - } - }, - }) - .catch((error) => { - console.log(error.message) + const OKU_URL = 'https://oku.club/api/collections/user/cory/reading' + const OPEN_LIBRARY_URL = 'https://openlibrary.org/search.json?title=' + const res = EleventyFetch(OKU_URL, { + duration: '1h', + type: 'json', + }).catch() + const data = await res + const books = [] + for (const book of data['books']) { + const res = await fetch(`${OPEN_LIBRARY_URL}${book.title.replace(/\s+/g, '+')}`) + .then((res) => res.json()) + .catch() + const data = await res + const coverId = data['docs'].find((b) => { + return b['author_name'][0] === book['authors'][0].name + })?.['cover_i'] + books.push({ + title: book.title, + url: `https://oku.club/book/${book.slug}`, + cover: coverId + ? `https://books.coryd.dev/b/id/${coverId}-L.jpg` + : `https://cdn.coryd.dev/books/${book.title.toLowerCase().replace(/\s+/g, '-')}.jpg`, }) - .catch() - const data = res.entries - await asset.save(data, 'json') - return data + } + return books } diff --git a/src/_data/site.json b/src/_data/site.json index d1d6155a..1e71d1c5 100644 --- a/src/_data/site.json +++ b/src/_data/site.json @@ -13,10 +13,8 @@ "instapaper": "https://www.instapaper.com/p/coryd", "letterboxd": "https://letterboxd.com/cdme", "letterboxd-host": "https://a.ltrbxd.com", - "oku-host": "https://oku.ams3.cdn.digitaloceanspaces.com", "trakt": "https://trakt.tv/users/cdransf", "oku": "https://oku.club/user/cory", "coffee": "https://www.buymeacoffee.com/cory", - "cdn-movies": "https://movies.coryd.dev", - "cdn-books": "https://books.coryd.dev" + "cdn-movies": "https://movies.coryd.dev" } diff --git a/src/_includes/now-topper.liquid b/src/_includes/now-topper.liquid index 4e830e9c..30015e12 100644 --- a/src/_includes/now-topper.liquid +++ b/src/_includes/now-topper.liquid @@ -6,8 +6,8 @@

I'm a software developer in Camarillo, California. I enjoy hanging out with my beautiful family and 4 rescue dogs, technology, automation, music, writing, reading and tv and movies.

-

- {{ status.emoji }} +

+ {{ status.emoji }} {{ status.content }}

diff --git a/src/_includes/now.liquid b/src/_includes/now.liquid index 0cff5267..f5b7e99e 100644 --- a/src/_includes/now.liquid +++ b/src/_includes/now.liquid @@ -119,13 +119,13 @@ layout: main
{% for book in books %} - -