-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
33 lines (26 loc) · 921 Bytes
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/
*/
const fetch = require("node-fetch-commonjs");
const fs = require('fs');
const path = require('path');
/**
* @type {import('gatsby').GatsbyNode['createPages']}
*/
exports.createPages = async ({ actions }) => {
const { createPage } = actions
const responseData = await fetch('https://fairfield-programming.github.io/openlist/licenses/download')
const responseJson = await responseData.json()
const storagePath = path.join(process.cwd(), 'src/res/licenses.json')
fs.writeFileSync(storagePath, JSON.stringify(responseJson));
responseJson.forEach(element => {
createPage({
path: `/licenses/${element.id}`,
component: require.resolve("./src/templates/license.js"),
context: element,
defer: process.env.NODE_ENV != "production",
})
});
}