generated from kohrongying/11ty-blog-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
20 lines (19 loc) 路 979 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { getStore, setEnvironmentContext } from '@netlify/blobs'
import fs from 'fs'
export const onPreBuild = async ({ constants }) => {
setEnvironmentContext({
siteID: constants.SITE_ID,
token: constants.NETLIFY_API_TOKEN,
})
const scrobbles = getStore('scrobbles')
const artists = getStore('artists')
const albums = getStore('albums')
const windowData = await scrobbles.get('window', { type: 'json'})
const artistsMap = await artists.get('artists-map', { type: 'json' })
const albumsMap = await albums.get('albums-map', { type: 'json' })
const nowPlaying = await scrobbles.get('now-playing', { type: 'json'})
fs.writeFileSync('./src/_data/json/scrobbles-window.json', JSON.stringify(windowData))
fs.writeFileSync('./src/_data/json/artists-map.json', JSON.stringify(artistsMap))
fs.writeFileSync('./src/_data/json/albums-map.json', JSON.stringify(albumsMap))
fs.writeFileSync('./src/_data/json/now-playing.json', JSON.stringify(nowPlaying))
}