feat: refactor feeds; reduce dependencies
This commit is contained in:
parent
4067148658
commit
d768007f1c
375 changed files with 2568 additions and 13971 deletions
|
@ -1,23 +0,0 @@
|
|||
export default async function () {
|
||||
const { ActivityFeed } = await import('@11ty/eleventy-activity-feed')
|
||||
const feed = new ActivityFeed()
|
||||
feed.addSource('rss', '📝', 'https://coryd.dev/feeds/posts')
|
||||
feed.addSource('rss', '🎥', 'https://coryd.dev/feeds/movies')
|
||||
feed.addSource('rss', '📖', 'https://coryd.dev/feeds/books')
|
||||
feed.addSource('rss', '🔗', 'https://coryd.dev/feeds/links')
|
||||
feed.addSource('rss', '🎧', 'https://coryd.dev/feeds/weekly-artist-chart')
|
||||
const entries = feed.getEntries().catch()
|
||||
const res = await entries
|
||||
const activity = { posts: [] }
|
||||
res.forEach((entry) => {
|
||||
activity.posts.push({
|
||||
id: entry.url,
|
||||
title: entry.title,
|
||||
url: entry.url,
|
||||
description: entry.content,
|
||||
content_html: entry.content,
|
||||
date_published: entry.published,
|
||||
})
|
||||
})
|
||||
return activity
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -1,8 +0,0 @@
|
|||
import { createRequire } from 'module'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const mastodonCache = require('../../cache/jsonfeed-to-mastodon.json')
|
||||
|
||||
export default async function () {
|
||||
return mastodonCache
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
import EleventyFetch from '@11ty/eleventy-fetch'
|
||||
import { S3Client, GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3'
|
||||
|
||||
const getReadableData = (readable) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const chunks = []
|
||||
readable.once('error', (err) => reject(err))
|
||||
readable.on('data', (chunk) => chunks.push(chunk))
|
||||
readable.once('end', () => resolve(chunks.join('')))
|
||||
})
|
||||
}
|
||||
|
||||
const filterDuplicates = array => {
|
||||
const seenIds = new Set();
|
||||
return array.filter(obj => !seenIds.has(obj.id) && seenIds.add(obj.id));
|
||||
};
|
||||
|
||||
export default async function () {
|
||||
const client = new S3Client({
|
||||
credentials: {
|
||||
accessKeyId: process.env.ACCESS_KEY_B2,
|
||||
secretAccessKey: process.env.SECRET_KEY_B2,
|
||||
},
|
||||
endpoint: {
|
||||
url: 'https://s3.us-west-001.backblazeb2.com',
|
||||
},
|
||||
region: 'us-west-1',
|
||||
})
|
||||
const BUCKET_B2 = process.env.BUCKET_B2
|
||||
const API_TOKEN_READWISE = process.env.API_TOKEN_READWISE
|
||||
const formatLinkData = (links) => links.map((link) => {
|
||||
return {
|
||||
title: link['title'],
|
||||
url: link['source_url'],
|
||||
tags: [...new Set(Object.keys(link['tags']))],
|
||||
date: `${link['created_at'] || link['updated_at']}`,
|
||||
author: link['author'],
|
||||
summary: link['summary'],
|
||||
note: link['notes'],
|
||||
description: `${link['summary']}<br/><br/>`,
|
||||
id: link['id']
|
||||
}
|
||||
})
|
||||
const fullData = [];
|
||||
const maxRequests = process.env.ELEVENTY_PRODUCTION ? 10 : 2
|
||||
let nextPageCursor = null;
|
||||
let requestCount = 0;
|
||||
let cachedLinks;
|
||||
|
||||
if (process.env.ELEVENTY_PRODUCTION) {
|
||||
const cachedLinksOutput = await client.send(
|
||||
new GetObjectCommand({
|
||||
Bucket: BUCKET_B2,
|
||||
Key: 'links.json',
|
||||
})
|
||||
)
|
||||
const cachedLinksData = getReadableData(cachedLinksOutput.Body)
|
||||
cachedLinks = await cachedLinksData.then((tracks) => JSON.parse(tracks)).catch()
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const queryParams = new URLSearchParams()
|
||||
if (nextPageCursor) queryParams.append('pageCursor', nextPageCursor)
|
||||
const res = EleventyFetch(`https://readwise.io/api/v3/list?location=archive&${queryParams.toString()}`, {
|
||||
duration: '1h',
|
||||
type: 'json',
|
||||
fetchOptions: {
|
||||
headers: {
|
||||
Authorization: `Token ${API_TOKEN_READWISE}`,
|
||||
},
|
||||
},
|
||||
}).catch()
|
||||
const data = await res
|
||||
fullData.push(...data['results']);
|
||||
nextPageCursor = data['nextPageCursor']
|
||||
requestCount++;
|
||||
if (!nextPageCursor || requestCount === maxRequests) break;
|
||||
}
|
||||
|
||||
if (process.env.ELEVENTY_PRODUCTION) {
|
||||
const mergedData = filterDuplicates([
|
||||
...formatLinkData(fullData).filter((link) => link.tags.includes('share')),
|
||||
...Object.values(cachedLinks)
|
||||
]).sort((a,b) => new Date(b.date) - new Date(a.date));
|
||||
|
||||
await client.send(
|
||||
new PutObjectCommand({
|
||||
Bucket: BUCKET_B2,
|
||||
Key: 'links.json',
|
||||
Body: JSON.stringify(mergedData),
|
||||
})
|
||||
)
|
||||
return mergedData
|
||||
}
|
||||
|
||||
return formatLinkData(fullData).filter((link) => link.tags.includes('share'))
|
||||
}
|
|
@ -23,7 +23,6 @@ export default async function () {
|
|||
{ name: 'Mastodon', url: 'https://social.lol/@cory', icon: 'brand-mastodon' },
|
||||
{ name: 'Last.fm', url: 'https://www.last.fm/user/coryd_', icon: 'brand-lastfm' },
|
||||
{ name: 'Trakt', url: 'https://trakt.tv/users/cdransf', icon: 'device-tv' },
|
||||
{ name: 'The StoryGraph', url: 'https://app.thestorygraph.com/profile/coryd', icon: 'books' },
|
||||
{ name: 'Webrings', url: '/webrings', icon: 'heart-handshake' },
|
||||
],
|
||||
}
|
||||
|
|
Reference in a new issue