feat: goodreads -> storygraph
This commit is contained in:
parent
ac504b2837
commit
bbb9f59e76
10 changed files with 470 additions and 81 deletions
|
@ -1,34 +1,45 @@
|
|||
const Parser = require('rss-parser')
|
||||
const jsdom = require('jsdom')
|
||||
const { AssetCache } = require('@11ty/eleventy-fetch')
|
||||
const { JSDOM } = jsdom
|
||||
|
||||
module.exports = async function () {
|
||||
const parser = new Parser({
|
||||
customFields: {
|
||||
item: ['book_large_image_url', 'isbn', 'book_description', 'user_date_added'],
|
||||
},
|
||||
})
|
||||
const url = process.env.SECRET_FEED_GOODREADS
|
||||
const url = 'https://app.thestorygraph.com/currently-reading/coryd'
|
||||
const asset = new AssetCache('books_data')
|
||||
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
|
||||
const data = []
|
||||
const res = await parser.parseURL(url).catch((error) => {
|
||||
console.log(error.message)
|
||||
})
|
||||
res.items.forEach((book) => {
|
||||
data.push({
|
||||
image: book['book_large_image_url'].replace(
|
||||
'https://i.gr-assets.com',
|
||||
'https://books.coryd.dev'
|
||||
),
|
||||
title: book['title'],
|
||||
url: book['link'],
|
||||
isbn: book['isbn'],
|
||||
description: `${book['book_description']}<br/><br/>`,
|
||||
dateAdded: book['user_date_added'],
|
||||
type: 'book',
|
||||
await fetch(url)
|
||||
.then((res) => res.text())
|
||||
.then((html) => {
|
||||
const DOM = new JSDOM(html)
|
||||
const doc = DOM.window.document
|
||||
doc
|
||||
.querySelectorAll('.md\\:block .book-title-author-and-series h3 > a')
|
||||
.forEach((title, index) => {
|
||||
if (!data[index]) data.push({ title: title.textContent })
|
||||
if (data[index]) data[index]['title'] = title.textContent
|
||||
})
|
||||
doc
|
||||
.querySelectorAll('.md\\:block .book-title-author-and-series h3 p:last-of-type > a')
|
||||
.forEach((author, index) => {
|
||||
if (!data[index]) data.push({ author: author.textContent })
|
||||
if (data[index]) data[index]['author'] = author.textContent
|
||||
})
|
||||
doc.querySelectorAll('.md\\:block .book-cover img').forEach((image, index) => {
|
||||
if (!data[index]) data.push({ image: image.src })
|
||||
if (data[index]) data[index]['image'] = image.src
|
||||
})
|
||||
doc.querySelectorAll('.md\\:block .book-cover a').forEach((url, index) => {
|
||||
if (!data[index]) data.push({ url: `https://app.thestorygraph.com${url.href}` })
|
||||
if (data[index]) data[index]['url'] = `https://app.thestorygraph.com${url.href}`
|
||||
})
|
||||
})
|
||||
const books = data
|
||||
.filter((book) => book.title)
|
||||
.map((book) => {
|
||||
book.type = 'book'
|
||||
book.dateAdded = new Date()
|
||||
return book
|
||||
})
|
||||
})
|
||||
const books = data.splice(0, 6)
|
||||
await asset.save(books, 'json')
|
||||
return books
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ module.exports = async function () {
|
|||
icon: 'device-airpods',
|
||||
},
|
||||
{ name: 'Trakt', url: 'https://trakt.tv/users/cdransf', icon: 'device-tv' },
|
||||
{ name: 'Goodreads', url: 'https://www.goodreads.com/cdransf', icon: 'books' },
|
||||
{ name: 'StoryGraph', url: 'https://app.thestorygraph.com/profile/coryd', icon: 'books' },
|
||||
{ name: 'Buy Me a Coffee', url: 'https://www.buymeacoffee.com/cory', icon: 'cup' },
|
||||
],
|
||||
resume: [
|
||||
|
|
Reference in a new issue