-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
37 lines (34 loc) · 1017 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
34
35
36
37
// We need the filesystem to write the JSON file
const fs = require("fs")
// Invoked after build has finished
exports.onPostBuild = async ({ graphql, reporter }) => {
// Query all f1teams, message in the console if errors occur
const result = await graphql(`
query F1Teams {
allFile(
filter: { absolutePath: { regex: "/f1-teams/" }, ext: { eq: ".md" } }
) {
nodes {
childMarkdownRemark {
frontmatter {
title
teamPrincipal
homeBase
logo {
publicURL
}
drivers
}
}
}
}
}
`)
if (result.errors) reporter.panic("🚨 F1Teams-query failed onPostBuild")
// Destructure result as f1Teams
const f1Teams = result.data.allFile.nodes.map(teamWithMarkdown => ({
...teamWithMarkdown.childMarkdownRemark.frontmatter,
}))
// Write the JSON file
fs.writeFileSync("./public/f1-teams.json", JSON.stringify(f1Teams))
}