This repository has been archived on 2025-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
coryd.dev-eleventy/src/_data/links.js
2023-09-14 09:12:18 -07:00

27 lines
927 B
JavaScript

const EleventyFetch = require('@11ty/eleventy-fetch')
module.exports = async function () {
const READWISE_TOKEN = process.env.API_TOKEN_READWISE
const headers = { Authorization: `Token ${READWISE_TOKEN}` }
const url = 'https://readwise.io/api/v3/list?category=article'
const res = EleventyFetch(url, {
duration: '1h',
type: 'json',
fetchOptions: { headers },
})
const data = await res
const links = data['results'].filter((result) => Object.keys(result.tags).includes('share'))
return links.map((link) => {
return {
title: link['title'],
url: link['source_url'],
date: link['published_date']
? new Date(link['published_date'])
: new Date(link['created_at']),
summary: link['summary'],
notes: link['notes'],
tags: Object.keys(link.tags).filter((tag) => tag !== 'share' && tag !== 'shortlist'),
id: btoa(link['source_url']),
}
})
}