chore: album releases cleanup

This commit is contained in:
Cory Dransfeldt 2024-02-21 09:26:50 -08:00
parent 6f07c6aa4d
commit 4a68d4d64a
No known key found for this signature in database

View file

@ -5,25 +5,21 @@ import { DateTime } from 'luxon'
export default async function () { export default async function () {
const URL = process.env.SECRET_FEED_ALBUM_RELEASES const URL = process.env.SECRET_FEED_ALBUM_RELEASES
const icsToJson = ics.default const icsToJson = ics.default
if (process.env.ELEVENTY_PRODUCTION) { const asset = new AssetCache('album_release_data')
const asset = new AssetCache('album_release_data') if (asset.isCacheValid('1h')) return await asset.getCachedValue()
if (asset.isCacheValid('1h')) return await asset.getCachedValue() const icsRes = await fetch(URL)
const icsRes = await fetch(URL) const icsData = await icsRes.text()
const icsData = await icsRes.text() const data = icsToJson(icsData)
const data = icsToJson(icsData) const albumReleases = data
const albumReleases = data .filter((d) => DateTime.fromISO(d.startDate) > DateTime.now())
.filter((d) => DateTime.fromISO(d.startDate) > DateTime.now()) .sort((a, b) => new Date(a.startDate) - new Date(b.startDate))
.sort((a, b) => new Date(a.startDate) - new Date(b.startDate)) .map((release) => {
.map((release) => { return {
return { date: release.startDate,
date: release.startDate, url: release.location,
url: release.location, title: release.summary.replace(/\\/g, ''),
title: release.summary.replace(/\\/g, ''), }
} })
}) await asset.save(albumReleases, 'json')
await asset.save(albumReleases, 'json') return albumReleases
return albumReleases
} else {
return {}
}
} }