offload now calls + generation to 11ty; add activity feed; cleanup

This commit is contained in:
Cory Dransfeldt 2023-03-16 13:25:57 -07:00
parent 4bd059bc90
commit 4dd6cc9313
No known key found for this signature in database
18 changed files with 192 additions and 93 deletions

12
src/_data/albums.js Normal file
View file

@ -0,0 +1,12 @@
const EleventyFetch = require('@11ty/eleventy-fetch')
module.exports = async function () {
const MUSIC_KEY = process.env.API_KEY_LASTFM
const url = `http://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user=cdme_&api_key=${MUSIC_KEY}&limit=8&format=json&period=7day`
const res = EleventyFetch(url, {
duration: '1h',
type: 'json',
})
const albums = await res
return albums.topalbums.album
}

12
src/_data/artists.js Normal file
View file

@ -0,0 +1,12 @@
const EleventyFetch = require('@11ty/eleventy-fetch')
module.exports = async function () {
const MUSIC_KEY = process.env.API_KEY_LASTFM
const url = `http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=cdme_&api_key=${MUSIC_KEY}&limit=8&format=json&period=7day`
const res = EleventyFetch(url, {
duration: '1h',
type: 'json',
})
const artists = await res
return artists.topartists.artist
}

12
src/_data/books.js Normal file
View file

@ -0,0 +1,12 @@
const { extract } = require('@extractus/feed-extractor')
const { AssetCache } = require('@11ty/eleventy-fetch')
module.exports = async function () {
const url = 'https://oku.club/rss/collection/POaRa'
const asset = new AssetCache('books_data')
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
const res = await extract(url).catch((error) => {})
const data = res.entries
await asset.save(data, 'json')
return data
}

12
src/_data/movies.js Normal file
View file

@ -0,0 +1,12 @@
const { extract } = require('@extractus/feed-extractor')
const { AssetCache } = require('@11ty/eleventy-fetch')
module.exports = async function () {
const url = 'https://letterboxd.com/cdme/rss'
const asset = new AssetCache('movies_data')
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
const res = await extract(url).catch((error) => {})
const data = res.entries.splice(0, 5)
await asset.save(data, 'json')
return data
}

View file

@ -1,17 +0,0 @@
const EleventyFetch = require('@11ty/eleventy-fetch')
module.exports = async function () {
const url = 'https://utils.coryd.dev/api/now?endpoints=artists,albums,books,movies,tv'
const res = EleventyFetch(url, {
duration: '1h',
type: 'json',
})
const now = await res
return {
artists: now.artists,
albums: now.albums,
books: now.books,
movies: now.movies,
tv: now.tv,
}
}

View file

@ -1,15 +0,0 @@
const EleventyFetch = require('@11ty/eleventy-fetch')
module.exports = async function () {
const url = 'https://utils.coryd.dev/api/music?limit=1'
const res = EleventyFetch(url, {
duration: '3m',
type: 'json',
})
const music = await res
return {
artist: music.recenttracks.track[0].artist['#text'],
title: music.recenttracks.track[0].name,
url: music.recenttracks.track[0].url,
}
}

13
src/_data/tv.js Normal file
View file

@ -0,0 +1,13 @@
const { extract } = require('@extractus/feed-extractor')
const { AssetCache } = require('@11ty/eleventy-fetch')
module.exports = async function () {
const TV_KEY = process.env.API_KEY_TRAKT
const url = `https://trakt.tv/users/cdransf/history.atom?slurm=${TV_KEY}`
const asset = new AssetCache('tv_data')
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
const res = await extract(url).catch((error) => {})
const data = res.entries.splice(0, 5)
await asset.save(data, 'json')
return data
}

View file

@ -1,7 +1,8 @@
const EleventyFetch = require('@11ty/eleventy-fetch')
module.exports = async function () {
const url = 'https://utils.coryd.dev/api/webmentions'
const KEY_CORYD = process.env.API_KEY_WEBMENTIONS_CORYD_DEV
const url = `https://webmention.io/api/mentions.jf2?token=${KEY_CORYD}&per-page=1000`
const res = EleventyFetch(url, {
duration: '1h',
type: 'json',

View file

@ -23,6 +23,7 @@
<link rel="pingback" href="https://webmention.io/coryd.dev/xmlrpc" />
<link type="application/atom+xml" rel="alternate" title="Cory Dransfeldt" href="/feed.xml">
<link rel="alternate" type="application/json" title="Cory Dransfeldt" href="/feed.json" />
<link rel="alternate" href="/follow.xml" title="Cory Dransfeldt's activity feed" type="application/rss+xml">
<script>
const isDarkMode = () => localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches);
if (isDarkMode()) {
@ -44,43 +45,6 @@
document.documentElement.classList.add('dark')
}
});
;(function () {
const nowPlayingWrapper = document.getElementById("now-playing");
if (nowPlayingWrapper) {
try {
const localStorageKey = "CD_NOW_PLAYING";
const cachedTemplate = localStorage.getItem(localStorageKey);
if (window.localStorage && cachedTemplate) {
nowPlayingWrapper.innerHTML = "";
nowPlayingWrapper.insertAdjacentHTML("beforeEnd", cachedTemplate);
}
fetch("https://utils.coryd.dev/api/music?limit=1")
.then((response) => response.json())
.then((data) => {
const track = data.recenttracks.track[0];
const artistName = track.artist["#text"];
const template = `<a href="${
track.url
}" class="no-underline dark:text-white text-gray-800 font-normal">${
track.name
}</a> by <a href="https://ddg.gg?q=!rym ${encodeURIComponent(
artistName
)}" class="no-underline dark:text-white text-gray-800 font-normal">${artistName}</a>`;
if (window.localStorage)
localStorage.setItem(localStorageKey, template);
nowPlayingWrapper.innerHTML = "";
nowPlayingWrapper.insertAdjacentHTML("beforeEnd", template);
});
} catch (e) {
nowPlayingWrapper.innerHTML = "";
}
}
})();
</script>
</body>
</html>

View file

@ -1,13 +1,5 @@
<div class="border-b border-gray-200 pb-8 dark:border-gray-700 mb-8 pb-8 dark:text-white text-gray-800">
<a class="no-underline" href="/now"><h2 class="m-0 text-xl font-black leading-tight tracking-normal md:text-2xl text-primary-500 hover:text-primary-400 mb-4">Now</h2></a>
<p>I'm a software developer in Camarillo, California. I enjoy hanging out with my beautiful family and 4 rescue dogs, technology, automation, music, writing, reading and tv and movies.</p>
<p>{{ status.emoji }} {{ status.content }}</p>
<p class="mb-0">
<span class="icon-inline">
{% heroicon "solid" "music-note" "Now playing" "width=20 height=20" %}
</span>
<span id="now-playing">
<span class="blur-md">Loading track</span>
</span>
</p>
<p class="mb-0">{{ status.emoji }} {{ status.content }}</p>
</div>

View file

@ -29,7 +29,7 @@ layout: main
<div class="pl-4 md:pl-8">
<p class="my-2"><span class="icon-inline mr-1">{% heroicon "solid" "terminal" "Terminal" "width=20 height=20" %}</span> Hacking away on random projects like this page, my <a href="/">blog</a>, and whatever else I can find time for.</p>
</div>
{% if now.artists %}
{% if artists %}
<h2
class="m-0 text-xl font-black leading-tight tracking-normal dark:text-gray-200 md:text-2xl mt-8 mb-4"
>
@ -37,7 +37,7 @@ layout: main
</h2>
<div>
<div class="grid grid-cols-2 gap-2 md:grid-cols-4 not-prose">
{% for artist in now.artists %}
{% for artist in artists %}
<a href="{{artist.url}}" title="{{artist.name | escape}}">
<div class="relative block">
<div class="absolute left-0 top-0 h-full w-full rounded-lg border border-primary-500 bg-cover-gradient dark:border-gray-500"></div>
@ -61,7 +61,7 @@ layout: main
</div>
</div>
{% endif %}
{% if now.albums %}
{% if albums %}
<h2
class="m-0 text-xl font-black leading-tight tracking-normal dark:text-gray-200 md:text-2xl mt-8 mb-4"
>
@ -69,7 +69,7 @@ layout: main
</h2>
<div>
<div class="grid grid-cols-2 gap-2 md:grid-cols-4 not-prose">
{% for album in now.albums %}
{% for album in albums %}
<a href="{{album.url}}" title="{{album.name | escape}}">
<div class="relative block">
<div class="absolute left-0 top-0 h-full w-full rounded-lg border border-primary-500 bg-cover-gradient dark:border-gray-500"></div>
@ -94,7 +94,7 @@ layout: main
</div>
</div>
{% endif %}
{% if now.books %}
{% if books %}
<h2
class="m-0 text-xl font-black leading-tight tracking-normal dark:text-gray-200 md:text-2xl mt-6 mb-4"
>
@ -102,7 +102,7 @@ layout: main
</h2>
<div>
<ul class="list-inside list-disc pl-5 md:pl-10">
{% for book in now.books %}
{% for book in books %}
<li class="mt-1.5 mb-2">
<a href="{{book.link}}" title="{{book.title | escape}}">
{{book.title}}
@ -112,7 +112,7 @@ layout: main
</ul>
</div>
{% endif %}
{% if now.movies %}
{% if movies %}
<h2
class="m-0 text-xl font-black leading-tight tracking-normal dark:text-gray-200 md:text-2xl mt-6 mb-4"
>
@ -120,7 +120,7 @@ layout: main
</h2>
<div>
<ul class="list-inside list-disc pl-5 md:pl-10">
{% for movie in now.movies %}
{% for movie in movies %}
<li class="mt-1.5 mb-2">
<a href="{{movie.link}}" title="{{movie.title | escape}}">
{{movie.title}}
@ -130,7 +130,7 @@ layout: main
</ul>
</div>
{% endif %}
{% if now.tv %}
{% if tv %}
<h2
class="m-0 text-xl font-black leading-tight tracking-normal dark:text-gray-200 md:text-2xl mt-6 mb-4"
>
@ -138,7 +138,7 @@ layout: main
</h2>
<div>
<ul class="list-inside list-disc pl-5 md:pl-10">
{% for show in now.tv %}
{% for show in tv %}
<li class="mt-1.5 mb-2">
<a href="{{show.link}}" title="{{show.title | escape}}">
{{show.title}}

25
src/follow-feed.11ty.js Normal file
View file

@ -0,0 +1,25 @@
module.exports = class {
data() {
return {
permalink: '/follow.xml',
}
}
async render() {
const { ActivityFeed } = await import('@11ty/eleventy-activity-feed')
const feed = new ActivityFeed()
feed.setCacheDuration('1h')
feed.addSource('atom', 'Blog', 'https://coryd.dev/feed.xml')
feed.addSource('rss', 'Letterboxd', 'https://letterboxd.com/cdme/rss')
feed.addSource('rss', 'Glass', 'https://glass.photo/coryd/rss')
feed.addSource('rss', 'Oku', 'https://oku.club/rss/collection/NvEmF')
return feed.toRssFeed({
title: "Cory Dransfeldt's activity feed",
language: 'en',
url: 'https://coryd.dev/follow/',
subtitle: "Cory Dransfeldt's activity across the web.",
})
}
}