/
gatsby-node.js
56 lines (48 loc) · 1.23 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.com/docs/node-apis/
*/
const {
processPieceTypes
} = require('./lib/pieces');
const {
getPageIds,
generatePageNodes
} = require('./lib/pages');
exports.sourceNodes = async ({
actions,
createContentDigest,
createNodeId
}, options) => {
options = options || {};
const { createNode } = actions;
if (!options.baseUrl) {
throw Error('You are missing the `baseUrl` option for gatsby-source-apostrophe');
}
if (!options.apiKey) {
throw Error('You are missing the `apiKey` option for gatsby-source-apostrophe');
}
const gatsbyUtils = {
createNode,
createNodeId,
createContentDigest
};
const routePathBase = options.routeBase || 'api/v1';
const apiRouteBase = `${options.baseUrl}/${routePathBase}`;
if (Array.isArray(options.pieceTypes)) {
await processPieceTypes(options.pieceTypes, {
apiRouteBase,
apiKey: options.apiKey
}, gatsbyUtils);
}
const pageIds = await getPageIds(apiRouteBase, {
apiKey: options.apiKey
});
await generatePageNodes(pageIds, {
baseUrl: options.baseUrl,
apiRouteBase,
apiKey: options.apiKey,
renderPages: options.renderPages
}, gatsbyUtils);
};