-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
36 lines (32 loc) · 959 Bytes
/
gatsby-node.js
File metadata and controls
36 lines (32 loc) · 959 Bytes
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
const fs = require('fs')
const path = require('path')
// TODO: testresult file should be better uuid
const targetDirectory = `src/content`
const resultFiles = fs.readdirSync(targetDirectory)
const results = resultFiles.map((file) => {
const data = JSON.parse(fs.readFileSync(`${targetDirectory}/${file}`, `utf8`))
const id = file.split(`_`)[1].split(`.`)[0]
return { id, filePath: `${targetDirectory}/${file}`, data }
})
exports.createPages = ({ actions }) => {
const { createPage } = actions
// Create main Page
createPage({
path: `/`,
component: path.resolve(`src/templates/main.tsx`),
context: {
results: results.sort((a, b) => (a.id < b.id ? 1 : -1)),
},
})
// Create results pages
results.forEach((result) => {
createPage({
path: `/result_${result.id}`,
component: path.resolve(`src/templates/result.tsx`),
context: {
id: result.id,
...result.data,
},
})
})
}