You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
648 B
JavaScript
22 lines
648 B
JavaScript
const path = require('path')
|
|
const Axios = require('axios')
|
|
const { readFile, cacheDir, mkdirAndWriteFile } = require('../paths')
|
|
|
|
async function getMetadata() {
|
|
const cacheFile = path.join(cacheDir, 'gutenberg-metadata.json')
|
|
try {
|
|
const fileContents = await readFile(cacheFile)
|
|
return JSON.parse(fileContents)
|
|
} catch (err) {}
|
|
|
|
console.log('Downloading metadata from GitHub')
|
|
const metadata = await Axios.get(
|
|
'https://hugovk.github.io/gutenberg-metadata/gutenberg-metadata.json'
|
|
).then(res => res.data)
|
|
|
|
await mkdirAndWriteFile(cacheFile, JSON.stringify(metadata))
|
|
return metadata
|
|
}
|
|
|
|
module.exports = { getMetadata }
|