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',