This repository has been archived by the owner on Nov 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
gatsby-node.js
58 lines (53 loc) · 1.72 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
57
58
const Notabase = require("notabase")
const genApiData = require('./src/genApiData')
let nb = new Notabase()
exports.sourceNodes = async ({ actions, createNodeId, createContentDigest }, options) => {
const { createNode } = actions
const { configTable, sourceConfig } = options
let config
let _dbMap = {}
let cacheTable = []
if (configTable) {
let configCollection = await nb.fetch(configTable)
config = configCollection.rows
} else if (sourceConfig) {
config = sourceConfig
}
let configNode = []
config.filter(i => i).map(c => {
configNode.push({
name: c.name,
cacheType: c.cacheType,
table: c.table
})
if (c.cacheType === "html") {
cacheTable.push(c.name)
_dbMap[c.name] = c.table
} else if (!(c.cacheType === "dynamic")) {
_dbMap[c.name] = c.table
}
})
configNode.map(data => {
const nodeContent = JSON.stringify(data)
const nodeMeta = {
id: createNodeId(nodeContent),
parent: null,
children: [],
internal: {
type: 'SourceConfig',
mediaType: `text/html`,
content: nodeContent,
contentDigest: createContentDigest(data)
},
}
const node = Object.assign({}, data, nodeMeta)
createNode(node)
})
// console.log(_dbMap, cacheTable)
let db = await nb.fetchAll(_dbMap)
await Promise.all(Object.entries(db).map(async (i) => {
let [tableName, collection] = i
await genApiData(nb, collection, tableName, 'id', createNode, createNodeId, createContentDigest, cacheTable)
}))
return
}