From 68b484be333aef06ad87fba54287024753344395 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Wed, 10 Jan 2024 12:55:53 -0800 Subject: [PATCH] chore: readwise post --- src/links.html | 4 +- .../2024/link-blogging-using-readwise.md | 72 +++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/posts/2024/link-blogging-using-readwise.md diff --git a/src/links.html b/src/links.html index 01c09ece..3229db54 100644 --- a/src/links.html +++ b/src/links.html @@ -13,9 +13,9 @@ pagination: -
{{ link.summary | markdown }}
+
{{ link.summary }}
{%- if link.note %} -

{{ link.note | markdown }}

+

{{ link.note }}

{% endif -%} {% endfor %} diff --git a/src/posts/2024/link-blogging-using-readwise.md b/src/posts/2024/link-blogging-using-readwise.md new file mode 100644 index 00000000..396341b2 --- /dev/null +++ b/src/posts/2024/link-blogging-using-readwise.md @@ -0,0 +1,72 @@ +--- +date: '2024-01-10' +title: 'Link blogging using Readwise Reader' +description: 'How I use Readwise Reader to post and share links.' +draft: false +tags: + - 'development' + - 'tech' + - 'Eleventy' +--- +I use Readwise Reader's API to populate the links on [my now page](/now). These then get included in [my follow feed](https://feedpress.me/coryd-follow) that's syndicated out to Mastodon using a [GitHub action](https://github.com/nhoizey/github-action-feed-to-mastodon) authored by [Nicolas Hoizey](https://nicolas-hoizey.com). + +The `data` file used to fetch these links looks like this: + +```javascript +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 res = EleventyFetch(url, { + duration: '1h', + type: 'json', + fetchOptions: { + headers: { + Authorization: `Token ${API_TOKEN_READWISE}`, + }, + }, + }).catch() + const data = await res + const links = data['results'].map((link) => { + return { + title: link['title'], + url: link['source_url'], + tags: [...new Set(Object.keys(link['tags']))], + date: link['created_at'], + summary: link['summary'], + note: link['notes'], + description: `${link['summary']}

`, + } + }) + return links.filter((link) => link.tags.includes('share')) +} +``` + +This fetches links from my archive (so that it's much more likely that I've read them) and includes them on my now page via a `links.liquid` partial that looks like this: + +{% raw %} +```liquid +{% if links.size > 0 %} +

+ {% tablericon "link" "Links" %} + Links +

+ +{% endif %} +``` +{% endraw %} + +Now, however, I've gone ahead and added the `notes` field from Readwise's API response to the `data` I expose in my `links.js` file above and constructed [an additional top level page](/links), complete with pagination. This top level page formats my shared links much like the posts on my home page, adds the summary Readwise fetches as a `
` and, if I've added notes to the document (which I'll now aim to do more consistently), it will render them below the `
`. Now, *all* of the links I've shared are at least visible *somewhere* on my site instead of the five most recent on [my now page](/now). + +There you have it — link blogging via Readwise Reader[^1]. + +[^1]: Or lazy link blogging, if you'd prefer. \ No newline at end of file