fix: album release sorting

This commit is contained in:
Cory Dransfeldt 2023-06-09 12:15:25 -07:00
parent 7602459198
commit 77992e259d
No known key found for this signature in database
2 changed files with 12 additions and 10 deletions

View file

@ -10,5 +10,6 @@ module.exports = async function () {
const icsRes = await fetch(URL)
const icsData = await icsRes.text()
const data = icsToJson(icsData)
return data.filter((d) => DateTime.fromISO(d.startDate) > DateTime.now())
const albumReleases = data.filter((d) => DateTime.fromISO(d.startDate) > DateTime.now())
return albumReleases.sort((a, b) => new Date(a.startDate) - new Date(b.startDate))
}

View file

@ -18,14 +18,15 @@ const ics = require('ics-to-json-extended')
const { DateTime } = require('luxon')
module.exports = async function () {
const URL = process.env.SECRET_FEED_ALBUM_RELEASES
const icsToJson = ics.default
const asset = new AssetCache('album_release_data')
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
const icsRes = await fetch(URL)
const icsData = await icsRes.text()
const data = icsToJson(icsData)
return data.filter((d) => DateTime.fromISO(d.startDate) > DateTime.now())
const URL = process.env.SECRET_FEED_ALBUM_RELEASES
const icsToJson = ics.default
const asset = new AssetCache('album_release_data')
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
const icsRes = await fetch(URL)
const icsData = await icsRes.text()
const data = icsToJson(icsData)
const albumReleases = data.filter((d) => DateTime.fromISO(d.startDate) > DateTime.now())
return albumReleases.sort((a, b) => new Date(a.startDate) - new Date(b.startDate))
}
```
@ -64,6 +65,6 @@ Rendering the output is as simple as:
{% endraw %}
Leaving us with:
{% image 'https://cdn.coryd.dev/blog/album-releases.jpg', 'Albums I\'m looking forward to', 'w-full', '600px' %}
{% image '<https://cdn.coryd.dev/blog/album-releases.jpg>', 'Albums I\'m looking forward to', 'w-full', '600px' %}
[^1]: At this point, a dev playground.