-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
50 lines (47 loc) · 1.04 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
const path = require("path")
const slugify = require("@sindresorhus/slugify")
exports.onCreateWebpackConfig = ({ stage, actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
assets: path.resolve(__dirname, "src/assets")
// ui: path.resolve(__dirname, "src/ui"),
}
}
})
}
exports.onCreateNode = ({ node, actions }) => {
const { createNodeField } = actions
if (node.internal.type === "Mdx") {
createNodeField({
node,
name: "slug",
value: `/post/${slugify(node.frontmatter.title)}`
})
}
}
exports.createPages = async ({ actions, graphql }) => {
const { createPage } = actions
const postTemplate = path.resolve(`src/ui/templates/post.js`)
const result = await graphql(`
{
allMdx {
nodes {
id
fields {
slug
}
}
}
}
`)
result.data.allMdx.nodes.forEach(({ id, fields: { slug } }) => {
createPage({
path: slug,
component: postTemplate,
context: {
id
}
})
})
}