-
Notifications
You must be signed in to change notification settings - Fork 2
/
gatsby-node.js
35 lines (27 loc) · 956 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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
// You can delete this file if you're not using it
const fs = require("fs")
const path = require("path")
const slugify = require("slugify")
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
const modules = fs.readdirSync("modules", { withFileTypes: true }).filter(dir => dir.isDirectory()).map(dir => dir.name)
for (const module of modules) {
const module_path = path.join("modules", module)
const config_path = path.join(module_path, "config.json")
const config_text = fs.readFileSync(config_path).toString()
const config = JSON.parse(config_text)
const component_path = path.join(module_path, "content.js")
createPage({
path: `/${slugify(config.name, '-')}`,
component: path.resolve(component_path),
context: {
name: config.name,
},
});
}
}