-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
92 lines (87 loc) · 2.29 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const path = require(`path`);
const { createFilePath } = require('gatsby-source-filesystem');
exports.onCreateWebpackConfig = ({ actions, plugins, getConfig }) => {
const output = getConfig().output || {};
actions.setWebpackConfig({
plugins: [
plugins.provide({
React: 'react',
}),
],
output,
resolve: {
alias: {
'@assets': path.resolve(__dirname, 'src/assets'),
'@components': path.resolve(__dirname, 'src/components'),
'@hooks': path.resolve(__dirname, 'src/hooks'),
'@layout': path.resolve(__dirname, 'src/layout'),
'@pages': path.resolve(__dirname, 'src/pages'),
'@store': path.resolve(__dirname, 'src/store'),
'@styles': path.resolve(__dirname, 'src/styles'),
'@templates': path.resolve(__dirname, 'src/templates'),
'@utils': path.resolve(__dirname, 'src/utils'),
},
},
});
};
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === `Mdx`) {
const slug = createFilePath({ node, getNode, basePath: `content` });
const newSlug = `/${slug.split('/').reverse()[1]}/`;
createNodeField({
node,
name: `slug`,
value: newSlug,
});
}
};
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const result = await graphql(`
{
allMdx(sort: { fields: frontmatter___date, order: DESC }, limit: 1000) {
edges {
node {
fields {
slug
}
frontmatter {
title
date(formatString: "YYYY년 M월 D일")
category
}
}
next {
fields {
slug
}
frontmatter {
title
}
}
previous {
fields {
slug
}
frontmatter {
title
}
}
}
}
}
`);
const posts = result.data.allMdx.edges;
posts.forEach(({ node, next, previous }) => {
createPage({
path: node.fields.slug,
component: path.resolve(`src/templates/post-template.tsx`),
context: {
slug: node.fields.slug,
next,
previous,
},
});
});
};