feat: fetch a larger set of links

This commit is contained in:
Cory Dransfeldt 2024-02-16 11:41:04 -08:00
parent 3405f87c11
commit cfc9db4ef7
No known key found for this signature in database
2 changed files with 22 additions and 12 deletions

View file

@ -1,6 +1,6 @@
{
"name": "coryd.dev",
"version": "5.8.0",
"version": "5.9.0",
"description": "The source for my personal site. Built using 11ty and hosted on Netlify.",
"type": "module",
"scripts": {

View file

@ -2,7 +2,6 @@ import EleventyFetch from '@11ty/eleventy-fetch'
export default async function () {
const API_TOKEN_READWISE = process.env.API_TOKEN_READWISE
const url = 'https://readwise.io/api/v3/list?location=archive'
const formatLinkData = (links) => links.map((link) => {
return {
title: link['title'],
@ -15,17 +14,28 @@ export default async function () {
description: `${link['summary']}<br/><br/>`,
}
})
const fullData = [];
let nextPageCursor = null;
let requestCount = 0;
const res = EleventyFetch(url, {
duration: '1h',
type: 'json',
fetchOptions: {
headers: {
Authorization: `Token ${API_TOKEN_READWISE}`,
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
return formatLinkData(data['results']).filter((link) => link.tags.includes('share'))
}).catch()
const data = await res
fullData.push(...data['results']);
nextPageCursor = data['nextPageCursor']
requestCount++;
if (!nextPageCursor || requestCount === 20) break;
}
return formatLinkData(fullData).filter((link) => link.tags.includes('share'))
}