fetch refactoring

This commit is contained in:
Cory Dransfeldt 2023-03-13 19:17:50 -07:00
parent 9a5431cffa
commit 0122e9b456
No known key found for this signature in database
4 changed files with 27 additions and 27 deletions

View file

@ -1,12 +1,12 @@
const EleventyFetch = require('@11ty/eleventy-fetch')
const fetch = require('node-fetch')
const { AssetCache } = require('@11ty/eleventy-fetch')
module.exports = async function () {
const url = 'https://utils.coryd.dev/api/webmentions'
const res = EleventyFetch(url, {
duration: '1d',
type: 'json',
})
const webmentions = await res
const asset = new AssetCache('webmentions_data')
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
const webmentions = await fetch(url).then((res) => res.json())
await asset.save(webmentions, 'json')
return {
mentions: webmentions.children,
}